Skip to content

Commit 3449818

Browse files
committed
Obtain scenario cache from Github. Color output.
1 parent c38588f commit 3449818

File tree

3 files changed

+29
-635
lines changed

3 files changed

+29
-635
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ dist/
4040
.idea/
4141
_build/
4242
coverage.xml
43+
scenario.cache

render_scenarios.py

+28-16
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
import json
44
import balanced
55
import pprint
6+
import requests
7+
import sys
8+
69
from pprint import PrettyPrinter
710
from mako.template import Template
811
from mako.lookup import TemplateLookup
912

13+
class colors:
14+
GREEN = '\033[92m'
15+
YELLOW = '\033[93m'
16+
RED = '\033[91m'
17+
RESET = '\033[0m'
18+
19+
SCENARIO_CACHE_URL = 'https://raw.githubusercontent.com/balanced/balanced-docs/master/scenario.cache'
20+
1021
def construct_response(scenario_name):
1122
# load up response data
1223
data = json.load(open('scenario.cache','r'))
@@ -50,8 +61,8 @@ def render_executables():
5061
request=request, payload=payload).strip()
5162
except KeyError:
5263
text = ''
53-
print "WARN: Skipped {} since {} not in scenario.cache".format(
54-
path, event_name)
64+
print colors.YELLOW + "WARN: Skipped {} since {} not in scenario.cache".format(
65+
path, event_name) + colors.RESET
5566
with open(os.path.join(os.path.dirname(path),
5667
'executable.py'), 'w+') as write_to:
5768
write_to.write(text)
@@ -68,23 +79,24 @@ def render_mako():
6879
"% elif mode == 'response':\n" + response + "\n% endif"
6980
wfile.write(body)
7081

71-
def issue_no_mako_warnings():
72-
73-
set_has_mako = set([])
74-
set_no_python_mako = set([])
75-
for path in glob2.glob('./scenarios/**/*.mako'):
76-
set_has_mako.add(os.path.dirname(path))
77-
for path in glob2.glob('./scenarios/**/python.mako'):
78-
set_no_python_mako.add(os.path.dirname(path))
79-
print 'The following dont have a python.mako file. Look into it!'
80-
print set_has_mako.difference(set_no_python_mako)
81-
82+
def fetch_scenario_cache():
83+
try:
84+
os.remove('scenario.cache')
85+
except OSError:
86+
pass
8287

88+
with open('scenario.cache', 'wb') as fo:
89+
response = requests.get(SCENARIO_CACHE_URL)
90+
if not response.ok:
91+
sys.exit()
92+
for block in response.iter_content():
93+
fo.write(block)
8394

8495
if __name__ == "__main__":
85-
print "Making Executables"
96+
print colors.GREEN + "Obtaining scenario cache..." + colors.RESET
97+
fetch_scenario_cache()
98+
print colors.GREEN + "Making Executables..." + colors.RESET
8699
render_executables()
87-
print "Rendering new mako files"
100+
print colors.GREEN + "Rendering new mako files..." + colors.RESET
88101
render_mako()
89-
issue_no_mako_warnings()
90102

0 commit comments

Comments
 (0)