Home | History | Annotate | Download | only in tko
      1 #!/usr/bin/python
      2 
      3 import cgi, traceback, urllib2
      4 import common
      5 from autotest_lib.frontend.afe.json_rpc import serviceHandler
      6 
      7 script = """\
      8 Content-Type: text/javascript
      9 
     10 %(callback)s(%(result)s);
     11 """
     12 
     13 class LogFileNotFound(Exception):
     14     pass
     15 
     16 form = cgi.FieldStorage(keep_blank_values=True)
     17 encoded_request = form['request'].value
     18 callback = form['callback'].value
     19 
     20 request = serviceHandler.ServiceHandler.translateRequest(encoded_request)
     21 parameters = request['params'][0]
     22 path = parameters['path']
     23 
     24 result_dict = serviceHandler.ServiceHandler.blank_result_dict()
     25 try:
     26     file_contents = urllib2.urlopen('http://localhost' + path).read()
     27     result_dict['result'] = file_contents
     28 except urllib2.HTTPError:
     29     result_dict['err'] = LogFileNotFound('%s not found' % path)
     30     result_dict['err_traceback'] = traceback.format_exc()
     31 
     32 encoded_result = serviceHandler.ServiceHandler.translateResult(result_dict)
     33 print script % dict(callback=callback, result=encoded_result)
     34