@@ -57,15 +57,6 @@ def collect(root_dir):
57
57
yield os .path .join (root , filename )
58
58
59
59
60
- def collect_contents (root_dir ):
61
- files = {}
62
- for path in collect (root_dir ):
63
- relative_path = os .path .relpath (path , root_dir )
64
- with open (path ) as schema_file :
65
- files [relative_path ] = json .load (schema_file )
66
- return files
67
-
68
-
69
60
class SanityTests (unittest .TestCase ):
70
61
@classmethod
71
62
def setUpClass (cls ):
@@ -153,7 +144,11 @@ def main(arguments):
153
144
154
145
json .dump (selected_cases , sys .stdout , indent = 4 , sort_keys = True )
155
146
elif arguments .command == "remotes" :
156
- remotes = collect_contents (REMOTES_DIR )
147
+ remotes = {}
148
+ for path in collect (REMOTES_DIR ):
149
+ relative_path = os .path .relpath (path , REMOTES_DIR )
150
+ with open (path ) as schema_file :
151
+ remotes [relative_path ] = json .load (schema_file )
157
152
json .dump (remotes , sys .stdout , indent = 4 , sort_keys = True )
158
153
elif arguments .command == "dump_remotes" :
159
154
if arguments .update :
@@ -168,7 +163,7 @@ def main(arguments):
168
163
raise
169
164
elif arguments .command == "serve" :
170
165
try :
171
- from flask import Flask , jsonify
166
+ import flask
172
167
except ImportError :
173
168
print (textwrap .dedent ("""
174
169
The Flask library is required to serve the remote schemas.
@@ -181,14 +176,11 @@ def main(arguments):
181
176
""" .strip ("\n " )))
182
177
sys .exit (1 )
183
178
184
- remotes = collect_contents (REMOTES_DIR )
185
- app = Flask (__name__ )
179
+ app = flask .Flask (__name__ )
186
180
187
181
@app .route ("/<path:path>" )
188
182
def serve_path (path ):
189
- if path in remotes :
190
- return jsonify (remotes [path ])
191
- return "Document does not exist." , 404
183
+ return flask .send_from_directory (REMOTES_DIR , path )
192
184
193
185
app .run (port = 1234 )
194
186
0 commit comments