blob: 35c48e6fdb3e2f486c2e43cab86615fa95ea8e2e [file] [log] [blame]
Chris Sosa7c931362010-10-11 19:49:01 -07001#!/usr/bin/python
2
Chris Sosa0356d3b2010-09-16 15:46:22 -07003# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
rtc@google.comded22402009-10-26 22:36:21 +00004# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Chris Sosa7c931362010-10-11 19:49:01 -07007"""A CherryPy-based webserver to host images and build packages."""
8
9import cherrypy
Sean O'Connor14b6a0a2010-03-20 23:23:48 -070010import optparse
rtc@google.comded22402009-10-26 22:36:21 +000011import os
Scott Zawalski4647ce62012-01-03 17:17:28 -050012import re
chocobo@google.com4dc25812009-10-27 23:46:26 +000013import sys
rtc@google.comded22402009-10-26 22:36:21 +000014
Chris Sosa0356d3b2010-09-16 15:46:22 -070015import autoupdate
Scott Zawalski16954532012-03-20 15:31:36 -040016import devserver_util
Chris Sosa0356d3b2010-09-16 15:46:22 -070017
Frank Farzan40160872011-12-12 18:39:18 -080018
Chris Sosa417e55d2011-01-25 16:40:48 -080019CACHED_ENTRIES = 12
Don Garrettf90edf02010-11-16 17:36:14 -080020
Chris Sosa0356d3b2010-09-16 15:46:22 -070021# Sets up global to share between classes.
rtc@google.com21a5ca32009-11-04 18:23:23 +000022global updater
23updater = None
rtc@google.comded22402009-10-26 22:36:21 +000024
Frank Farzan40160872011-12-12 18:39:18 -080025
Scott Zawalski4647ce62012-01-03 17:17:28 -050026def _LeadingWhiteSpaceCount(string):
27 """Count the amount of leading whitespace in a string.
28
29 Args:
30 string: The string to count leading whitespace in.
31 Returns:
32 number of white space chars before characters start.
33 """
34 matched = re.match('^\s+', string)
35 if matched:
36 return len(matched.group())
37
38 return 0
39
40
41def _PrintDocStringAsHTML(func):
42 """Make a functions docstring somewhat HTML style.
43
44 Args:
45 func: The function to return the docstring from.
46 Returns:
47 A string that is somewhat formated for a web browser.
48 """
49 # TODO(scottz): Make this parse Args/Returns in a prettier way.
50 # Arguments could be bolded and indented etc.
51 html_doc = []
52 for line in func.__doc__.splitlines():
53 leading_space = _LeadingWhiteSpaceCount(line)
54 if leading_space > 0:
Scott Zawalski51ccf9e2012-03-28 08:16:01 -070055 line = ' '*leading_space + line
Scott Zawalski4647ce62012-01-03 17:17:28 -050056
57 html_doc.append('<BR>%s' % line)
58
59 return '\n'.join(html_doc)
60
61
Chris Sosa7c931362010-10-11 19:49:01 -070062def _GetConfig(options):
63 """Returns the configuration for the devserver."""
64 base_config = { 'global':
65 { 'server.log_request_headers': True,
66 'server.protocol_version': 'HTTP/1.1',
Aaron Plattner2bfab982011-05-20 09:01:08 -070067 'server.socket_host': '::',
Chris Sosa7c931362010-10-11 19:49:01 -070068 'server.socket_port': int(options.port),
Chris Sosa374c62d2010-10-14 09:13:54 -070069 'server.socket_timeout': 6000,
70 'response.timeout': 6000,
Zdenek Behan1347a312011-02-10 03:59:17 +010071 'tools.staticdir.root':
72 os.path.dirname(os.path.abspath(sys.argv[0])),
Chris Sosa7c931362010-10-11 19:49:01 -070073 },
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070074 '/api':
75 {
76 # Gets rid of cherrypy parsing post file for args.
77 'request.process_request_body': False,
78 },
Chris Sosaa1ef0102010-10-21 16:22:35 -070079 '/build':
80 {
81 'response.timeout': 100000,
82 },
Chris Sosa7c931362010-10-11 19:49:01 -070083 '/update':
84 {
85 # Gets rid of cherrypy parsing post file for args.
86 'request.process_request_body': False,
Chris Sosaf65f4b92010-10-21 15:57:51 -070087 'response.timeout': 10000,
Chris Sosa7c931362010-10-11 19:49:01 -070088 },
89 # Sets up the static dir for file hosting.
90 '/static':
91 { 'tools.staticdir.dir': 'static',
92 'tools.staticdir.on': True,
Chris Sosaf65f4b92010-10-21 15:57:51 -070093 'response.timeout': 10000,
Chris Sosa7c931362010-10-11 19:49:01 -070094 },
95 }
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -050096
97 if options.log_dir:
98 base_config['global']['log.access_file'] = os.path.join(
99 options.log_dir, 'devserver_access.log')
100 base_config['global']['log.error_file'] = os.path.join(
101 options.log_dir, 'devserver_error.log')
102
Chris Sosa417e55d2011-01-25 16:40:48 -0800103 if options.production:
104 base_config['global']['server.environment'] = 'production'
105
Chris Sosa7c931362010-10-11 19:49:01 -0700106 return base_config
rtc@google.com64244662009-11-12 00:52:08 +0000107
Darin Petkove17164a2010-08-11 13:24:41 -0700108
Zdenek Behan608f46c2011-02-19 00:47:16 +0100109def _PrepareToServeUpdatesOnly(image_dir, static_dir):
Chris Sosa0356d3b2010-09-16 15:46:22 -0700110 """Sets up symlink to image_dir for serving purposes."""
111 assert os.path.exists(image_dir), '%s must exist.' % image_dir
112 # If we're serving out of an archived build dir (e.g. a
113 # buildbot), prepare this webserver's magic 'static/' dir with a
114 # link to the build archive.
Chris Sosa7c931362010-10-11 19:49:01 -0700115 cherrypy.log('Preparing autoupdate for "serve updates only" mode.',
116 'DEVSERVER')
Zdenek Behan608f46c2011-02-19 00:47:16 +0100117 if os.path.lexists('%s/archive' % static_dir):
118 if image_dir != os.readlink('%s/archive' % static_dir):
Chris Sosa7c931362010-10-11 19:49:01 -0700119 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER')
Zdenek Behan608f46c2011-02-19 00:47:16 +0100120 os.unlink('%s/archive' % static_dir)
121 os.symlink(image_dir, '%s/archive' % static_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700122 else:
Zdenek Behan608f46c2011-02-19 00:47:16 +0100123 os.symlink(image_dir, '%s/archive' % static_dir)
Chris Sosa7c931362010-10-11 19:49:01 -0700124 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir,
125 'DEVSERVER')
126
127
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700128class ApiRoot(object):
129 """RESTful API for Dev Server information."""
130 exposed = True
131
132 @cherrypy.expose
133 def hostinfo(self, ip):
134 """Returns a JSON dictionary containing information about the given ip.
135
136 Not all information may be known at the time the request is made. The
137 possible keys are:
138
139 last_event_type: int
140 Last update event type received.
141
142 last_event_status: int
143 Last update event status received.
144
145 last_known_version: string
146 Last known version recieved for update ping.
147
148 forced_update_label: string
149 Update label to force next update ping to use. Set by setnextupdate.
150
151 See the OmahaEvent class in update_engine/omaha_request_action.h for status
152 code definitions. If the ip does not exist an empty string is returned."""
153 return updater.HandleHostInfoPing(ip)
154
155 @cherrypy.expose
Gilad Arnold286a0062012-01-12 13:47:02 -0800156 def hostlog(self, ip):
157 """Returns a JSON object containing a log of events pertaining to a
158 particular host, or all hosts. Log events contain a timestamp and any
159 subset of the attributes listed for the hostinfo method."""
160 return updater.HandleHostLogPing(ip)
161
162 @cherrypy.expose
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700163 def setnextupdate(self, ip):
164 """Allows the response to the next update ping from a host to be set.
165
166 Takes the IP of the host and an update label as normally provided to the
167 /update command."""
168 body_length = int(cherrypy.request.headers['Content-Length'])
169 label = cherrypy.request.rfile.read(body_length)
170
171 if label:
172 label = label.strip()
173 if label:
174 return updater.HandleSetUpdatePing(ip, label)
175 raise cherrypy.HTTPError(400, 'No label provided.')
176
177
David Rochberg7c79a812011-01-19 14:24:45 -0500178class DevServerRoot(object):
Chris Sosa7c931362010-10-11 19:49:01 -0700179 """The Root Class for the Dev Server.
180
181 CherryPy works as follows:
182 For each method in this class, cherrpy interprets root/path
183 as a call to an instance of DevServerRoot->method_name. For example,
184 a call to http://myhost/build will call build. CherryPy automatically
185 parses http args and places them as keyword arguments in each method.
186 For paths http://myhost/update/dir1/dir2, you can use *args so that
187 cherrypy uses the update method and puts the extra paths in args.
188 """
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700189 api = ApiRoot()
Chris Sosa7c931362010-10-11 19:49:01 -0700190
David Rochberg7c79a812011-01-19 14:24:45 -0500191 def __init__(self):
Nick Sanders7dcaa2e2011-08-04 15:20:41 -0700192 self._builder = None
Scott Zawalski51ccf9e2012-03-28 08:16:01 -0700193 self._downloader = None
David Rochberg7c79a812011-01-19 14:24:45 -0500194
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700195 @cherrypy.expose
David Rochberg7c79a812011-01-19 14:24:45 -0500196 def build(self, board, pkg, **kwargs):
Chris Sosa7c931362010-10-11 19:49:01 -0700197 """Builds the package specified."""
Nick Sanders7dcaa2e2011-08-04 15:20:41 -0700198 import builder
199 if self._builder is None:
200 self._builder = builder.Builder()
David Rochberg7c79a812011-01-19 14:24:45 -0500201 return self._builder.Build(board, pkg, kwargs)
Chris Sosa7c931362010-10-11 19:49:01 -0700202
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700203 @cherrypy.expose
Frank Farzanbcb571e2012-01-03 11:48:17 -0800204 def download(self, **kwargs):
205 """Downloads and archives full/delta payloads from Google Storage.
206
207 Args:
208 archive_url: Google Storage URL for the build.
209
210 Example URL:
211 'http://myhost/download?archive_url=gs://chromeos-image-archive/'
212 'x86-generic/R17-1208.0.0-a1-b338'
213 """
Scott Zawalski51ccf9e2012-03-28 08:16:01 -0700214 import downloader
215 if self._downloader is None:
216 self._downloader = downloader.Downloader(updater.static_dir)
217 return self._downloader.Download(kwargs['archive_url'])
Frank Farzan40160872011-12-12 18:39:18 -0800218
219 @cherrypy.expose
Scott Zawalski16954532012-03-20 15:31:36 -0400220 def latestbuild(self, **params):
221 """Return a string representing the latest build for a given target.
222
223 Args:
224 target: The build target, typically a combination of the board and the
225 type of build e.g. x86-mario-release.
226 milestone: The milestone to filter builds on. E.g. R16. Optional, if not
227 provided the latest RXX build will be returned.
228 Returns:
229 A string representation of the latest build if one exists, i.e.
230 R19-1993.0.0-a1-b1480.
231 An empty string if no latest could be found.
232 """
233 if not params:
234 return _PrintDocStringAsHTML(self.latestbuild)
235
236 if 'target' not in params:
237 raise cherrypy.HTTPError('500 Internal Server Error',
238 'Error: target= is required!')
239 try:
240 return devserver_util.GetLatestBuildVersion(
241 updater.static_dir, params['target'],
242 milestone=params.get('milestone'))
243 except devserver_util.DevServerUtilError as errmsg:
244 raise cherrypy.HTTPError('500 Internal Server Error', str(errmsg))
245
246 @cherrypy.expose
Scott Zawalski84a39c92012-01-13 15:12:42 -0500247 def controlfiles(self, **params):
Scott Zawalski4647ce62012-01-03 17:17:28 -0500248 """Return a control file or a list of all known control files.
249
250 Example URL:
251 To List all control files:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500252 http://dev-server/controlfiles?board=x86-alex-release&build=R18-1514.0.0
Scott Zawalski4647ce62012-01-03 17:17:28 -0500253 To return the contents of a path:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500254 http://dev-server/controlfiles?board=x86-alex-release&build=R18-1514.0.0&control_path=client/sleeptest/control
Scott Zawalski4647ce62012-01-03 17:17:28 -0500255
256 Args:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500257 build: The build i.e. x86-alex-release/R18-1514.0.0-a1-b1450.
Scott Zawalski4647ce62012-01-03 17:17:28 -0500258 control_path: If you want the contents of a control file set this
259 to the path. E.g. client/site_tests/sleeptest/control
260 Optional, if not provided return a list of control files is returned.
261 Returns:
262 Contents of a control file if control_path is provided.
263 A list of control files if no control_path is provided.
264 """
Scott Zawalski4647ce62012-01-03 17:17:28 -0500265 if not params:
266 return _PrintDocStringAsHTML(self.controlfiles)
267
Scott Zawalski84a39c92012-01-13 15:12:42 -0500268 if 'build' not in params:
Scott Zawalski4647ce62012-01-03 17:17:28 -0500269 raise cherrypy.HTTPError('500 Internal Server Error',
Scott Zawalski84a39c92012-01-13 15:12:42 -0500270 'Error: build= is required!')
Scott Zawalski4647ce62012-01-03 17:17:28 -0500271
272 if 'control_path' not in params:
273 return devserver_util.GetControlFileList(updater.static_dir,
Scott Zawalski84a39c92012-01-13 15:12:42 -0500274 params['build'])
Scott Zawalski4647ce62012-01-03 17:17:28 -0500275 else:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500276 return devserver_util.GetControlFile(updater.static_dir, params['build'],
Scott Zawalski4647ce62012-01-03 17:17:28 -0500277 params['control_path'])
Frank Farzan40160872011-12-12 18:39:18 -0800278
279 @cherrypy.expose
Chris Sosa7c931362010-10-11 19:49:01 -0700280 def index(self):
281 return 'Welcome to the Dev Server!'
282
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700283 @cherrypy.expose
Chris Sosa7c931362010-10-11 19:49:01 -0700284 def update(self, *args):
285 label = '/'.join(args)
Gilad Arnold286a0062012-01-12 13:47:02 -0800286 body_length = int(cherrypy.request.headers.get('Content-Length', 0))
Chris Sosa7c931362010-10-11 19:49:01 -0700287 data = cherrypy.request.rfile.read(body_length)
288 return updater.HandleUpdatePing(data, label)
289
Chris Sosa0356d3b2010-09-16 15:46:22 -0700290
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700291if __name__ == '__main__':
292 usage = 'usage: %prog [options]'
Gilad Arnold286a0062012-01-12 13:47:02 -0800293 parser = optparse.OptionParser(usage=usage)
Sean O'Connore38ea152010-04-16 13:50:40 -0700294 parser.add_option('--archive_dir', dest='archive_dir',
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700295 help='serve archived builds only.')
Chris Sosae67b78f2010-11-04 17:33:16 -0700296 parser.add_option('--board', dest='board',
297 help='When pre-generating update, board for latest image.')
Don Garrett0c880e22010-11-17 18:13:37 -0800298 parser.add_option('--clear_cache', action='store_true', default=False,
Don Garrettf90edf02010-11-16 17:36:14 -0800299 help='Clear out all cached udpates and exit')
Greg Spencerc8b59b22011-03-15 14:15:23 -0700300 parser.add_option('--client_prefix', dest='client_prefix_deprecated',
301 help='No longer used. It is still here so we don\'t break '
302 'scripts that used it.', default='')
Satoru Takabayashid733cbe2011-11-15 09:36:32 -0800303 parser.add_option('--critical_update', dest='critical_update',
304 action='store_true', default=False,
305 help='Present update payload as critical')
Zdenek Behan5d21a2a2011-02-12 02:06:01 +0100306 parser.add_option('--data_dir', dest='data_dir',
307 help='Writable directory where static lives',
308 default=os.path.dirname(os.path.abspath(sys.argv[0])))
Don Garrett0c880e22010-11-17 18:13:37 -0800309 parser.add_option('--exit', action='store_true', default=False,
310 help='Don\'t start the server (still pregenerate or clear'
311 'cache).')
Andrew de los Reyes52620802010-04-12 13:40:07 -0700312 parser.add_option('--factory_config', dest='factory_config',
313 help='Config file for serving images from factory floor.')
Chris Sosa4136e692010-10-28 23:42:37 -0700314 parser.add_option('--for_vm', dest='vm', default=False, action='store_true',
315 help='Update is for a vm image.')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700316 parser.add_option('--image', dest='image',
317 help='Force update using this image.')
Chris Sosa2c048f12010-10-27 16:05:27 -0700318 parser.add_option('-p', '--pregenerate_update', action='store_true',
319 default=False, help='Pre-generate update payload.')
Don Garrett0c880e22010-11-17 18:13:37 -0800320 parser.add_option('--payload', dest='payload',
321 help='Use update payload from specified directory.')
Chris Sosa7c931362010-10-11 19:49:01 -0700322 parser.add_option('--port', default=8080,
Gilad Arnold286a0062012-01-12 13:47:02 -0800323 help='Port for the dev server to use (default: 8080).')
Chris Sosa0f1ec842011-02-14 16:33:22 -0800324 parser.add_option('--private_key', default=None,
325 help='Path to the private key in pem format.')
Chris Sosa417e55d2011-01-25 16:40:48 -0800326 parser.add_option('--production', action='store_true', default=False,
327 help='Have the devserver use production values.')
Don Garrett0ad09372010-12-06 16:20:30 -0800328 parser.add_option('--proxy_port', default=None,
329 help='Port to have the client connect to (testing support)')
Chris Sosa62f720b2010-10-26 21:39:48 -0700330 parser.add_option('--src_image', default='',
331 help='Image on remote machine for generating delta update.')
Sean O'Connor1f7fd362010-04-07 16:34:52 -0700332 parser.add_option('-t', action='store_true', dest='test_image')
333 parser.add_option('-u', '--urlbase', dest='urlbase',
334 help='base URL, other than devserver, for update images.')
Andrew de los Reyes52620802010-04-12 13:40:07 -0700335 parser.add_option('--validate_factory_config', action="store_true",
336 dest='validate_factory_config',
337 help='Validate factory config file, then exit.')
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -0500338 parser.add_option('-l', '--log-dir', default=None,
339 help=('Specify a directory for error and access logs. ',
340 'Default None, i.e. no logging.'))
Chris Sosa7c931362010-10-11 19:49:01 -0700341 (options, _) = parser.parse_args()
rtc@google.com21a5ca32009-11-04 18:23:23 +0000342
Chris Sosa7c931362010-10-11 19:49:01 -0700343 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
344 root_dir = os.path.realpath('%s/../..' % devserver_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700345 serve_only = False
346
Zdenek Behan608f46c2011-02-19 00:47:16 +0100347 static_dir = os.path.realpath('%s/static' % options.data_dir)
348 os.system('mkdir -p %s' % static_dir)
349
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -0500350 if options.log_dir and not os.path.isdir(options.log_dir):
351 parser.error('%s is not a valid dir, provide a valid dir to --log-dir' %
352 options.log_dir)
353
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700354 if options.archive_dir:
Zdenek Behan608f46c2011-02-19 00:47:16 +0100355 # TODO(zbehan) Remove legacy support:
356 # archive_dir is the directory where static/archive will point.
357 # If this is an absolute path, all is fine. If someone calls this
358 # using a relative path, that is relative to src/platform/dev/.
359 # That use case is unmaintainable, but since applications use it
360 # with =./static, instead of a boolean flag, we'll make this relative
361 # to devserver_dir to keep these unbroken. For now.
362 archive_dir = options.archive_dir
363 if not os.path.isabs(archive_dir):
Scott Zawalski51ccf9e2012-03-28 08:16:01 -0700364 archive_dir = os.path.realpath(os.path.join(devserver_dir,archive_dir))
Zdenek Behan608f46c2011-02-19 00:47:16 +0100365 _PrepareToServeUpdatesOnly(archive_dir, static_dir)
Zdenek Behan6d93e552011-03-02 22:35:49 +0100366 static_dir = os.path.realpath(archive_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700367 serve_only = True
Chris Sosa0356d3b2010-09-16 15:46:22 -0700368
Don Garrettf90edf02010-11-16 17:36:14 -0800369 cache_dir = os.path.join(static_dir, 'cache')
370 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER')
371
Don Garrettf90edf02010-11-16 17:36:14 -0800372 if os.path.exists(cache_dir):
Chris Sosa6b8c3742011-01-31 12:12:17 -0800373 if options.clear_cache:
374 # Clear the cache and exit on error.
375 if os.system('rm -rf %s/*' % cache_dir) != 0:
376 cherrypy.log('Failed to clear the cache with %s' % cmd,
377 'DEVSERVER')
378 sys.exit(1)
379
380 else:
381 # Clear all but the last N cached updates
382 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' %
383 (cache_dir, CACHED_ENTRIES))
384 if os.system(cmd) != 0:
385 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd,
386 'DEVSERVER')
387 sys.exit(1)
388 else:
389 os.makedirs(cache_dir)
Don Garrettf90edf02010-11-16 17:36:14 -0800390
Greg Spencerc8b59b22011-03-15 14:15:23 -0700391 if options.client_prefix_deprecated:
392 cherrypy.log('The --client_prefix argument is DEPRECATED, '
393 'and is no longer needed.', 'DEVSERVER')
394
Zdenek Behan5d21a2a2011-02-12 02:06:01 +0100395 cherrypy.log('Data dir is %s' % options.data_dir, 'DEVSERVER')
Chris Sosa7c931362010-10-11 19:49:01 -0700396 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER')
397 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER')
rtc@google.com21a5ca32009-11-04 18:23:23 +0000398
Andrew de los Reyes52620802010-04-12 13:40:07 -0700399 updater = autoupdate.Autoupdate(
400 root_dir=root_dir,
401 static_dir=static_dir,
Chris Sosa0356d3b2010-09-16 15:46:22 -0700402 serve_only=serve_only,
Andrew de los Reyes52620802010-04-12 13:40:07 -0700403 urlbase=options.urlbase,
404 test_image=options.test_image,
405 factory_config_path=options.factory_config,
Chris Sosa5d342a22010-09-28 16:54:41 -0700406 forced_image=options.image,
Don Garrett0c880e22010-11-17 18:13:37 -0800407 forced_payload=options.payload,
Chris Sosa62f720b2010-10-26 21:39:48 -0700408 port=options.port,
Don Garrett0ad09372010-12-06 16:20:30 -0800409 proxy_port=options.proxy_port,
Chris Sosa4136e692010-10-28 23:42:37 -0700410 src_image=options.src_image,
Chris Sosae67b78f2010-11-04 17:33:16 -0700411 vm=options.vm,
Chris Sosa08d55a22011-01-19 16:08:02 -0800412 board=options.board,
Chris Sosa0f1ec842011-02-14 16:33:22 -0800413 copy_to_static_root=not options.exit,
414 private_key=options.private_key,
Satoru Takabayashid733cbe2011-11-15 09:36:32 -0800415 critical_update=options.critical_update,
Chris Sosa0f1ec842011-02-14 16:33:22 -0800416 )
Chris Sosa7c931362010-10-11 19:49:01 -0700417
418 # Sanity-check for use of validate_factory_config.
419 if not options.factory_config and options.validate_factory_config:
420 parser.error('You need a factory_config to validate.')
rtc@google.com64244662009-11-12 00:52:08 +0000421
Chris Sosa0356d3b2010-09-16 15:46:22 -0700422 if options.factory_config:
Chris Sosa7c931362010-10-11 19:49:01 -0700423 updater.ImportFactoryConfigFile(options.factory_config,
Chris Sosa0356d3b2010-09-16 15:46:22 -0700424 options.validate_factory_config)
Chris Sosa7c931362010-10-11 19:49:01 -0700425 # We don't run the dev server with this option.
426 if options.validate_factory_config:
427 sys.exit(0)
Chris Sosa2c048f12010-10-27 16:05:27 -0700428 elif options.pregenerate_update:
Chris Sosae67b78f2010-11-04 17:33:16 -0700429 if not updater.PreGenerateUpdate():
430 sys.exit(1)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700431
Don Garrett0c880e22010-11-17 18:13:37 -0800432 # If the command line requested after setup, it's time to do it.
433 if not options.exit:
434 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))