blob: ffb4d65b4efdaf4c4244d575a0514ba1df9dad2b [file] [log] [blame]
showard9484c312009-01-07 21:07:28 +00001#!/usr/bin/python
2
showard2df3c692009-09-11 18:41:07 +00003import cgi, traceback, urllib2
showardef6fe022009-03-27 20:55:16 +00004import common
5from autotest_lib.frontend.afe.json_rpc import serviceHandler
showard9484c312009-01-07 21:07:28 +00006
7script = """\
8Content-Type: text/javascript
9
10%(callback)s(%(result)s);
11"""
12
showardef6fe022009-03-27 20:55:16 +000013class LogFileNotFound(Exception):
14 pass
15
16form = cgi.FieldStorage(keep_blank_values=True)
17encoded_request = form['request'].value
showard9484c312009-01-07 21:07:28 +000018callback = form['callback'].value
19
showardef6fe022009-03-27 20:55:16 +000020request = serviceHandler.ServiceHandler.translateRequest(encoded_request)
21parameters = request['params'][0]
22path = parameters['path']
23
showard2df3c692009-09-11 18:41:07 +000024result_dict = serviceHandler.ServiceHandler.blank_result_dict()
showard9484c312009-01-07 21:07:28 +000025try:
26 file_contents = urllib2.urlopen('http://localhost' + path).read()
showard2df3c692009-09-11 18:41:07 +000027 result_dict['result'] = file_contents
showard9484c312009-01-07 21:07:28 +000028except urllib2.HTTPError:
showard2df3c692009-09-11 18:41:07 +000029 result_dict['err'] = LogFileNotFound('%s not found' % path)
30 result_dict['err_traceback'] = traceback.format_exc()
showard9484c312009-01-07 21:07:28 +000031
showard2df3c692009-09-11 18:41:07 +000032encoded_result = serviceHandler.ServiceHandler.translateResult(result_dict)
showardef6fe022009-03-27 20:55:16 +000033print script % dict(callback=callback, result=encoded_result)