-
Notifications
You must be signed in to change notification settings - Fork 1
/
release
executable file
·70 lines (52 loc) · 1.83 KB
/
release
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
#!/usr/bin/env python3
# encoding: utf-8
# we could also use twitter pex
import os
import sys
import glob
import shutil
import zipapp
import argparse
# To late for it .. but here as a reminder that it can be done
os.environ['PYTHONDONTWRITEBYTECODE'] = ""
FOLDER = os.path.dirname(os.path.realpath(__file__))
IMPORT = os.path.abspath(os.path.join(FOLDER, 'lib'))
if not os.path.exists(IMPORT):
sys.exit(f'could not import "{IMPORT}"')
sys.path = [IMPORT]
from vyosextra.insource import generate
from vyosextra.insource import location
def remove_cache():
for name in glob.glob('./lib/*/__pycache__'):
shutil.rmtree(name)
for name in glob.glob('./lib/*/*/__pycache__'):
shutil.rmtree(name)
for name in glob.glob('./lib/*/*.pyc'):
os.remove(name)
for name in glob.glob('./lib/*/*/*.pyc'):
os.remove(name)
def release(target, debug):
params = {
'source': 'lib',
'target': target,
'interpreter': '/usr/bin/env python3',
'main': 'vyosextra.main:main',
}
if debug:
params['interpreter'] = '/usr/bin/env VYOSEXTRA_DEBUG=1 python3'
if sys.version_info.minor >= 7:
params['compressed'] = not debug
here = os.path.dirname(os.path.realpath(__file__))
data = os.path.abspath(os.path.join(here, 'data'))
generate(data)
remove_cache()
zipapp.create_archive(**params)
os.remove(location())
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='build vyos tool')
parser.add_argument('target', help='name of the binary to create', default='./vyos')
parser.add_argument('-d', '--debug', help='run python with pdb', action='store_true')
arg = parser.parse_args()
if sys.version_info.minor < 5:
sys.exit('zipapp is only available with python 3.5+')
release(arg.target, arg.debug)