-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-portable.py
88 lines (62 loc) · 2.18 KB
/
make-portable.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def pack(version: str, base: str):
import os
import shutil
pname = "nomacs-" + version
binarydir = "/installer/nomacs.x64"
dstdir = "/installer/" + pname
licenses = "/ImageLounge/license"
zipname = "nomacs-portable-win.zip"
zippath = base + "/installer/" + zipname
dst = base + dstdir
# collect all files
copytree(base + binarydir, dst)
copytree(base + licenses, dst + "/license")
# create empty settings.ini (nomacs will then recognize that it's portable)
open(dst + "/settings.ini", 'w').close()
# zip
nf = zip(dst, zippath, pname)
# clean up
shutil.rmtree(dst)
zipsize = os.stat(zippath).st_size / (1024*1024) # -> MB
print(("[nomacs portable] %d files zipped to %s [%.2f MB] ") % (nf, zipname, zipsize))
def zip(src: str, dst: str, zipbase: str):
import zipfile
numfiles = 0
with zipfile.ZipFile(dst, 'w', zipfile.ZIP_DEFLATED) as zh:
# zip everything
for root, dirs, files in os.walk(src):
base = root.replace(src, zipbase)
for file in files:
zh.write(os.path.join(root, file), os.path.join(base, file))
numfiles += 1
return numfiles
def copytree(src: str, dst: str, ext: str = "", symlinks: bool = False, ignore: bool = None):
import shutil
import os
if not os.path.exists(dst):
os.mkdir(dst)
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
copytree(s, d, ext, symlinks, ignore)
elif ext:
if s.endswith(ext):
shutil.copyfile(s, d)
else:
shutil.copyfile(s, d)
if __name__ == "__main__":
import argparse
import sys, os
from utils.config import repopath
parser = argparse.ArgumentParser(
description='packs nomacs portable.')
parser.add_argument("version", type=str,
help="""current nomacs version""")
rp = repopath(sys.argv[0])
print(rp)
args = parser.parse_args()
if not os.path.exists(rp):
print("repository path does not exist: " + rp)
exit()
pack(args.version, rp)