Bump version to 24.04.3.4
[LibreOffice.git] / bin / update / tools.py
blob6bc3f7971fc8b7994396eb9ea43c031a93fe779b
1 import os
2 import hashlib
3 import subprocess
5 from path import convert_to_native
8 def uncompress_file_to_dir(compressed_file, uncompress_dir):
9 os.makedirs(uncompress_dir, exist_ok=True)
11 if subprocess.call([
12 'msiexec', '/a', convert_to_native(compressed_file).replace('/', '\\'),
13 '/quiet',
14 'TARGETDIR=' + convert_to_native(uncompress_dir).replace('/', '\\')]) != 0:
15 raise Exception(f'msiexec failed')
17 return uncompress_dir
20 BUF_SIZE = 1048576
23 def get_hash(file_path):
24 sha512 = hashlib.sha512()
25 with open(file_path, 'rb') as f:
26 while data := f.read(BUF_SIZE):
27 sha512.update(data)
28 return sha512.hexdigest()
31 def get_file_info(mar_file, url):
32 filesize = os.path.getsize(mar_file)
33 data = {'hash': get_hash(mar_file),
34 'hash_function': 'sha512',
35 'size': filesize,
36 'url': url + os.path.basename(mar_file)}
38 return data
41 def replace_variables_in_string(string, **kwargs):
42 new_string = string
43 for key, val in kwargs.items():
44 new_string = new_string.replace('$(%s)' % key, val)
46 return new_string
49 def make_complete_mar_name(target_dir, filename_prefix):
50 filename = filename_prefix + "_complete.mar"
51 return os.path.join(target_dir, filename)