OLD | NEW |
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 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. | 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. |
10 """ | 10 """ |
(...skipping 13 matching lines...) Expand all Loading... |
24 # so any dirs that are already in the PYTHONPATH will be preferred. | 24 # so any dirs that are already in the PYTHONPATH will be preferred. |
25 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | 25 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) |
26 GM_DIRECTORY = os.path.dirname(PARENT_DIRECTORY) | 26 GM_DIRECTORY = os.path.dirname(PARENT_DIRECTORY) |
27 if GM_DIRECTORY not in sys.path: | 27 if GM_DIRECTORY not in sys.path: |
28 sys.path.append(GM_DIRECTORY) | 28 sys.path.append(GM_DIRECTORY) |
29 import gm_json | 29 import gm_json |
30 import imagepairset | 30 import imagepairset |
31 | 31 |
32 # Keys used to link an image to a particular GM test. | 32 # Keys used to link an image to a particular GM test. |
33 # NOTE: Keep these in sync with static/constants.js | 33 # NOTE: Keep these in sync with static/constants.js |
34 REBASELINE_SERVER_SCHEMA_VERSION_NUMBER = 3 | 34 VALUE__HEADER__SCHEMA_VERSION = 3 |
35 KEY__EXPECTATIONS__BUGS = gm_json.JSONKEY_EXPECTEDRESULTS_BUGS | 35 KEY__EXPECTATIONS__BUGS = gm_json.JSONKEY_EXPECTEDRESULTS_BUGS |
36 KEY__EXPECTATIONS__IGNOREFAILURE = gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE | 36 KEY__EXPECTATIONS__IGNOREFAILURE = gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE |
37 KEY__EXPECTATIONS__REVIEWED = gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED | 37 KEY__EXPECTATIONS__REVIEWED = gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED |
38 KEY__EXTRACOLUMN__BUILDER = 'builder' | 38 KEY__EXTRACOLUMNS__BUILDER = 'builder' |
39 KEY__EXTRACOLUMN__CONFIG = 'config' | 39 KEY__EXTRACOLUMNS__CONFIG = 'config' |
40 KEY__EXTRACOLUMN__RESULT_TYPE = 'resultType' | 40 KEY__EXTRACOLUMNS__RESULT_TYPE = 'resultType' |
41 KEY__EXTRACOLUMN__TEST = 'test' | 41 KEY__EXTRACOLUMNS__TEST = 'test' |
42 KEY__HEADER = 'header' | |
43 KEY__HEADER__DATAHASH = 'dataHash' | 42 KEY__HEADER__DATAHASH = 'dataHash' |
44 KEY__HEADER__IS_EDITABLE = 'isEditable' | 43 KEY__HEADER__IS_EDITABLE = 'isEditable' |
45 KEY__HEADER__IS_EXPORTED = 'isExported' | 44 KEY__HEADER__IS_EXPORTED = 'isExported' |
46 KEY__HEADER__IS_STILL_LOADING = 'resultsStillLoading' | 45 KEY__HEADER__IS_STILL_LOADING = 'resultsStillLoading' |
47 KEY__HEADER__RESULTS_ALL = 'all' | 46 KEY__HEADER__RESULTS_ALL = 'all' |
48 KEY__HEADER__RESULTS_FAILURES = 'failures' | 47 KEY__HEADER__RESULTS_FAILURES = 'failures' |
49 KEY__HEADER__SCHEMA_VERSION = 'schemaVersion' | 48 KEY__HEADER__SCHEMA_VERSION = 'schemaVersion' |
50 KEY__HEADER__TIME_NEXT_UPDATE_AVAILABLE = 'timeNextUpdateAvailable' | 49 KEY__HEADER__TIME_NEXT_UPDATE_AVAILABLE = 'timeNextUpdateAvailable' |
51 KEY__HEADER__TIME_UPDATED = 'timeUpdated' | 50 KEY__HEADER__TIME_UPDATED = 'timeUpdated' |
52 KEY__HEADER__TYPE = 'type' | 51 KEY__HEADER__TYPE = 'type' |
53 KEY__NEW_IMAGE_URL = 'newImageUrl' | |
54 KEY__RESULT_TYPE__FAILED = gm_json.JSONKEY_ACTUALRESULTS_FAILED | 52 KEY__RESULT_TYPE__FAILED = gm_json.JSONKEY_ACTUALRESULTS_FAILED |
55 KEY__RESULT_TYPE__FAILUREIGNORED = gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED | 53 KEY__RESULT_TYPE__FAILUREIGNORED = gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED |
56 KEY__RESULT_TYPE__NOCOMPARISON = gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON | 54 KEY__RESULT_TYPE__NOCOMPARISON = gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON |
57 KEY__RESULT_TYPE__SUCCEEDED = gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED | 55 KEY__RESULT_TYPE__SUCCEEDED = gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED |
58 | 56 |
59 IMAGE_FILENAME_RE = re.compile(gm_json.IMAGE_FILENAME_PATTERN) | 57 IMAGE_FILENAME_RE = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
60 IMAGE_FILENAME_FORMATTER = '%s_%s.png' # pass in (testname, config) | 58 IMAGE_FILENAME_FORMATTER = '%s_%s.png' # pass in (testname, config) |
61 | 59 |
62 DEFAULT_ACTUALS_DIR = '.gm-actuals' | 60 DEFAULT_ACTUALS_DIR = '.gm-actuals' |
63 DEFAULT_GENERATED_IMAGES_ROOT = os.path.join( | 61 DEFAULT_GENERATED_IMAGES_ROOT = os.path.join( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 results_type: string indicating which set of results to return; | 94 results_type: string indicating which set of results to return; |
97 must be one of the RESULTS_* constants | 95 must be one of the RESULTS_* constants |
98 reload_seconds: if specified, note that new results may be available once | 96 reload_seconds: if specified, note that new results may be available once |
99 these results are reload_seconds old | 97 these results are reload_seconds old |
100 is_editable: whether clients are allowed to submit new baselines | 98 is_editable: whether clients are allowed to submit new baselines |
101 is_exported: whether these results are being made available to other | 99 is_exported: whether these results are being made available to other |
102 network hosts | 100 network hosts |
103 """ | 101 """ |
104 response_dict = self._results[results_type] | 102 response_dict = self._results[results_type] |
105 time_updated = self.get_timestamp() | 103 time_updated = self.get_timestamp() |
106 response_dict[KEY__HEADER] = { | 104 response_dict[imagepairset.KEY__ROOT__HEADER] = { |
107 KEY__HEADER__SCHEMA_VERSION: ( | 105 KEY__HEADER__SCHEMA_VERSION: ( |
108 REBASELINE_SERVER_SCHEMA_VERSION_NUMBER), | 106 VALUE__HEADER__SCHEMA_VERSION), |
109 | 107 |
110 # Timestamps: | 108 # Timestamps: |
111 # 1. when this data was last updated | 109 # 1. when this data was last updated |
112 # 2. when the caller should check back for new data (if ever) | 110 # 2. when the caller should check back for new data (if ever) |
113 KEY__HEADER__TIME_UPDATED: time_updated, | 111 KEY__HEADER__TIME_UPDATED: time_updated, |
114 KEY__HEADER__TIME_NEXT_UPDATE_AVAILABLE: ( | 112 KEY__HEADER__TIME_NEXT_UPDATE_AVAILABLE: ( |
115 (time_updated+reload_seconds) if reload_seconds else None), | 113 (time_updated+reload_seconds) if reload_seconds else None), |
116 | 114 |
117 # The type we passed to get_results_of_type() | 115 # The type we passed to get_results_of_type() |
118 KEY__HEADER__TYPE: results_type, | 116 KEY__HEADER__TYPE: results_type, |
119 | 117 |
120 # Hash of dataset, which the client must return with any edits-- | 118 # Hash of dataset, which the client must return with any edits-- |
121 # this ensures that the edits were made to a particular dataset. | 119 # this ensures that the edits were made to a particular dataset. |
122 KEY__HEADER__DATAHASH: str(hash(repr( | 120 KEY__HEADER__DATAHASH: str(hash(repr( |
123 response_dict[imagepairset.KEY__IMAGEPAIRS]))), | 121 response_dict[imagepairset.KEY__ROOT__IMAGEPAIRS]))), |
124 | 122 |
125 # Whether the server will accept edits back. | 123 # Whether the server will accept edits back. |
126 KEY__HEADER__IS_EDITABLE: is_editable, | 124 KEY__HEADER__IS_EDITABLE: is_editable, |
127 | 125 |
128 # Whether the service is accessible from other hosts. | 126 # Whether the service is accessible from other hosts. |
129 KEY__HEADER__IS_EXPORTED: is_exported, | 127 KEY__HEADER__IS_EXPORTED: is_exported, |
130 } | 128 } |
131 return response_dict | 129 return response_dict |
132 | 130 |
133 def get_timestamp(self): | 131 def get_timestamp(self): |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 295 |
298 @staticmethod | 296 @staticmethod |
299 def get_multilevel(input_dict, *keys): | 297 def get_multilevel(input_dict, *keys): |
300 """ Returns input_dict[key1][key2][...], or None if any key is not found. | 298 """ Returns input_dict[key1][key2][...], or None if any key is not found. |
301 """ | 299 """ |
302 for key in keys: | 300 for key in keys: |
303 if input_dict == None: | 301 if input_dict == None: |
304 return None | 302 return None |
305 input_dict = input_dict.get(key, None) | 303 input_dict = input_dict.get(key, None) |
306 return input_dict | 304 return input_dict |
OLD | NEW |