Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / pass-desktop / tools / update-metadata.py
blob959b4d4bf74cbb708315202ea410c65a3439da3b
1 import os
2 import sys
3 import json
4 import hashlib
5 from datetime import datetime, timezone
6 import sys
8 script_dir = os.path.dirname(os.path.realpath(__file__))
9 project_root = os.path.dirname(script_dir)
10 platform = sys.argv[1]
11 channel = sys.argv[2]
13 def sha512sum(filename):
14 h = hashlib.sha512()
15 with open(filename, "rb") as f:
16 for chunk in iter(lambda: f.read(4096), b""):
17 h.update(chunk)
18 return h.hexdigest()
20 def to_release_file(file):
21 name = file['Name']
22 dl_base = f"https://proton.me/download/pass/{platform}"
23 sha = sha512sum(os.path.join(file['Dir'], name))
25 release_file = {
26 'Url': f"{dl_base}/{file['Name']}",
27 'Sha512CheckSum': sha,
28 'Args': '',
31 if 'Identifier' in file:
32 release_file['Identifier'] = file['Identifier']
34 return release_file
36 def main():
37 if channel is None:
38 print("PASS_RELEASE_CHANNEL not set")
39 sys.exit(1)
41 with open(os.path.join(project_root, "package.json")) as f:
42 version = json.load(f)["version"]
44 files = []
46 if platform == "windows":
47 files.append({
48 'Name': f"ProtonPass_Setup_{version}.exe",
49 'Dir': os.path.join(project_root, 'out', 'make', 'squirrel.windows', 'x64'),
51 elif platform == "macos":
52 files.append({
53 'Name': f"ProtonPass_{version}.dmg",
54 'Dir': os.path.join(project_root, 'out', 'make'),
56 elif platform == "linux":
57 files.append({
58 'Name': f"proton-pass_{version}_amd64.deb",
59 'Identifier': '.deb (Ubuntu/Debian)',
60 'Dir': os.path.join(project_root, 'out', 'make', 'deb', 'x64'),
62 files.append({
63 'Name': f"proton-pass-{version}-1.x86_64.rpm",
64 'Identifier': '.rpm (Fedora/RHEL)',
65 'Dir': os.path.join(project_root, 'out', 'make', 'rpm', 'x64'),
68 now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
69 version_json_path = f"assets/{platform}/version.json"
70 if not os.path.isfile(version_json_path):
71 with open(version_json_path, "w") as f:
72 json.dump({"Releases": []}, f)
74 with open(version_json_path) as f:
75 version_json = json.load(f)
77 new_release = {
78 "CategoryName": channel,
79 "Version": version,
80 "ReleaseDate": now,
81 "RolloutPercentage": 0.2,
82 "File": list(map(to_release_file, files))
85 version_json["Releases"].insert(0, new_release)
86 with open(version_json_path, "w") as f:
87 print(f"*** Prepending {new_release}")
88 json.dump(version_json, f, indent=2)
89 f.write("\n")
91 if __name__ == "__main__":
92 main()