3
3
import json
4
4
import balanced
5
5
import pprint
6
+ import requests
7
+ import sys
8
+
6
9
from pprint import PrettyPrinter
7
10
from mako .template import Template
8
11
from mako .lookup import TemplateLookup
9
12
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
+
10
21
def construct_response (scenario_name ):
11
22
# load up response data
12
23
data = json .load (open ('scenario.cache' ,'r' ))
@@ -50,8 +61,8 @@ def render_executables():
50
61
request = request , payload = payload ).strip ()
51
62
except KeyError :
52
63
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
55
66
with open (os .path .join (os .path .dirname (path ),
56
67
'executable.py' ), 'w+' ) as write_to :
57
68
write_to .write (text )
@@ -68,23 +79,24 @@ def render_mako():
68
79
"% elif mode == 'response':\n " + response + "\n % endif"
69
80
wfile .write (body )
70
81
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
82
87
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 )
83
94
84
95
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
86
99
render_executables ()
87
- print "Rendering new mako files"
100
+ print colors . GREEN + "Rendering new mako files..." + colors . RESET
88
101
render_mako ()
89
- issue_no_mako_warnings ()
90
102
0 commit comments