Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: gm/rebaseline_server/server.py

Issue 453433004: rebaseline_server: allow live queries to examine JSONKEY_EXPECTEDRESULTS or JSONKEY_ACTUALRESULTS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: create ALLOWED_SECTION_NAMES Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2013 Google Inc. 4 Copyright 2013 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 HTTP server for our HTML rebaseline viewer. 9 HTTP server for our HTML rebaseline viewer.
10 """ 10 """
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 GENERATED_HTML_SUBDIR = 'generated-html' 81 GENERATED_HTML_SUBDIR = 'generated-html'
82 GENERATED_IMAGES_SUBDIR = 'generated-images' 82 GENERATED_IMAGES_SUBDIR = 'generated-images'
83 GENERATED_JSON_SUBDIR = 'generated-json' 83 GENERATED_JSON_SUBDIR = 'generated-json'
84 84
85 # Directives associated with various HTTP GET requests. 85 # Directives associated with various HTTP GET requests.
86 GET__LIVE_RESULTS = 'live-results' 86 GET__LIVE_RESULTS = 'live-results'
87 GET__PRECOMPUTED_RESULTS = 'results' 87 GET__PRECOMPUTED_RESULTS = 'results'
88 GET__PREFETCH_RESULTS = 'prefetch' 88 GET__PREFETCH_RESULTS = 'prefetch'
89 GET__STATIC_CONTENTS = 'static' 89 GET__STATIC_CONTENTS = 'static'
90 90
91 # Parameters we use within do_GET_live_results() 91 # Parameters we use within do_GET_live_results() and do_GET_prefetch_results()
92 LIVE_PARAM__DOWNLOAD_ONLY_DIFFERING = 'downloadOnlyDifferingImages'
92 LIVE_PARAM__SET_A_DIR = 'setADir' 93 LIVE_PARAM__SET_A_DIR = 'setADir'
94 LIVE_PARAM__SET_A_SECTION = 'setASection'
93 LIVE_PARAM__SET_B_DIR = 'setBDir' 95 LIVE_PARAM__SET_B_DIR = 'setBDir'
94 96 LIVE_PARAM__SET_B_SECTION = 'setBSection'
95 # Parameters we use within do_GET_prefetch_results()
96 PREFETCH_PARAM__DOWNLOAD_ONLY_DIFFERING = 'downloadOnlyDifferingImages'
97 97
98 # How often (in seconds) clients should reload while waiting for initial 98 # How often (in seconds) clients should reload while waiting for initial
99 # results to load. 99 # results to load.
100 RELOAD_INTERVAL_UNTIL_READY = 10 100 RELOAD_INTERVAL_UNTIL_READY = 10
101 101
102 SUMMARY_TYPES = [ 102 SUMMARY_TYPES = [
103 results_mod.KEY__HEADER__RESULTS_FAILURES, 103 results_mod.KEY__HEADER__RESULTS_FAILURES,
104 results_mod.KEY__HEADER__RESULTS_ALL, 104 results_mod.KEY__HEADER__RESULTS_ALL,
105 ] 105 ]
106 # If --compare-configs is specified, compare these configs. 106 # If --compare-configs is specified, compare these configs.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 self.send_json_dict(response_dict) 526 self.send_json_dict(response_dict)
527 527
528 def do_GET_live_results(self, url_remainder): 528 def do_GET_live_results(self, url_remainder):
529 """ Handle a GET request for live-generated image diff data. 529 """ Handle a GET request for live-generated image diff data.
530 530
531 Args: 531 Args:
532 url_remainder: string indicating which image diffs to generate 532 url_remainder: string indicating which image diffs to generate
533 """ 533 """
534 logging.debug('do_GET_live_results: url_remainder="%s"' % url_remainder) 534 logging.debug('do_GET_live_results: url_remainder="%s"' % url_remainder)
535 param_dict = urlparse.parse_qs(url_remainder) 535 param_dict = urlparse.parse_qs(url_remainder)
536 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( 536 results_obj = self._call_compare_rendered_pictures(
537 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR], 537 param_dict=param_dict, prefetch_only=False)
538 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR],
539 image_diff_db=_SERVER.image_diff_db,
540 diff_base_url='/static/generated-images',
541 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results)
542 self.send_json_dict(results_obj.get_packaged_results_of_type( 538 self.send_json_dict(results_obj.get_packaged_results_of_type(
543 results_mod.KEY__HEADER__RESULTS_ALL)) 539 results_mod.KEY__HEADER__RESULTS_ALL))
544 540
545 def do_GET_prefetch_results(self, url_remainder): 541 def do_GET_prefetch_results(self, url_remainder):
546 """ Prefetch image diff data for a future do_GET_live_results() call. 542 """ Prefetch image diff data for a future do_GET_live_results() call.
547 543
548 Args: 544 Args:
549 url_remainder: string indicating which image diffs to generate 545 url_remainder: string indicating which image diffs to generate
550 """ 546 """
551 logging.debug('do_GET_prefetch_results: url_remainder="%s"' % url_remainder) 547 logging.debug('do_GET_prefetch_results: url_remainder="%s"' % url_remainder)
552 param_dict = urlparse.parse_qs(url_remainder) 548 param_dict = urlparse.parse_qs(url_remainder)
553 download_all_images = ( 549 self._call_compare_rendered_pictures(
554 param_dict.get(PREFETCH_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower() 550 param_dict=param_dict, prefetch_only=True)
555 not in ['1', 'true'])
556 compare_rendered_pictures.RenderedPicturesComparisons(
557 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR],
558 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR],
559 image_diff_db=_SERVER.image_diff_db,
560 diff_base_url='/static/generated-images',
561 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results,
562 prefetch_only=True, download_all_images=download_all_images)
563 self.send_response(200) 551 self.send_response(200)
564 552
565 def do_GET_static(self, path): 553 def do_GET_static(self, path):
566 """ Handle a GET request for a file under STATIC_CONTENTS_SUBDIR . 554 """ Handle a GET request for a file under STATIC_CONTENTS_SUBDIR .
567 Only allow serving of files within STATIC_CONTENTS_SUBDIR that is a 555 Only allow serving of files within STATIC_CONTENTS_SUBDIR that is a
568 filesystem sibling of this script. 556 filesystem sibling of this script.
569 557
570 Args: 558 Args:
571 path: path to file (within STATIC_CONTENTS_SUBDIR) to retrieve 559 path: path to file (within STATIC_CONTENTS_SUBDIR) to retrieve
572 """ 560 """
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 mimetype. 688 mimetype.
701 689
702 Args: 690 Args:
703 json_dict: dictionary to send 691 json_dict: dictionary to send
704 """ 692 """
705 self.send_response(200) 693 self.send_response(200)
706 self.send_header('Content-type', 'application/json') 694 self.send_header('Content-type', 'application/json')
707 self.end_headers() 695 self.end_headers()
708 json.dump(json_dict, self.wfile) 696 json.dump(json_dict, self.wfile)
709 697
698 def _call_compare_rendered_pictures(self, param_dict, prefetch_only):
699 """Instantiates RenderedPicturesComparisons object to serve a GET request.
700
701 Args:
702 param_dict: dictionary of URL parameters
703 prefetch_only: parameter to pass into RenderedPicturesComparisons
704 constructor
705
706 Returns: a reference to the new RenderedPicturesComparisons object.
707 """
708 download_all_images = (
709 param_dict.get(LIVE_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower()
710 not in ['1', 'true'])
711 setA_section = self._validate_summary_section(
712 param_dict.get(LIVE_PARAM__SET_A_SECTION, [None])[0])
713 setB_section = self._validate_summary_section(
714 param_dict.get(LIVE_PARAM__SET_B_SECTION, [None])[0])
715 return compare_rendered_pictures.RenderedPicturesComparisons(
716 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR],
717 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR],
718 setA_section=setA_section, setB_section=setB_section,
719 image_diff_db=_SERVER.image_diff_db,
720 diff_base_url='/static/generated-images',
721 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results,
722 prefetch_only=prefetch_only, download_all_images=download_all_images)
723
724 def _validate_summary_section(self, section_name):
725 """Validates the section we have been requested to read within JSON summary.
726
727 Args:
728 section_name: which section of the JSON summary file has been requested
729
730 Returns: the validated section name
731
732 Raises: Exception if an invalid section_name was requested.
733 """
734 if section_name not in compare_rendered_pictures.ALLOWED_SECTION_NAMES:
735 raise Exception('requested section name "%s" not in allowed list %s' % (
736 section_name, compare_rendered_pictures.ALLOWED_SECTION_NAMES))
737 return section_name
738
710 739
711 def main(): 740 def main():
712 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', 741 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
713 datefmt='%m/%d/%Y %H:%M:%S', 742 datefmt='%m/%d/%Y %H:%M:%S',
714 level=logging.INFO) 743 level=logging.INFO)
715 parser = argparse.ArgumentParser() 744 parser = argparse.ArgumentParser()
716 parser.add_argument('--actuals-dir', 745 parser.add_argument('--actuals-dir',
717 help=('Directory into which we will check out the latest ' 746 help=('Directory into which we will check out the latest '
718 'actual GM results. If this directory does not ' 747 'actual GM results. If this directory does not '
719 'exist, it will be created. Defaults to %(default)s'), 748 'exist, it will be created. Defaults to %(default)s'),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 reload_seconds=args.reload, config_pairs=config_pairs, 820 reload_seconds=args.reload, config_pairs=config_pairs,
792 builder_regex_list=args.builders, boto_file_path=args.boto, 821 builder_regex_list=args.builders, boto_file_path=args.boto,
793 imagediffdb_threads=args.threads) 822 imagediffdb_threads=args.threads)
794 if args.truncate: 823 if args.truncate:
795 _SERVER.truncate_results = True 824 _SERVER.truncate_results = True
796 _SERVER.run() 825 _SERVER.run()
797 826
798 827
799 if __name__ == '__main__': 828 if __name__ == '__main__':
800 main() 829 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698