-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.py
executable file
·61 lines (50 loc) · 1.59 KB
/
deploy.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 python
import sys
import subprocess
from optparse import OptionParser
def load_app_yaml():
input = open('app.yaml', 'r')
lines = input.readlines()
input.close()
while lines and not lines[-1].strip():
lines.pop(-1)
return lines
def update_app_yaml(lines, **kwargs):
output = open('app.yaml', 'w')
for line in lines:
if ':' in line:
key, value = line.split(':', 1)
argname = key.strip().replace('-', '_')
if argname in kwargs:
line = key + ': ' + kwargs[argname] + '\n'
output.write(line)
output.close()
def attempt(command):
print command
returncode = subprocess.call(command.split())
if returncode:
print "failed with return code", returncode
sys.exit(returncode)
def main():
usage = "usage: %prog [options] [version]"
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
if not args:
options.version = 'master'
elif len(args) == 1:
options.version = args[0]
else:
parser.error("Too many command line arguments.")
exclude = ['.git', 'common', 'popular.py',
'english.py', 'french.py', 'spanish.py', 'german.py']
attempt('pep8 --count --repeat --exclude %s .' % ','.join(exclude))
attempt('.git/hooks/pre-commit')
attempt('./manage.py test')
app_yaml = load_app_yaml()
update_app_yaml(app_yaml, version=options.version)
try:
attempt('./manage.py update')
finally:
update_app_yaml(app_yaml)
if __name__ == '__main__':
sys.exit(main())