33import json
44import balanced
55import pprint
6+ import requests
7+ import sys
8+
69from pprint import PrettyPrinter
710from mako .template import Template
811from 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+
1021def 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
8495if __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