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

Side by Side Diff: Tools/TestResultServer/model/jsonresults.py

Issue 14562007: Change TestResultServer to use python 2.7. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2010 Google Inc. All rights reserved. 1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the 11 # in the documentation and/or other materials provided with the
12 # distribution. 12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from 14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission. 15 # this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 from datetime import datetime 29 import json
30 from django.utils import simplejson
31 import logging 30 import logging
32 import sys 31 import sys
33 import traceback 32 import traceback
34 33
35 from model.testfile import TestFile 34 from model.testfile import TestFile
36 35
37 JSON_RESULTS_FILE = "results.json" 36 JSON_RESULTS_FILE = "results.json"
38 JSON_RESULTS_FILE_SMALL = "results-small.json" 37 JSON_RESULTS_FILE_SMALL = "results-small.json"
39 JSON_RESULTS_PREFIX = "ADD_RESULTS(" 38 JSON_RESULTS_PREFIX = "ADD_RESULTS("
40 JSON_RESULTS_SUFFIX = ");" 39 JSON_RESULTS_SUFFIX = ");"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 99
101 class JsonResults(object): 100 class JsonResults(object):
102 @classmethod 101 @classmethod
103 def _strip_prefix_suffix(cls, data): 102 def _strip_prefix_suffix(cls, data):
104 # FIXME: Stop stripping jsonp callback once we upload pure json everywhe re. 103 # FIXME: Stop stripping jsonp callback once we upload pure json everywhe re.
105 if data.startswith(JSON_RESULTS_PREFIX) and data.endswith(JSON_RESULTS_S UFFIX): 104 if data.startswith(JSON_RESULTS_PREFIX) and data.endswith(JSON_RESULTS_S UFFIX):
106 return data[len(JSON_RESULTS_PREFIX):len(data) - len(JSON_RESULTS_SU FFIX)] 105 return data[len(JSON_RESULTS_PREFIX):len(data) - len(JSON_RESULTS_SU FFIX)]
107 return data 106 return data
108 107
109 @classmethod 108 @classmethod
110 def _generate_file_data(cls, json, sort_keys=False): 109 def _generate_file_data(cls, data, sort_keys=False):
111 return simplejson.dumps(json, separators=(',', ':'), sort_keys=sort_keys ) 110 return json.dumps(data, separators=(',', ':'), sort_keys=sort_keys)
112 111
113 @classmethod 112 @classmethod
114 def _load_json(cls, file_data): 113 def _load_json(cls, file_data):
115 json_results_str = cls._strip_prefix_suffix(file_data) 114 json_results_str = cls._strip_prefix_suffix(file_data)
116 if not json_results_str: 115 if not json_results_str:
117 logging.warning("No json results data.") 116 logging.warning("No json results data.")
118 return None 117 return None
119 118
120 try: 119 try:
121 return simplejson.loads(json_results_str) 120 return json.loads(json_results_str)
122 except: 121 except:
123 logging.debug(json_results_str) 122 logging.debug(json_results_str)
124 logging.error("Failed to load json results: %s", traceback.print_exc eption(*sys.exc_info())) 123 logging.error("Failed to load json results: %s", traceback.print_exc eption(*sys.exc_info()))
125 return None 124 return None
126 125
127 @classmethod 126 @classmethod
128 def _merge_json(cls, aggregated_json, incremental_json, num_runs): 127 def _merge_json(cls, aggregated_json, incremental_json, num_runs):
129 cls._merge_non_test_data(aggregated_json, incremental_json, num_runs) 128 cls._merge_non_test_data(aggregated_json, incremental_json, num_runs)
130 incremental_tests = incremental_json[JSON_RESULTS_TESTS] 129 incremental_tests = incremental_json[JSON_RESULTS_TESTS]
131 if incremental_tests: 130 if incremental_tests:
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 352
354 logging.debug("Checking test results json...") 353 logging.debug("Checking test results json...")
355 if not cls._check_json(builder, json): 354 if not cls._check_json(builder, json):
356 return None 355 return None
357 356
358 test_list_json = {} 357 test_list_json = {}
359 tests = json[builder][JSON_RESULTS_TESTS] 358 tests = json[builder][JSON_RESULTS_TESTS]
360 cls._delete_results_and_times(tests) 359 cls._delete_results_and_times(tests)
361 test_list_json[builder] = {"tests": tests} 360 test_list_json[builder] = {"tests": tests}
362 return cls._generate_file_data(test_list_json) 361 return cls._generate_file_data(test_list_json)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698