-
Notifications
You must be signed in to change notification settings - Fork 5
/
manage.py
executable file
·68 lines (57 loc) · 2.01 KB
/
manage.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
#!/usr/bin/env python
import argparse
import subprocess
sh = lambda cmd: print(cmd) or subprocess.call(cmd, shell=True)
ssh = lambda cmd: sh(
'ssh yadro.org "%s"'
% cmd.replace('"', '\"').replace('$', '\$')
)
def process_args(args=None):
parser = argparse.ArgumentParser()
subs = parser.add_subparsers(title='subcommands')
def sub(name, **kw):
s = subs.add_parser(name, **kw)
s.set_defaults(sub=name)
s.arg = lambda *a, **kw: s.add_argument(*a, **kw) and s
s.exe = lambda f: s.set_defaults(exe=f) and s
return s
sub('deploy', help='deploy to server')\
.arg(
'-t', '--target', default='origin/master',
help='target for checkout'
)\
.exe(lambda a: ssh(
'cd /home/pusto/src'
'&& git fetch origin'
'&& git checkout {target}'
'&& source $(cat .venv)/bin/activate'
'&& ./manage.py bootstrap'
'&& ./pusto.py build -b build-tmp'
'&& rm -rf build'
'&& mv build-tmp build'
'&& systemctl restart nginx.service'
.format(target=a.target)
))
sub('bootstrap', help='install dependencies')\
.exe(lambda a: sh('pip install -r requirements.txt --no-index'))
sub('wheels', help='prepare wheels')\
.exe(lambda a: sh(
'pip wheel -r requirements.txt -w wheels'
'&& pip install --no-install -d wheels wheel'
))
sub('napokaz', help='napokaz updater')\
.arg('--push', action='store_true')\
.arg('--init', action='store_true')\
.exe(lambda a: sh(
'git remote add napokaz git@github.com:naspeh/napokaz.git'
if a.init else
'git subtree %s -P data/s/napokaz/src napokaz master'
% ('push' if a.push else 'pull --squash')
))
args = parser.parse_args(args)
if not hasattr(args, 'sub'):
parser.print_usage()
else:
args.exe(args)
if __name__ == '__main__':
process_args()