forked from bugy/script-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.py
More file actions
executable file
·60 lines (43 loc) · 1.74 KB
/
Copy pathinit.py
File metadata and controls
executable file
·60 lines (43 loc) · 1.74 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
57
58
59
60
#!/usr/bin/env python3
import argparse
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..', 'src'))
from utils.env_utils import EnvVariables
from utils.process_utils import ProcessInvoker
def download_web_files(project_path):
print('Downloading web files...')
from io import BytesIO
from zipfile import ZipFile
from urllib.request import urlopen
response = urlopen('https://github.com/bugy/script-server/releases/download/dev/script-server.zip')
with ZipFile(BytesIO(response.read())) as zipfile:
for file in zipfile.namelist():
if file.startswith('web/'):
zipfile.extract(file, project_path)
print('Done')
def build_web_files(project_path):
process_invoker = ProcessInvoker(EnvVariables(os.environ))
print('Building web...')
work_dir = os.path.join(project_path, 'web-src')
process_invoker.invoke('npm install', work_dir)
process_invoker.invoke('npm run build', work_dir)
print('Done')
def prepare_project(project_path, *, download_web=False):
if download_web:
download_web_files(project_path)
else:
build_web_files(project_path)
runners_conf = os.path.join(project_path, 'conf', 'runners')
if not os.path.exists(runners_conf):
os.makedirs(runners_conf)
if __name__ == "__main__":
script_folder = sys.path[0]
if script_folder:
project_path = os.path.abspath(os.path.join(script_folder, '..'))
else:
project_path = ''
parser = argparse.ArgumentParser(description='Initializes source code repo to make it runnable')
parser.add_argument('--no-npm', action='store_true', default=False)
args = vars(parser.parse_args())
prepare_project(project_path, download_web=args['no_npm'])