diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /bin/update/tools.py | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bin/update/tools.py')
-rw-r--r-- | bin/update/tools.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/bin/update/tools.py b/bin/update/tools.py new file mode 100644 index 0000000000..ab38d10f4b --- /dev/null +++ b/bin/update/tools.py @@ -0,0 +1,61 @@ +import os +import hashlib +import zipfile +import tarfile + + +def uncompress_file_to_dir(compressed_file, uncompress_dir): + extension = os.path.splitext(compressed_file)[1] + + os.makedirs(uncompress_dir, exist_ok=True) + + if extension == '.gz': + with tarfile.open(compressed_file) as tar: + tar.extractall(uncompress_dir) + elif extension == '.zip': + with zipfile.ZipFile(compressed_file) as zip_file: + zip_file.extractall(uncompress_dir) + + uncompress_dir = os.path.join(uncompress_dir, os.listdir(uncompress_dir)[0]) + if " " in os.listdir(uncompress_dir)[0]: + print("replacing whitespace in directory name") + os.rename(os.path.join(uncompress_dir, os.listdir(uncompress_dir)[0]), + os.path.join(uncompress_dir, os.listdir(uncompress_dir)[0].replace(" ", "_"))) + else: + print("Error: unknown extension " + extension) + + return os.path.join(uncompress_dir, os.listdir(uncompress_dir)[0]) + + +BUF_SIZE = 1048576 + + +def get_hash(file_path): + sha512 = hashlib.sha512() + with open(file_path, 'rb') as f: + while data := f.read(BUF_SIZE): + sha512.update(data) + return sha512.hexdigest() + + +def get_file_info(mar_file, url): + filesize = os.path.getsize(mar_file) + data = {'hash': get_hash(mar_file), + 'hash_function': 'sha512', + 'size': filesize, + 'url': url + os.path.basename(mar_file)} + + return data + + +def replace_variables_in_string(string, **kwargs): + new_string = string + for key, val in kwargs.items(): + new_string = new_string.replace('$(%s)' % key, val) + + return new_string + + +def make_complete_mar_name(target_dir, filename_prefix): + filename = filename_prefix + "_complete.mar" + return os.path.join(target_dir, filename) |