Repository navigation
Expand file tree
/
Copy pathmake_app.py
More file actions
56 lines (39 loc) · 1.37 KB
/
Copy pathmake_app.py
File metadata and controls
56 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
from os import walk, strerror
from errno import ENOENT
from zipfile import ZipInfo, ZIP_DEFLATED, ZipFile
from time import localtime
from pathlib import Path
from sys import argv
if len(argv) != 3:
print(f"USAGE: {argv[0]} [APP_DIRECTORY] [EXECUTABLE]")
exit(-1)
app_dir = Path(argv[1])
exe = Path(argv[2])
if app_dir.suffix != ".app":
print("Error: " + app_dir + " is not an .app folder.")
exit(-1)
if not app_dir.exists():
raise FileNotFoundError(ENOENT, strerror(ENOENT), app_dir)
if not exe.exists():
raise FileNotFoundError(ENOENT, strerror(ENOENT), exe)
zip_name = app_dir.stem + ".zip"
with ZipFile(zip_name, 'w', ZIP_DEFLATED) as zip_f:
found_bin = False
for root, dirs, files in walk(app_dir):
for fname in files:
path = Path(root, fname)
zip_f.write(path)
mac_os = next((x for x in dirs if x == "MacOS"), None)
if not mac_os:
continue
with open(exe, 'rb') as exe_f:
exe_bytes = exe_f.read()
info = ZipInfo(str(Path(root, mac_os, exe.name[:-1])))
info.date_time = localtime()
info.external_attr = 0o100755 << 16
# UNIX host
info.create_system = 3
print(oct(info.external_attr))
zip_f.writestr(info, exe_bytes, ZIP_DEFLATED)
print("Created " + zip_name)