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 | 9 |
10 ''' | 10 ''' |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 """ | 72 """ |
73 def __init__(self, | 73 def __init__(self, |
74 actuals_dir=DEFAULT_ACTUALS_DIR, | 74 actuals_dir=DEFAULT_ACTUALS_DIR, |
75 expectations_dir=DEFAULT_EXPECTATIONS_DIR, | 75 expectations_dir=DEFAULT_EXPECTATIONS_DIR, |
76 port=DEFAULT_PORT, export=False): | 76 port=DEFAULT_PORT, export=False): |
77 self._actuals_dir = actuals_dir | 77 self._actuals_dir = actuals_dir |
78 self._expectations_dir = expectations_dir | 78 self._expectations_dir = expectations_dir |
79 self._port = port | 79 self._port = port |
80 self._export = export | 80 self._export = export |
81 | 81 |
| 82 def is_exported(self): |
| 83 """ Returns true iff HTTP clients on other hosts are allowed to access |
| 84 this server. """ |
| 85 return self._export |
| 86 |
82 def fetch_results(self): | 87 def fetch_results(self): |
83 """ Create self.results, based on the expectations in | 88 """ Create self.results, based on the expectations in |
84 self._expectations_dir and the latest actuals from skia-autogen. | 89 self._expectations_dir and the latest actuals from skia-autogen. |
85 | 90 |
86 TODO(epoger): Add a new --browseonly mode setting. In that mode, | 91 TODO(epoger): Add a new --browseonly mode setting. In that mode, |
87 the gm-actuals and expectations will automatically be updated every few | 92 the gm-actuals and expectations will automatically be updated every few |
88 minutes. See discussion in https://codereview.chromium.org/24274003/ . | 93 minutes. See discussion in https://codereview.chromium.org/24274003/ . |
89 """ | 94 """ |
90 print 'Checking out latest actual GM results from %s into %s ...' % ( | 95 print 'Checking out latest actual GM results from %s into %s ...' % ( |
91 ACTUALS_SVN_REPO, self._actuals_dir) | 96 ACTUALS_SVN_REPO, self._actuals_dir) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 dispatcher(remainder) | 148 dispatcher(remainder) |
144 | 149 |
145 def do_GET_results(self, result_type): | 150 def do_GET_results(self, result_type): |
146 """ Handle a GET request for GM results. | 151 """ Handle a GET request for GM results. |
147 For now, we ignore the remaining path info, because we only know how to | 152 For now, we ignore the remaining path info, because we only know how to |
148 return all results. | 153 return all results. |
149 | 154 |
150 TODO(epoger): Unless we start making use of result_type, remove that | 155 TODO(epoger): Unless we start making use of result_type, remove that |
151 parameter.""" | 156 parameter.""" |
152 print 'do_GET_results: sending results of type "%s"' % result_type | 157 print 'do_GET_results: sending results of type "%s"' % result_type |
| 158 # TODO(epoger): Cache response_dict rather than the results object, to save |
| 159 # time on subsequent fetches (no need to regenerate the header, etc.) |
153 response_dict = _SERVER.results.GetAll() | 160 response_dict = _SERVER.results.GetAll() |
154 if response_dict: | 161 if response_dict: |
| 162 response_dict["header"] = { |
| 163 # Hash of testData, which the client must return with any edits-- |
| 164 # this ensures that the edits were made to a particular dataset. |
| 165 "data-hash": str(hash(repr(response_dict["testData"]))), |
| 166 |
| 167 # Whether the server will accept edits back. |
| 168 # TODO(epoger): Not yet implemented, so hardcoding to False; |
| 169 # once we implement the "browseonly" mode discussed in |
| 170 # https://codereview.chromium.org/24274003/#msg6 , this value will vary. |
| 171 "is-editable": False, |
| 172 |
| 173 # Whether the service is accessible from other hosts. |
| 174 "is-exported": _SERVER.is_exported(), |
| 175 } |
155 self.send_json_dict(response_dict) | 176 self.send_json_dict(response_dict) |
156 else: | 177 else: |
157 self.send_error(404) | 178 self.send_error(404) |
158 | 179 |
159 def do_GET_static(self, path): | 180 def do_GET_static(self, path): |
160 """ Handle a GET request for a file under the 'static' directory. | 181 """ Handle a GET request for a file under the 'static' directory. |
161 Only allow serving of files within the 'static' directory that is a | 182 Only allow serving of files within the 'static' directory that is a |
162 filesystem sibling of this script. """ | 183 filesystem sibling of this script. """ |
163 print 'do_GET_static: sending file "%s"' % path | 184 print 'do_GET_static: sending file "%s"' % path |
164 static_dir = os.path.realpath(os.path.join(PARENT_DIRECTORY, 'static')) | 185 static_dir = os.path.realpath(os.path.join(PARENT_DIRECTORY, 'static')) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 'defaults to %(default)s'), | 249 'defaults to %(default)s'), |
229 default=DEFAULT_PORT) | 250 default=DEFAULT_PORT) |
230 args = parser.parse_args() | 251 args = parser.parse_args() |
231 global _SERVER | 252 global _SERVER |
232 _SERVER = Server(expectations_dir=args.expectations_dir, | 253 _SERVER = Server(expectations_dir=args.expectations_dir, |
233 port=args.port, export=args.export) | 254 port=args.port, export=args.export) |
234 _SERVER.run() | 255 _SERVER.run() |
235 | 256 |
236 if __name__ == '__main__': | 257 if __name__ == '__main__': |
237 main() | 258 main() |
OLD | NEW |