-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·61 lines (52 loc) · 1.55 KB
/
build.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
import secrets
import argparse
import git
sys.setrecursionlimit(5000)
parser = argparse.ArgumentParser()
parser.add_argument("--web", help="build web app", action="store_true")
parser.add_argument("-v", help="generate version file", action="store_true")
args = parser.parse_args()
# generate random key
key = str(secrets.token_urlsafe(32))
# optmize level
optimize=1
# version
version="0.3"
def generate_version():
local_repo = git.Repo(".")
COMMIT=list(local_repo.iter_commits("master"))[0]
VERSION = [
COMMIT.hexsha,
COMMIT.committed_datetime.strftime("%Y-%m-%d"),
]
with open('VERSION', mode='wt', encoding='utf-8') as f:
f.write("\n".join(VERSION))
if sys.platform == 'win32':
cmdargs = ["set","PYTHONOPTIMIZE="+str(optimize),'&&']
delimiter = ';'
else:
cmdargs = ["PYTHONOPTIMIZE="+str(optimize)]
delimiter = ':'
cmdargs = cmdargs + [
"pyinstaller",
"--key="+key,
'-F',
'--clean',
'--hidden-import cmath',
]
if args.web:
generate_version()
name="mbztool"
webargs = cmdargs + [
'-n',name+'_'+version,
'--add-data=\"web'+delimiter+'./web\"',
'--add-data=\"VERSION'+delimiter+'.\"',
'app.py',
]
os.system(" ".join(webargs))
if args.v:
generate_version()