aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Teivonen <patrik.teivonen@qt.io>2022-08-31 13:28:47 +0300
committerPatrik Teivonen <patrik.teivonen@qt.io>2022-09-29 08:23:58 +0000
commit61acafbd12812679b9da5a109165f66983493964 (patch)
treee83db56ccff0760fef6b610e3ea5bc087eea471a
parent3e01d055325322cbb4fe20b1917baeb0e84a4cf3 (diff)
bldinstallercommon: Remove unneeded text file functionsv5.15.11-lts-packaging
It is no longer needed to ensure file endings for text payload while creating an installer. Remove functions related to this that are not used for anything else. Change-Id: Ia2473aba9f2c89dcd118cbe08226e3f681f725b9 Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r--packaging-tools/bldinstallercommon.py50
-rw-r--r--packaging-tools/create_installer.py9
2 files changed, 1 insertions, 58 deletions
diff --git a/packaging-tools/bldinstallercommon.py b/packaging-tools/bldinstallercommon.py
index 0418a9318..cf41c24f3 100644
--- a/packaging-tools/bldinstallercommon.py
+++ b/packaging-tools/bldinstallercommon.py
@@ -246,28 +246,6 @@ def replace_in_files(filelist: List[str], regexp: str, replacement_string: str)
###############################
# function
###############################
-def ensure_text_file_endings(filename: str) -> None:
- print('------------ ensure_text_file_endings ----------------')
- if os.path.isdir(filename):
- print(f'*** Warning, given file is directory? Did nothing for: {filename}')
- return
- with open(filename, "rb") as handle:
- data = handle.read()
- if b'\0' in data:
- print(f'*** Warning, given file is binary? Did nothing for: {filename}')
- return
- if is_windows():
- newdata = re.sub(b"\r?\n", b"\r\n", data)
- if newdata != data:
- print(f'File endings changed for: {filename}')
- with open(filename, "wb") as handle:
- handle.write(newdata)
- print('--------------------------------------------------------------------')
-
-
-###############################
-# function
-###############################
def safe_config_key_fetch(conf: ConfigParser, section: str, key: str) -> Any:
if not conf.has_section(section):
return ''
@@ -323,34 +301,6 @@ def locate_paths(search_dir: Union[str, Path], patterns: List[str],
return [str(p) for p in paths if all(f(p) for f in filters)]
-def is_text(data: Union[str, bytes]) -> bool:
- # original snippet:
- # http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/
- data = str(data)
- if isinstance(data, str) and "\0" in data or isinstance(data, bytes) and b"\0" in data:
- return False
- if not data: # Empty files are considered text
- return True
- # Get the non-text characters (maps a character to itself then
- # use the 'remove' option to get rid of the text characters.)
- text_characters = "".join(list(map(chr, list(range(32, 127)))) + list("\n\r\t\b"))
- non_text = data
- for char in text_characters:
- non_text = non_text.replace(char, "")
- # If more than 30% non-text characters, then
- # this is considered a binary file
- if len(non_text) / len(data) > 0.30:
- return False
- return True
-
-
-def is_text_file(filename: Union[str, Path], blocksize: int = 512) -> bool:
- try:
- return is_text(open(filename, encoding="utf-8").read(blocksize))
- except UnicodeDecodeError:
- return is_text(open(filename, 'rb').read(blocksize))
-
-
###############################
# Function
###############################
diff --git a/packaging-tools/create_installer.py b/packaging-tools/create_installer.py
index d3e602f4a..a1e04bd64 100644
--- a/packaging-tools/create_installer.py
+++ b/packaging-tools/create_installer.py
@@ -48,11 +48,9 @@ from archiveresolver import ArchiveLocationResolver
from bld_utils import download, is_linux, is_macos, is_windows
from bldinstallercommon import (
copy_tree,
- ensure_text_file_endings,
extract_file,
handle_component_rpath,
is_content_url_valid,
- is_text_file,
locate_executable,
locate_path,
locate_paths,
@@ -371,14 +369,9 @@ def get_component_data(
# extract contents
if archive.extract_archive == 'yes':
extracted = extract_file(downloaded_archive, install_dir)
- # remove old package
+ # remove old package if extraction was successful, else keep it
if extracted:
os.remove(downloaded_archive)
- else:
- # ok we could not extract the file, so propably not even archived file,
- # check the case if we downloaded a text file, must ensure proper file endings
- if is_text_file(downloaded_archive):
- ensure_text_file_endings(downloaded_archive)
# perform custom action script for the extracted archive
if archive.archive_action: