-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·88 lines (60 loc) · 1.77 KB
/
main.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
#!/usr/bin/env python
'''Wrapper script that manages multiple installed projects/tools'''
import os
import shlex
from argh import add_commands, dispatch
from argparse import ArgumentParser
from json import load as json_load
ROOT_DIR = os.path.realpath(os.path.dirname(__file__))
commands = []
env = {}
def prepare():
os.environ['PACKAGE_ROOT_DIR'] = ROOT_DIR
# setup virtualenv
os.environ['PATH'] = ':'.join([
os.path.join(ROOT_DIR, '.virtualenv', 'bin'),
os.environ['PATH'],
])
os.environ['PYTHONPATH'] = os.path.join(ROOT_DIR, 'python_modules')
def build(*args):
prepare()
if len(args) == 1:
args = shlex.split(args[0])
# my build tool is broken ;(
# quick fix: force clean for each build
binargs = ['waf', 'clean', 'build'] + list(args)
os.execvp(binargs[0], binargs)
commands.append(build)
def waf(*args):
prepare()
if len(args) == 1:
args = shlex.split(args[0])
binargs = ['waf'] + list(args)
os.execvp(binargs[0], binargs)
commands.append(waf)
def pip(*args):
prepare()
if len(args) == 1:
args = shlex.split(args[0])
binargs = ['pip'] + list(args)
os.execvp(binargs[0], binargs)
commands.append(pip)
def alembic(*args):
prepare()
if len(args) == 1:
args = shlex.split(args[0])
binargs = ['alembic'] + list(args)
os.execvp(binargs[0], binargs)
commands.append(alembic)
def runserver(*args):
prepare()
if len(args) == 1:
args = shlex.split(args[0])
os.chdir(os.path.join(ROOT_DIR, 'server'))
binargs = ['python', 'main.py'] + list(args)
os.execvp(binargs[0], binargs)
commands.append(runserver)
if __name__ == '__main__':
parser = ArgumentParser()
add_commands(parser, commands)
dispatch(parser)