forked from the-blue-alliance/the-blue-alliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
209 lines (169 loc) · 6.79 KB
/
pavement.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Easy paver commands for less command typing and more coding.
# Visit http://paver.github.com/paver/ to get started. - @brandondean Sept. 30
import subprocess
import json
import time
import optparse
import os
import re
from paver.easy import *
path = path("./")
@task
@cmdopts([
optparse.make_option("-p", "--project", help="App Engine project to deploy", default="tbatv-prod-hrd"),
optparse.make_option("--yolo", action="store_true", help="Do not wait for the travis build to succeed #yolo", default=False),
optparse.make_option("--config", help="gcloud SDK configuration profile to use", default=""),
optparse.make_option("--version", help="App engine version to deploy", default=""),
optparse.make_option("--modules", help="Comma separated names of module yaml files to deploy", default=""),
optparse.make_option("--skip-cron", action="store_true", help="Do not deploy cron.yaml", default=False),
optparse.make_option("--app-cfg-dir", help="Place to find appcfg.py [deprecated]", default=""),
])
def deploy(options):
args = ["python", "deploy.py", "--project", options.deploy.project]
if options.deploy.yolo:
args.append("--yolo")
if options.deploy.config:
args.extend(["--config", options.deploy.config])
if options.deploy.version:
args.extend(["--version", options.deploy.version])
if options.deploy.modules:
args.extend(["--modules", options.deploy.modules])
if options.skip_cron:
args.append("--skip-cron")
if options.app_cfg_dir:
args.extend(["--app-cfg-dir", options.app_cfg_dir])
print "Running {}".format(subprocess.list2cmdline(args))
subprocess.call(args)
@task
def javascript():
"""Combine Compress Javascript"""
print("Combining and Compressing Javascript")
sh("python do_compress.py js")
@task
def gulp():
"""Update all npm dependencies and run 'gulp build' task"""
print("Running 'gulp build'")
sh("npm update && gulp build --production")
@task
def install_libs():
sh("pip install -r deploy_requirements.txt -t lib")
@task
def jinja2():
sh("python compile_jinja2_templates.py")
@task
def less():
"""Build and Combine CSS"""
print("Building and Combining CSS")
sh("lessc static/css/less_css/tba_style.main.less static/css/less_css/tba_style.main.css")
sh("lessc static/css/less_css/tba_style.gameday.less static/css/less_css/tba_style.gameday.css")
sh("python do_compress.py css")
@task
@cmdopts([
('commit=', 'c', 'Commit hash to lint'),
('base=', 'b', 'Lint all changes between the current HEAD and this base branch'),
])
def lint(options):
args = ""
if 'base' in options.lint:
args = "--base {}".format(options.lint.base)
elif 'commit' in options.lint:
args = "--commit {}".format(options.lint.commit)
sh("python ops/linter.py {}".format(args))
@task
def make():
javascript()
gulp()
less()
jinja2()
build_time = time.ctime()
travis_job = os.environ.get('TRAVIS_BUILD_ID', '')
try:
git_branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
git_last_commit = subprocess.check_output(["git", "log", "-1"])
except Exception:
print "No git history found, falling back to defaults..."
git_branch_name = 'dev'
git_last_commit = 'dev'
data = {"git_branch_name": git_branch_name,
"git_last_commit": git_last_commit,
"build_time": build_time,
"build_number": travis_job,
}
with open("version_info.json", "w") as f:
f.write(json.dumps(data))
@task
def make_endpoints_config():
sh("python lib/endpoints/endpointscfg.py get_openapi_spec mobile_main.MobileAPI --hostname tbatv-prod-hrd.appspot.com")
@task
def preflight():
"""Prep a prod push"""
install_libs()
test_function([])
make()
@task
def run():
"""Run local dev server"""
sh("dev_appserver.py dispatch.yaml app.yaml app-backend-tasks.yaml app-backend-tasks-b2.yaml api.yaml clientapi.yaml tasks.yaml")
@task
@consume_args
def test(args):
"""Run tests. Accepts an argument to match subnames of tests"""
test_function(args)
@task
def setup():
sh("pip install -r requirements.txt")
install_libs()
make()
@task
def test_fast():
"""Run tests that don't require HTTP"""
print("Running Fast Tests")
sh("python run_tests.py --test_pattern=test_math_*.py")
sh("python run_tests.py --test_pattern=test_*helper*.py")
sh("python run_tests.py --test_pattern=test_*parser*.py")
sh("python run_tests.py --test_pattern=test_*manipulator.py")
sh("python run_tests.py --test_pattern=test_*api.py")
sh("python run_tests.py --test_pattern=test_event.py")
sh("python run_tests.py --test_pattern=test_match_cleanup.py")
sh("python run_tests.py --test_pattern=test_event_group_by_week.py")
sh("python run_tests.py --test_pattern=test_event_team_repairer.py")
sh("python run_tests.py --test_pattern=test_event_team_updater.py")
sh("python run_tests.py --test_pattern=test_event_get_short_name.py")
@task
@cmdopts([
optparse.make_option("--key", help="Event, Team, or Match key to import", default="2016necmp"),
optparse.make_option("--project", help="App Engine Project", default=""),
optparse.make_option("--port", type=int, help="Local port running the API server", default=None),
])
def bootstrap(options):
"""Download and import an event or team from apiv3"""
log = '/var/log/tba.log'
key = options.bootstrap.key
url = None
if options.bootstrap.project:
url = "https://{}.appspot.com".format(options.bootstrap.project)
elif os.path.exists(log) and os.path.isfile(log):
prog = re.compile('Starting API server at: http://localhost:(\d{5})$')
with open(log, 'r') as f:
for line in f:
result = prog.search(line.strip())
if result:
url = "localhost:{}".format(result.group(1))
break
if not url:
if "port" not in options.bootstrap or not options.bootstrap.port:
print "Unable to find GAE remote API port, either tee the log to {} or provide --port".format(log)
return
url = "localhost:{}".format(options.bootstrap.port)
args = ["python", "bootstrap.py", "--url", url, key]
print "Running {}".format(subprocess.list2cmdline(args))
subprocess.call(args)
@task
def devserver():
sh("dev_appserver.py --skip_sdk_update_check=true --admin_host=0.0.0.0 --host=0.0.0.0 --datastore_path=/datastore/tba.db dispatch.yaml app.yaml app-backend-tasks.yaml app-backend-tasks-b2.yaml api.yaml clientapi.yaml tasks.yaml")
def test_function(args):
print("Running Tests")
test_pattern = ""
if len(args) > 0:
test_pattern = " --test_pattern=*%s*" % args[0]
sh("python run_tests.py%s" % test_pattern)