tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / bin / update / create_partial_update.py
blob8dfa370e5fa7d80461f1a102843e245b1c5e6636
1 #!/usr/bin/env python3
2 import json
3 import os
4 import re
5 import subprocess
6 import sys
7 import time
9 from path import UpdaterPath, convert_to_native
10 from signing import sign_mar_file
11 from tools import get_file_info, uncompress_file_to_dir
14 def generate_file_name(old_build_id, mar_name_prefix):
15 name = "%s_from_%s_partial.mar" % (mar_name_prefix, old_build_id)
16 return name
18 def waitforlock(lockfile):
19 while True:
20 try:
21 os.close(os.open(lockfile, os.O_CREAT | os.O_EXCL))
22 break
23 except OSError:
24 print("waiting for lockfile/msiexec already running, sleeping 10s")
25 time.sleep(10)
27 def releaselock(lockfile):
28 os.remove(lockfile)
30 def main():
31 workdir = sys.argv[1]
32 lockfile = os.path.join(workdir,"msiexeclock")
34 updater_path = UpdaterPath(os.path.join(workdir,os.environ.get('ARCH','unknown')))
35 updater_path.ensure_dir_exist()
37 mar_name_prefix = sys.argv[2]
38 channel = sys.argv[3]
39 certificate_path = sys.argv[4]
40 certificate_name = sys.argv[5]
41 base_url = sys.argv[6]
42 product_name = sys.argv[7]
43 version = sys.argv[8]
44 old_msi = sys.argv[9]
45 new_msi_file = sys.argv[10]
47 waitforlock(lockfile)
48 old_uncompress_dir = uncompress_file_to_dir(old_msi, updater_path.get_previous_build_dir())
49 new_uncompress_dir = uncompress_file_to_dir(new_msi_file, updater_path.get_current_build_dir())
50 releaselock(lockfile)
51 versionini = os.path.join(old_uncompress_dir, 'program', 'version.ini') #TODO: Linux, macOS
52 old_build_id = None
53 with open(versionini) as f:
54 for l in f:
55 m = re.fullmatch('buildid=(.*)', l.rstrip())
56 if m:
57 old_build_id = m.group(1)
58 break
59 if old_build_id is None:
60 raise Exception(f'Cannot find buildid in {versionini}')
62 update_dir = updater_path.get_update_dir()
64 file_name = generate_file_name(old_build_id, mar_name_prefix)
65 mar_file = os.path.join(update_dir, file_name)
67 os.putenv('MOZ_PRODUCT_VERSION', version)
68 os.putenv('MAR_CHANNEL_ID', 'LOOnlineUpdater')
69 subprocess.call([os.path.join(workdir, 'UnpackedTarball/onlineupdate/tools/update-packaging/make_incremental_update.sh'), convert_to_native(mar_file),
70 convert_to_native(old_uncompress_dir), convert_to_native(new_uncompress_dir)])
72 sign_mar_file(update_dir, certificate_path, certificate_name, mar_file, mar_name_prefix)
74 data = {
75 'from': old_build_id,
76 'see also': '',
77 'update': get_file_info(mar_file, base_url),
78 'languages': {}
80 with open(os.path.join(update_dir, channel), "w") as f:
81 json.dump(data, f, indent=4)
84 if __name__ == '__main__':
85 main()