From d42dc501c2a51239bc7535b3d0720392cbb994c0 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 9 Jun 2011 17:43:42 +0530 Subject: [PATCH] getjsfile.cgi return js code in json --- cgi-bin/getjsfile.cgi | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/cgi-bin/getjsfile.cgi b/cgi-bin/getjsfile.cgi index 18a876cead..4e9bbd9ebe 100755 --- a/cgi-bin/getjsfile.cgi +++ b/cgi-bin/getjsfile.cgi @@ -9,6 +9,7 @@ try: form = cgi.FieldStorage() out = '' out_buf, str_out = '', '' + jsonout= {} # Traceback # --------- @@ -21,9 +22,10 @@ try: body = body + "%-20s %s" % (string.join(list[:-1], ""), list[-1]) return body - def load_js_file(): + def load_js_from_file(module_name): global out - filename = form.getvalue('filename') + global jsonout + filename = module_name # TODO replace . by / import os try: f = open(os.path.join('../js/', filename)) @@ -33,6 +35,18 @@ try: f.close() except IOError,e: out = "Not Found: %s" % filename + jsonout[module_name]=out + + def load_js_module(module_name): + if module_name not in jsonout: + dependent_mods = get_dependencies(module_name) + for module in dependent_mods: + load_js_module(module) + load_js_from_file(module_name) + + def get_dependencies(module_name): + return [] + def compress_string(buf): import gzip, cStringIO @@ -49,7 +63,7 @@ try: except: pass - load_js_file() + load_js_module('test.js') if compress and len(out)>512: out_buf = compress_string(str_out) @@ -64,10 +78,10 @@ try: if out_buf: sys.stdout.write(out_buf) elif out: - print out + import json + print json.dumps(jsonout) except Exception, e: print "Content-Type: text/javascript" print print getTraceback().replace('\n','
') - \ No newline at end of file