diff options
author | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-03-27 20:55:16 +0000 |
---|---|---|
committer | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-03-27 20:55:16 +0000 |
commit | ab4d4003903891a5cc66bd28941770656bfd8bf6 (patch) | |
tree | 920d654c386d29db1851981b7b37dccfe6400074 /tko/retrieve_logs.cgi | |
parent | d0ec4aa6a8a06673dc40ed9bdb22ccfd9cbbe3c3 (diff) |
generic JSON-RPC implementation using JSONP (JSON with Padding). the central part of this change consists of:
* refactored JsonRpcProxy to extract all XmlHttpRequest-specific logic into a new XhrHttpRequest subclass, and made JsonRpcProxy abstract
* introduced new PaddedJsonRpcProxy subclass of XmlHttpRequest that uses JSONP instead of XHR
* added new handle_jsonp_rpc_request() method to rpc_handler.py, to handle JSONP requests on the server side
This enables the entire frontend (either AFE or TKO) to operate via JSONP instead of XHR. I didn't make them do that now, since there's no reason, but it will be critical when we go to make components embeddable in other pages (on other domains). Other changes here include:
* made TestDetailView use PaddedJsonRpcProxy (it previous had its own custom JSONP logic, which was all moved into PaddedJsonRpcProxy).
* made retrieve_logs.cgi and jsonp_fetcher.cgi support JSONP requests, so that log fetching requests could go through the shared JsonRpcProxy codepath. retrieve_logs.cgi still supports the old GET params interface for backwards compatibility (at least old TKO still uses it, and possible other scripts).
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@2943 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/retrieve_logs.cgi')
-rwxr-xr-x | tko/retrieve_logs.cgi | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/tko/retrieve_logs.cgi b/tko/retrieve_logs.cgi index 2097f170..fb4a52ea 100755 --- a/tko/retrieve_logs.cgi +++ b/tko/retrieve_logs.cgi @@ -4,36 +4,36 @@ import cgi, os, sys, urllib2 import common from autotest_lib.client.common_lib import global_config from autotest_lib.client.bin import utils +from autotest_lib.frontend.afe.json_rpc import serviceHandler -page = """\ +_PAGE = """\ Status: 302 Found Content-Type: text/plain Location: %s\r\n\r """ -# Get access to directories -tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) -sys.path.insert(0, tko) - -autodir = os.path.abspath(os.path.join(tko, '..')) - - +# Define function for retrieving logs def _retrieve_logs_dummy(job_path): pass - -# Define function for retrieving logs retrieve_logs = utils.import_site_function(__file__, "autotest_lib.tko.site_retrieve_logs", "retrieve_logs", _retrieve_logs_dummy) - -# Get form fields form = cgi.FieldStorage(keep_blank_values=True) -# Retrieve logs -job_path = form['job'].value -job_path = os.path.join(autodir, job_path) -keyval = retrieve_logs(job_path) +# determine if this is a JSON-RPC request. we support both so that the new TKO +# client can use its RPC client code, but the old TKO can still use simple GET +# params. +_is_json_request = form.has_key('callback') + +def _get_requested_path(): + if _is_json_request: + request_data = form['request'].value + request = serviceHandler.ServiceHandler.translateRequest(request_data) + parameters = request['params'][0] + return parameters['path'] + + return form['job'].value def find_repository_host(job_path): @@ -59,19 +59,20 @@ def find_repository_host(job_path): return None -def get_full_path(host, path): +def get_full_url(host, path): if host: prefix = 'http://' + host else: prefix = '' - if form.has_key('jsonp_callback'): - callback = form['jsonp_callback'].value - return '%s/tko/jsonp_fetcher.cgi?path=%s&callback=%s' % ( - prefix, path, callback) + if _is_json_request: + return '%s/tko/jsonp_fetcher.cgi?%s' % (prefix, + os.environ['QUERY_STRING']) else: return prefix + path -host = find_repository_host(job_path) -print page % get_full_path(host, job_path) +log_path = _get_requested_path() +retrieve_logs(log_path) +host = find_repository_host(log_path) +print _PAGE % get_full_url(host, log_path) |