blob: 47ee236f775ddc7a0324a0aceb7f7102fbdbfc25 [file] [log] [blame]
epoger@google.comf9d134d2013-09-27 15:02:44 +00001#!/usr/bin/python
2
epoger@google.com9fb6c8a2013-10-09 18:05:58 +00003"""
epoger@google.comf9d134d2013-09-27 15:02:44 +00004Copyright 2013 Google Inc.
5
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
epoger@google.comf9d134d2013-09-27 15:02:44 +00008
epoger@google.comf9d134d2013-09-27 15:02:44 +00009HTTP server for our HTML rebaseline viewer.
epoger@google.com9fb6c8a2013-10-09 18:05:58 +000010"""
epoger@google.comf9d134d2013-09-27 15:02:44 +000011
12# System-level imports
13import argparse
14import BaseHTTPServer
15import json
epoger@google.comdcb4e652013-10-11 18:45:33 +000016import logging
epoger@google.comf9d134d2013-09-27 15:02:44 +000017import os
18import posixpath
19import re
20import shutil
epoger@google.comb08c7072013-10-30 14:09:04 +000021import socket
epoger@google.comf9d134d2013-09-27 15:02:44 +000022import sys
epoger@google.com542b65f2013-10-15 20:10:33 +000023import thread
24import time
epoger@google.comdcb4e652013-10-11 18:45:33 +000025import urlparse
epoger@google.comf9d134d2013-09-27 15:02:44 +000026
27# Imports from within Skia
28#
29# We need to add the 'tools' directory, so that we can import svn.py within
30# that directory.
31# Make sure that the 'tools' dir is in the PYTHONPATH, but add it at the *end*
32# so any dirs that are already in the PYTHONPATH will be preferred.
epoger@google.comcb55f112013-10-02 19:27:35 +000033PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
34TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(PARENT_DIRECTORY))
epoger@google.comf9d134d2013-09-27 15:02:44 +000035TOOLS_DIRECTORY = os.path.join(TRUNK_DIRECTORY, 'tools')
36if TOOLS_DIRECTORY not in sys.path:
37 sys.path.append(TOOLS_DIRECTORY)
38import svn
39
40# Imports from local dir
41import results
42
43ACTUALS_SVN_REPO = 'http://skia-autogen.googlecode.com/svn/gm-actual'
44PATHSPLIT_RE = re.compile('/([^/]+)/(.+)')
45TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(
46 os.path.realpath(__file__))))
epoger@google.comb063e132013-11-25 18:06:29 +000047EXPECTATIONS_DIR = os.path.join(TRUNK_DIRECTORY, 'expectations', 'gm')
epoger@google.com9dddf6f2013-11-08 16:25:25 +000048GENERATED_IMAGES_ROOT = os.path.join(PARENT_DIRECTORY, 'static',
49 'generated-images')
epoger@google.comf9d134d2013-09-27 15:02:44 +000050
51# A simple dictionary of file name extensions to MIME types. The empty string
52# entry is used as the default when no extension was given or if the extension
53# has no entry in this dictionary.
54MIME_TYPE_MAP = {'': 'application/octet-stream',
55 'html': 'text/html',
56 'css': 'text/css',
57 'png': 'image/png',
58 'js': 'application/javascript',
59 'json': 'application/json'
60 }
61
62DEFAULT_ACTUALS_DIR = '.gm-actuals'
epoger@google.comf9d134d2013-09-27 15:02:44 +000063DEFAULT_PORT = 8888
64
epoger@google.comeb832592013-10-23 15:07:26 +000065_HTTP_HEADER_CONTENT_LENGTH = 'Content-Length'
66_HTTP_HEADER_CONTENT_TYPE = 'Content-Type'
67
epoger@google.comf9d134d2013-09-27 15:02:44 +000068_SERVER = None # This gets filled in by main()
69
epoger@google.com591469b2013-11-20 19:58:06 +000070def _get_routable_ip_address():
epoger@google.comb08c7072013-10-30 14:09:04 +000071 """Returns routable IP address of this host (the IP address of its network
72 interface that would be used for most traffic, not its localhost
73 interface). See http://stackoverflow.com/a/166589 """
74 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
75 sock.connect(('8.8.8.8', 80))
76 host = sock.getsockname()[0]
77 sock.close()
78 return host
79
epoger@google.com591469b2013-11-20 19:58:06 +000080def _create_svn_checkout(dir_path, repo_url):
81 """Creates local checkout of an SVN repository at the specified directory
82 path, returning an svn.Svn object referring to the local checkout.
83
84 Args:
85 dir_path: path to the local checkout; if this directory does not yet exist,
86 it will be created and the repo will be checked out into it
87 repo_url: URL of SVN repo to check out into dir_path (unless the local
88 checkout already exists)
89 Returns: an svn.Svn object referring to the local checkout.
90 """
91 local_checkout = svn.Svn(dir_path)
92 if not os.path.isdir(dir_path):
93 os.makedirs(dir_path)
94 local_checkout.Checkout(repo_url, '.')
95 return local_checkout
96
epoger@google.comb08c7072013-10-30 14:09:04 +000097
epoger@google.comf9d134d2013-09-27 15:02:44 +000098class Server(object):
epoger@google.com9fb6c8a2013-10-09 18:05:58 +000099 """ HTTP server for our HTML rebaseline viewer. """
epoger@google.comf9d134d2013-09-27 15:02:44 +0000100
epoger@google.comf9d134d2013-09-27 15:02:44 +0000101 def __init__(self,
102 actuals_dir=DEFAULT_ACTUALS_DIR,
epoger@google.com542b65f2013-10-15 20:10:33 +0000103 port=DEFAULT_PORT, export=False, editable=True,
104 reload_seconds=0):
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000105 """
106 Args:
107 actuals_dir: directory under which we will check out the latest actual
108 GM results
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000109 port: which TCP port to listen on for HTTP requests
110 export: whether to allow HTTP clients on other hosts to access this server
epoger@google.com542b65f2013-10-15 20:10:33 +0000111 editable: whether HTTP clients are allowed to submit new baselines
112 reload_seconds: polling interval with which to check for new results;
113 if 0, don't check for new results at all
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000114 """
epoger@google.comf9d134d2013-09-27 15:02:44 +0000115 self._actuals_dir = actuals_dir
epoger@google.comf9d134d2013-09-27 15:02:44 +0000116 self._port = port
117 self._export = export
epoger@google.com542b65f2013-10-15 20:10:33 +0000118 self._editable = editable
119 self._reload_seconds = reload_seconds
epoger@google.com591469b2013-11-20 19:58:06 +0000120 self._actuals_repo = _create_svn_checkout(
121 dir_path=actuals_dir, repo_url=ACTUALS_SVN_REPO)
122
123 # We only update the expectations dir if the server was run with a
124 # nonzero --reload argument; otherwise, we expect the user to maintain
125 # her own expectations as she sees fit.
126 #
epoger@google.comb063e132013-11-25 18:06:29 +0000127 # TODO(epoger): Use git instead of svn to update the expectations dir, since
epoger@google.com591469b2013-11-20 19:58:06 +0000128 # the Skia repo is moving to git.
epoger@google.comb063e132013-11-25 18:06:29 +0000129 # When we make that change, we will have to update the entire workspace,
130 # not just the expectations dir, because git only operates on the repo
131 # as a whole.
132 # And since Skia uses depot_tools to manage its dependencies, we will have
133 # to run "gclient sync" rather than a raw "git pull".
epoger@google.com591469b2013-11-20 19:58:06 +0000134 if reload_seconds:
epoger@google.comb063e132013-11-25 18:06:29 +0000135 self._expectations_repo = svn.Svn(EXPECTATIONS_DIR)
epoger@google.com591469b2013-11-20 19:58:06 +0000136 else:
137 self._expectations_repo = None
epoger@google.comf9d134d2013-09-27 15:02:44 +0000138
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000139 def is_exported(self):
140 """ Returns true iff HTTP clients on other hosts are allowed to access
141 this server. """
142 return self._export
143
epoger@google.com542b65f2013-10-15 20:10:33 +0000144 def is_editable(self):
145 """ Returns true iff HTTP clients are allowed to submit new baselines. """
146 return self._editable
epoger@google.comf9d134d2013-09-27 15:02:44 +0000147
epoger@google.com542b65f2013-10-15 20:10:33 +0000148 def reload_seconds(self):
149 """ Returns the result reload period in seconds, or 0 if we don't reload
150 results. """
151 return self._reload_seconds
152
epoger@google.comeb832592013-10-23 15:07:26 +0000153 def update_results(self):
epoger@google.com542b65f2013-10-15 20:10:33 +0000154 """ Create or update self.results, based on the expectations in
epoger@google.comb063e132013-11-25 18:06:29 +0000155 EXPECTATIONS_DIR and the latest actuals from skia-autogen.
epoger@google.comf9d134d2013-09-27 15:02:44 +0000156 """
epoger@google.com591469b2013-11-20 19:58:06 +0000157 logging.info('Updating actual GM results in %s from SVN repo %s ...' % (
158 self._actuals_dir, ACTUALS_SVN_REPO))
159 self._actuals_repo.Update('.')
160
161 if self._expectations_repo:
162 logging.info(
epoger@google.comb063e132013-11-25 18:06:29 +0000163 'Updating expected GM results in %s ...' % EXPECTATIONS_DIR)
epoger@google.com591469b2013-11-20 19:58:06 +0000164 self._expectations_repo.Update('.')
epoger@google.comeb832592013-10-23 15:07:26 +0000165
epoger@google.com61952902013-11-08 17:23:54 +0000166 logging.info(
epoger@google.com9dddf6f2013-11-08 16:25:25 +0000167 ('Parsing results from actuals in %s and expectations in %s, '
168 + 'and generating pixel diffs (may take a while) ...') % (
epoger@google.comb063e132013-11-25 18:06:29 +0000169 self._actuals_dir, EXPECTATIONS_DIR))
epoger@google.com591469b2013-11-20 19:58:06 +0000170 self.results = results.Results(
epoger@google.comeb832592013-10-23 15:07:26 +0000171 actuals_root=self._actuals_dir,
epoger@google.comb063e132013-11-25 18:06:29 +0000172 expected_root=EXPECTATIONS_DIR,
epoger@google.com9dddf6f2013-11-08 16:25:25 +0000173 generated_images_root=GENERATED_IMAGES_ROOT)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000174
epoger@google.com542b65f2013-10-15 20:10:33 +0000175 def _result_reloader(self):
176 """ If --reload argument was specified, reload results at the appropriate
177 interval.
178 """
179 while self._reload_seconds:
180 time.sleep(self._reload_seconds)
epoger@google.comeb832592013-10-23 15:07:26 +0000181 self.update_results()
epoger@google.com542b65f2013-10-15 20:10:33 +0000182
epoger@google.comf9d134d2013-09-27 15:02:44 +0000183 def run(self):
epoger@google.comeb832592013-10-23 15:07:26 +0000184 self.update_results()
epoger@google.com542b65f2013-10-15 20:10:33 +0000185 thread.start_new_thread(self._result_reloader, ())
186
epoger@google.comf9d134d2013-09-27 15:02:44 +0000187 if self._export:
188 server_address = ('', self._port)
epoger@google.com591469b2013-11-20 19:58:06 +0000189 host = _get_routable_ip_address()
epoger@google.com542b65f2013-10-15 20:10:33 +0000190 if self._editable:
191 logging.warning('Running with combination of "export" and "editable" '
192 'flags. Users on other machines will '
193 'be able to modify your GM expectations!')
epoger@google.comf9d134d2013-09-27 15:02:44 +0000194 else:
epoger@google.comb08c7072013-10-30 14:09:04 +0000195 host = '127.0.0.1'
196 server_address = (host, self._port)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000197 http_server = BaseHTTPServer.HTTPServer(server_address, HTTPRequestHandler)
epoger@google.com61952902013-11-08 17:23:54 +0000198 logging.info('Ready for requests on http://%s:%d' % (
199 host, http_server.server_port))
epoger@google.comf9d134d2013-09-27 15:02:44 +0000200 http_server.serve_forever()
201
202
203class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
204 """ HTTP request handlers for various types of queries this server knows
205 how to handle (static HTML and Javascript, expected/actual results, etc.)
206 """
207 def do_GET(self):
208 """ Handles all GET requests, forwarding them to the appropriate
209 do_GET_* dispatcher. """
210 if self.path == '' or self.path == '/' or self.path == '/index.html' :
epoger@google.com045c3d32013-11-01 16:46:41 +0000211 self.redirect_to('/static/index.html')
epoger@google.comf9d134d2013-09-27 15:02:44 +0000212 return
213 if self.path == '/favicon.ico' :
214 self.redirect_to('/static/favicon.ico')
215 return
216
217 # All requests must be of this form:
218 # /dispatcher/remainder
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000219 # where 'dispatcher' indicates which do_GET_* dispatcher to run
220 # and 'remainder' is the remaining path sent to that dispatcher.
epoger@google.comf9d134d2013-09-27 15:02:44 +0000221 normpath = posixpath.normpath(self.path)
222 (dispatcher_name, remainder) = PATHSPLIT_RE.match(normpath).groups()
223 dispatchers = {
224 'results': self.do_GET_results,
225 'static': self.do_GET_static,
226 }
227 dispatcher = dispatchers[dispatcher_name]
228 dispatcher(remainder)
229
epoger@google.comdcb4e652013-10-11 18:45:33 +0000230 def do_GET_results(self, type):
epoger@google.comf9d134d2013-09-27 15:02:44 +0000231 """ Handle a GET request for GM results.
epoger@google.comf9d134d2013-09-27 15:02:44 +0000232
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000233 Args:
epoger@google.comdcb4e652013-10-11 18:45:33 +0000234 type: string indicating which set of results to return;
235 must be one of the results.RESULTS_* constants
236 """
237 logging.debug('do_GET_results: sending results of type "%s"' % type)
238 try:
epoger@google.com591469b2013-11-20 19:58:06 +0000239 # Since we must make multiple calls to the Results object, grab a
240 # reference to it in case it is updated to point at a new Results
241 # object within another thread.
242 #
epoger@google.comdcb4e652013-10-11 18:45:33 +0000243 # TODO(epoger): Rather than using a global variable for the handler
244 # to refer to the Server object, make Server a subclass of
245 # HTTPServer, and then it could be available to the handler via
246 # the handler's .server instance variable.
epoger@google.com591469b2013-11-20 19:58:06 +0000247 results_obj = _SERVER.results
248 response_dict = results_obj.get_results_of_type(type)
249 time_updated = results_obj.get_timestamp()
epoger@google.com542b65f2013-10-15 20:10:33 +0000250
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000251 response_dict['header'] = {
epoger@google.com542b65f2013-10-15 20:10:33 +0000252 # Timestamps:
253 # 1. when this data was last updated
254 # 2. when the caller should check back for new data (if ever)
255 #
256 # We only return these timestamps if the --reload argument was passed;
257 # otherwise, we have no idea when the expectations were last updated
258 # (we allow the user to maintain her own expectations as she sees fit).
259 'timeUpdated': time_updated if _SERVER.reload_seconds() else None,
260 'timeNextUpdateAvailable': (
261 (time_updated+_SERVER.reload_seconds()) if _SERVER.reload_seconds()
262 else None),
263
epoger@google.comeb832592013-10-23 15:07:26 +0000264 # The type we passed to get_results_of_type()
265 'type': type,
266
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000267 # Hash of testData, which the client must return with any edits--
268 # this ensures that the edits were made to a particular dataset.
epoger@google.com542b65f2013-10-15 20:10:33 +0000269 'dataHash': str(hash(repr(response_dict['testData']))),
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000270
271 # Whether the server will accept edits back.
epoger@google.com542b65f2013-10-15 20:10:33 +0000272 'isEditable': _SERVER.is_editable(),
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000273
274 # Whether the service is accessible from other hosts.
275 'isExported': _SERVER.is_exported(),
276 }
epoger@google.comf9d134d2013-09-27 15:02:44 +0000277 self.send_json_dict(response_dict)
epoger@google.comdcb4e652013-10-11 18:45:33 +0000278 except:
epoger@google.comf9d134d2013-09-27 15:02:44 +0000279 self.send_error(404)
epoger@google.com542b65f2013-10-15 20:10:33 +0000280 raise
epoger@google.comf9d134d2013-09-27 15:02:44 +0000281
282 def do_GET_static(self, path):
epoger@google.comcb55f112013-10-02 19:27:35 +0000283 """ Handle a GET request for a file under the 'static' directory.
284 Only allow serving of files within the 'static' directory that is a
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000285 filesystem sibling of this script.
286
287 Args:
288 path: path to file (under static directory) to retrieve
289 """
epoger@google.comdcb4e652013-10-11 18:45:33 +0000290 # Strip arguments ('?resultsToLoad=all') from the path
291 path = urlparse.urlparse(path).path
292
293 logging.debug('do_GET_static: sending file "%s"' % path)
epoger@google.comcb55f112013-10-02 19:27:35 +0000294 static_dir = os.path.realpath(os.path.join(PARENT_DIRECTORY, 'static'))
295 full_path = os.path.realpath(os.path.join(static_dir, path))
296 if full_path.startswith(static_dir):
297 self.send_file(full_path)
298 else:
epoger@google.comdcb4e652013-10-11 18:45:33 +0000299 logging.error(
300 'Attempted do_GET_static() of path [%s] outside of static dir [%s]'
301 % (full_path, static_dir))
epoger@google.comcb55f112013-10-02 19:27:35 +0000302 self.send_error(404)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000303
epoger@google.comeb832592013-10-23 15:07:26 +0000304 def do_POST(self):
305 """ Handles all POST requests, forwarding them to the appropriate
306 do_POST_* dispatcher. """
307 # All requests must be of this form:
308 # /dispatcher
309 # where 'dispatcher' indicates which do_POST_* dispatcher to run.
310 normpath = posixpath.normpath(self.path)
311 dispatchers = {
312 '/edits': self.do_POST_edits,
313 }
314 try:
315 dispatcher = dispatchers[normpath]
316 dispatcher()
317 self.send_response(200)
318 except:
319 self.send_error(404)
320 raise
321
322 def do_POST_edits(self):
323 """ Handle a POST request with modifications to GM expectations, in this
324 format:
325
326 {
327 'oldResultsType': 'all', # type of results that the client loaded
328 # and then made modifications to
329 'oldResultsHash': 39850913, # hash of results when the client loaded them
330 # (ensures that the client and server apply
331 # modifications to the same base)
332 'modifications': [
333 {
334 'builder': 'Test-Android-Nexus10-MaliT604-Arm7-Debug',
335 'test': 'strokerect',
336 'config': 'gpu',
337 'expectedHashType': 'bitmap-64bitMD5',
338 'expectedHashDigest': '1707359671708613629',
339 },
340 ...
341 ],
342 }
343
344 Raises an Exception if there were any problems.
345 """
346 if not _SERVER.is_editable():
347 raise Exception('this server is not running in --editable mode')
348
349 content_type = self.headers[_HTTP_HEADER_CONTENT_TYPE]
350 if content_type != 'application/json;charset=UTF-8':
351 raise Exception('unsupported %s [%s]' % (
352 _HTTP_HEADER_CONTENT_TYPE, content_type))
353
354 content_length = int(self.headers[_HTTP_HEADER_CONTENT_LENGTH])
355 json_data = self.rfile.read(content_length)
356 data = json.loads(json_data)
357 logging.debug('do_POST_edits: received new GM expectations data [%s]' %
358 data)
359
epoger@google.com591469b2013-11-20 19:58:06 +0000360 # Since we must make multiple calls to the Results object, grab a
361 # reference to it in case it is updated to point at a new Results
362 # object within another thread.
363 results_obj = _SERVER.results
364 oldResultsType = data['oldResultsType']
365 oldResults = results_obj.get_results_of_type(oldResultsType)
366 oldResultsHash = str(hash(repr(oldResults['testData'])))
367 if oldResultsHash != data['oldResultsHash']:
368 raise Exception('results of type "%s" changed while the client was '
369 'making modifications. The client should reload the '
370 'results and submit the modifications again.' %
371 oldResultsType)
372 results_obj.edit_expectations(data['modifications'])
epoger@google.comeb832592013-10-23 15:07:26 +0000373
374 # Now that the edits have been committed, update results to reflect them.
375 _SERVER.update_results()
376
epoger@google.comf9d134d2013-09-27 15:02:44 +0000377 def redirect_to(self, url):
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000378 """ Redirect the HTTP client to a different url.
379
380 Args:
381 url: URL to redirect the HTTP client to
382 """
epoger@google.comf9d134d2013-09-27 15:02:44 +0000383 self.send_response(301)
384 self.send_header('Location', url)
385 self.end_headers()
386
387 def send_file(self, path):
388 """ Send the contents of the file at this path, with a mimetype based
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000389 on the filename extension.
390
391 Args:
392 path: path of file whose contents to send to the HTTP client
393 """
epoger@google.comf9d134d2013-09-27 15:02:44 +0000394 # Grab the extension if there is one
395 extension = os.path.splitext(path)[1]
396 if len(extension) >= 1:
397 extension = extension[1:]
398
399 # Determine the MIME type of the file from its extension
400 mime_type = MIME_TYPE_MAP.get(extension, MIME_TYPE_MAP[''])
401
402 # Open the file and send it over HTTP
403 if os.path.isfile(path):
404 with open(path, 'rb') as sending_file:
405 self.send_response(200)
406 self.send_header('Content-type', mime_type)
407 self.end_headers()
408 self.wfile.write(sending_file.read())
409 else:
410 self.send_error(404)
411
412 def send_json_dict(self, json_dict):
413 """ Send the contents of this dictionary in JSON format, with a JSON
epoger@google.com9fb6c8a2013-10-09 18:05:58 +0000414 mimetype.
415
416 Args:
417 json_dict: dictionary to send
418 """
epoger@google.comf9d134d2013-09-27 15:02:44 +0000419 self.send_response(200)
420 self.send_header('Content-type', 'application/json')
421 self.end_headers()
422 json.dump(json_dict, self.wfile)
423
424
425def main():
epoger@google.comdcb4e652013-10-11 18:45:33 +0000426 logging.basicConfig(level=logging.INFO)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000427 parser = argparse.ArgumentParser()
428 parser.add_argument('--actuals-dir',
429 help=('Directory into which we will check out the latest '
430 'actual GM results. If this directory does not '
431 'exist, it will be created. Defaults to %(default)s'),
432 default=DEFAULT_ACTUALS_DIR)
epoger@google.com542b65f2013-10-15 20:10:33 +0000433 parser.add_argument('--editable', action='store_true',
epoger@google.comeb832592013-10-23 15:07:26 +0000434 help=('Allow HTTP clients to submit new baselines.'))
epoger@google.comf9d134d2013-09-27 15:02:44 +0000435 parser.add_argument('--export', action='store_true',
436 help=('Instead of only allowing access from HTTP clients '
437 'on localhost, allow HTTP clients on other hosts '
438 'to access this server. WARNING: doing so will '
439 'allow users on other hosts to modify your '
epoger@google.com542b65f2013-10-15 20:10:33 +0000440 'GM expectations, if combined with --editable.'))
epoger@google.comafaad3d2013-09-30 15:06:25 +0000441 parser.add_argument('--port', type=int,
442 help=('Which TCP port to listen on for HTTP requests; '
443 'defaults to %(default)s'),
444 default=DEFAULT_PORT)
epoger@google.com542b65f2013-10-15 20:10:33 +0000445 parser.add_argument('--reload', type=int,
446 help=('How often (a period in seconds) to update the '
epoger@google.comb063e132013-11-25 18:06:29 +0000447 'results. If specified, both expected and actual '
448 'results will be updated. '
epoger@google.com542b65f2013-10-15 20:10:33 +0000449 'By default, we do not reload at all, and you '
450 'must restart the server to pick up new data.'),
451 default=0)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000452 args = parser.parse_args()
453 global _SERVER
epoger@google.com542b65f2013-10-15 20:10:33 +0000454 _SERVER = Server(actuals_dir=args.actuals_dir,
epoger@google.com542b65f2013-10-15 20:10:33 +0000455 port=args.port, export=args.export, editable=args.editable,
456 reload_seconds=args.reload)
epoger@google.comf9d134d2013-09-27 15:02:44 +0000457 _SERVER.run()
458
459if __name__ == '__main__':
460 main()