refactor image import and add Alpine docker image

- dynamic import of QR reader
- build docker also for arm64
This commit is contained in:
scito 2022-12-24 01:59:35 +01:00 committed by Roland Kurmann
parent 915efcf192
commit 9d052dc78a
21 changed files with 910 additions and 521 deletions

View file

@ -14,12 +14,13 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import csv
import glob
import io
import json
import os
import re
import shutil
from io import StringIO
import sys
import glob
# Ref. https://stackoverflow.com/a/16571630
@ -31,9 +32,9 @@ with Capturing() as output:
'''
def __enter__(self):
self._stdout = sys.stdout
sys.stdout = self._stringio_std = StringIO()
sys.stdout = self._stringio_std = io.StringIO()
self._stderr = sys.stderr
sys.stderr = self._stringio_err = StringIO()
sys.stderr = self._stringio_err = io.StringIO()
return self
def __exit__(self, *args):
@ -102,3 +103,22 @@ def read_file_to_list(filename):
def read_file_to_str(filename):
"""Returns a str."""
return "".join(read_file_to_list(filename))
def read_binary_file_as_stream(filename):
"""Returns binary file content."""
with open(filename, "rb",) as infile:
return io.BytesIO(infile.read())
def replace_escaped_octal_utf8_bytes_with_str(str):
encoded_name_strings = re.findall(r'name: .*$', str, flags=re.MULTILINE)
for encoded_name_string in encoded_name_strings:
escaped_bytes = re.findall(r'((?:\\[0-9]+)+)', encoded_name_string)
for byte_sequence in escaped_bytes:
unicode_str = b''.join([int(byte, 8).to_bytes(1, 'little') for byte in byte_sequence.split('\\') if byte]).decode('utf-8')
print("Replace '{}' by '{}'".format(byte_sequence, unicode_str))
str = str.replace(byte_sequence, unicode_str)
return str
def quick_and_dirty_workaround_encoding_problem(str):
return re.sub(r'name: "encoding: .*$', '', str, flags=re.MULTILINE)