Index: gm/rebaseline_server/server.py |
diff --git a/gm/rebaseline_server/server.py b/gm/rebaseline_server/server.py |
index f817597a0f69d72684c7b386a2a38b372ac1de97..f5b3a54ed5f437f0c396b209b300388c2efae02c 100755 |
--- a/gm/rebaseline_server/server.py |
+++ b/gm/rebaseline_server/server.py |
@@ -218,7 +218,9 @@ class Server(object): |
at all, just compare to whatever files are already in actuals_dir |
port: which TCP port to listen on for HTTP requests |
export: whether to allow HTTP clients on other hosts to access this server |
- editable: whether HTTP clients are allowed to submit new baselines |
+ editable: whether HTTP clients are allowed to submit new GM baselines |
+ (SKP baseline modifications are performed using an entirely different |
+ mechanism, not affected by this parameter) |
reload_seconds: polling interval with which to check for new results; |
if 0, don't check for new results at all |
config_pairs: List of (string, string) tuples; for each tuple, compare |
@@ -293,7 +295,7 @@ class Server(object): |
@property |
def is_editable(self): |
- """ Returns true iff HTTP clients are allowed to submit new baselines. """ |
+ """ True iff HTTP clients are allowed to submit new GM baselines. """ |
return self._editable |
@property |
@@ -524,6 +526,49 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
} |
self.send_json_dict(response_dict) |
+ def _get_live_results_or_prefetch(self, url_remainder, prefetch_only=False): |
+ """ Handle a GET request for live-generated image diff data. |
+ |
+ Args: |
+ url_remainder: string indicating which image diffs to generate |
+ prefetch_only: if True, the user isn't waiting around for results |
+ """ |
+ param_dict = urlparse.parse_qs(url_remainder) |
+ download_all_images = ( |
+ param_dict.get(LIVE_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower() |
+ not in ['1', 'true']) |
+ setA_section = self._validate_summary_section( |
+ param_dict.get(LIVE_PARAM__SET_A_SECTION, [None])[0]) |
+ setB_section = self._validate_summary_section( |
+ param_dict.get(LIVE_PARAM__SET_B_SECTION, [None])[0]) |
+ |
+ # Is the user in a position to submit new baselines? |
+ # |
+ # TODO(epoger): For now, we only allow rebaselining if the expectations |
+ # are on the left-hand side. In a coming CL, I would like to automatically |
+ # flip the two sides if a user requests setA=actuals, setB=expected. |
+ # Right now that is difficult to do, though, because the JSON generated by |
+ # RenderedPicturesComparisons doesn't include full setA/setB descriptions, |
+ # so the UI has to trust that whatever setA/setB were requested were also |
+ # returned. |
+ is_rebaselining = ((setA_section == gm_json.JSONKEY_EXPECTEDRESULTS) and |
+ (setB_section == gm_json.JSONKEY_ACTUALRESULTS)) |
+ |
+ results_obj = compare_rendered_pictures.RenderedPicturesComparisons( |
+ setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR], |
+ setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR], |
+ setA_section=setA_section, setB_section=setB_section, |
+ image_diff_db=_SERVER.image_diff_db, |
+ diff_base_url='/static/generated-images', |
+ gs=_SERVER.gs, truncate_results=_SERVER.truncate_results, |
+ prefetch_only=prefetch_only, download_all_images=download_all_images) |
+ |
+ if prefetch_only: |
+ self.send_response(200) |
+ else: |
+ self.send_json_dict(results_obj.get_packaged_results_of_type( |
+ results_mod.KEY__HEADER__RESULTS_ALL, is_editable=is_rebaselining)) |
+ |
def do_GET_live_results(self, url_remainder): |
""" Handle a GET request for live-generated image diff data. |
@@ -531,11 +576,8 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
url_remainder: string indicating which image diffs to generate |
""" |
logging.debug('do_GET_live_results: url_remainder="%s"' % url_remainder) |
- param_dict = urlparse.parse_qs(url_remainder) |
- results_obj = self._call_compare_rendered_pictures( |
- param_dict=param_dict, prefetch_only=False) |
- self.send_json_dict(results_obj.get_packaged_results_of_type( |
- results_mod.KEY__HEADER__RESULTS_ALL)) |
+ self._get_live_results_or_prefetch( |
+ url_remainder=url_remainder, prefetch_only=False) |
def do_GET_prefetch_results(self, url_remainder): |
""" Prefetch image diff data for a future do_GET_live_results() call. |
@@ -544,10 +586,8 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
url_remainder: string indicating which image diffs to generate |
""" |
logging.debug('do_GET_prefetch_results: url_remainder="%s"' % url_remainder) |
- param_dict = urlparse.parse_qs(url_remainder) |
- self._call_compare_rendered_pictures( |
- param_dict=param_dict, prefetch_only=True) |
- self.send_response(200) |
+ self._get_live_results_or_prefetch( |
+ url_remainder=url_remainder, prefetch_only=True) |
def do_GET_static(self, path): |
""" Handle a GET request for a file under STATIC_CONTENTS_SUBDIR . |
@@ -694,32 +734,6 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
self.end_headers() |
json.dump(json_dict, self.wfile) |
- def _call_compare_rendered_pictures(self, param_dict, prefetch_only): |
- """Instantiates RenderedPicturesComparisons object to serve a GET request. |
- |
- Args: |
- param_dict: dictionary of URL parameters |
- prefetch_only: parameter to pass into RenderedPicturesComparisons |
- constructor |
- |
- Returns: a reference to the new RenderedPicturesComparisons object. |
- """ |
- download_all_images = ( |
- param_dict.get(LIVE_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower() |
- not in ['1', 'true']) |
- setA_section = self._validate_summary_section( |
- param_dict.get(LIVE_PARAM__SET_A_SECTION, [None])[0]) |
- setB_section = self._validate_summary_section( |
- param_dict.get(LIVE_PARAM__SET_B_SECTION, [None])[0]) |
- return compare_rendered_pictures.RenderedPicturesComparisons( |
- setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR], |
- setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR], |
- setA_section=setA_section, setB_section=setB_section, |
- image_diff_db=_SERVER.image_diff_db, |
- diff_base_url='/static/generated-images', |
- gs=_SERVER.gs, truncate_results=_SERVER.truncate_results, |
- prefetch_only=prefetch_only, download_all_images=download_all_images) |
- |
def _validate_summary_section(self, section_name): |
"""Validates the section we have been requested to read within JSON summary. |
@@ -767,7 +781,7 @@ def main(): |
'differences between these config pairs: ' |
+ str(CONFIG_PAIRS_TO_COMPARE))) |
parser.add_argument('--editable', action='store_true', |
- help=('Allow HTTP clients to submit new baselines.')) |
+ help=('Allow HTTP clients to submit new GM baselines.')) |
parser.add_argument('--export', action='store_true', |
help=('Instead of only allowing access from HTTP clients ' |
'on localhost, allow HTTP clients on other hosts ' |