getjsfile.cgi return js code in json
This commit is contained in:
parent
d9404210e4
commit
d42dc501c2
1 changed files with 19 additions and 5 deletions
|
|
@ -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','<br>')
|
||||
|
||||
Loading…
Add table
Reference in a new issue