-
Notifications
You must be signed in to change notification settings - Fork 4
/
dev_build.py
95 lines (81 loc) · 3.15 KB
/
dev_build.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
89
90
91
92
93
94
95
from tempfile import mkstemp
from shutil import move
from os import remove, close
import subprocess
import sys
import re
import datetime
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def main():
start_time = datetime.datetime.now()
print "\n"
print bcolors.WARNING + "\tBegin build for development" + bcolors.ENDC
print "\n"
replace('settingslocal.py','MEDIA_COMPRESSED = True', 'MEDIA_COMPRESSED = False')
print "\tMedia will no longer be compressed"
replace('settingslocal.py','MEDIA_MERGED = True', 'MEDIA_MERGED = False')
print "\tMedia will no longer be merged"
replace('settingslocal.py','ENABLE_APPSTATS = True', 'ENABLE_APPSTATS = False')
print "\tAppStats is now disabled"
replace('settingslocal.py','DEBUG = False', 'DEBUG = True')
print "\tDebug is now enabled"
replace('settingslocal.py','TEMPLATE_DEBUG = False', 'TEMPLATE_DEBUG = "DEBUG"')
print "\tTemplate Debug is now enabled"
replace('settingslocal.py','CACHE_TEMPLATES = True', 'CACHE_TEMPLATES = False')
print "\tTemplates will now no longer be cached"
print "\n"
print "\tStarting build script..."
process = subprocess.Popen("ant set_cachebuster clean-no-flex stage-no-flex", shell=True,
stdout=subprocess.PIPE)
stdout = process.communicate()[0]
swf_num = 1
web_num = 1
if stdout:
stdout = stdout.split('\n')
for line in stdout:
if 'max.svn.swf.revision=' in line:
swf_num = line.split('=')[1]
elif 'max.svn.web.revision=' in line:
web_num = line.split('=')[1]
print "\tSetting SWF_REVISION = '%s'" % swf_num
print "\tSetting WEB_REVISION = '%s'" % web_num
replace('settingslocal.py',"SWF_REVISION = '(.*)'","SWF_REVISION = '%s'" % swf_num)
replace('settingslocal.py',"WEB_REVISION = '(.*)'","WEB_REVISION = '%s'" % web_num)
# Edit app.yaml
replace('app.yaml',"application: (.*)", "application: big-sky")
replace('app.yaml','(version: )(?!.*\").*', "version: 1", 10)
print bcolors.OKGREEN + "\tDev build completed." + bcolors.ENDC
# subprocess.Popen('say "Dev build completed."', shell=True)
net_time = datetime.datetime.now() - start_time
devnull = open('/dev/null', 'w')
subprocess.Popen('terminal-notifier -message "The dev build has completed successfully after %s seconds." -title "Dev Build Completed"' % net_time.seconds, shell=True, stdout=subprocess.PIPE, stderr=devnull)
print "\n"
sys.exit()
def replace(file, pattern, subst, limit=None):
# Create temp file
fh, abs_path = mkstemp()
new_file = open(abs_path,'w')
old_file = open(file)
counter = 0
for line in old_file:
counter += 1
if not limit or counter < limit:
new_file.write(re.sub(pattern, subst, line))
else:
new_file.write(line)
# Close temp file
new_file.close()
close(fh)
old_file.close()
# Remove original file
remove(file)
# Move new file
move(abs_path, file)
if __name__ == '__main__':
main()