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