blob: 92493149bfb6414b49bfe01d65fc016061ed08c7 [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 Sosab82107a2012-03-13 18:43:21 -070017import downloader
Chris Sosa0356d3b2010-09-16 15:46:22 -070018
Frank Farzan40160872011-12-12 18:39:18 -080019
Chris Sosa417e55d2011-01-25 16:40:48 -080020CACHED_ENTRIES = 12
Don Garrettf90edf02010-11-16 17:36:14 -080021
Chris Sosa0356d3b2010-09-16 15:46:22 -070022# Sets up global to share between classes.
rtc@google.com21a5ca32009-11-04 18:23:23 +000023global updater
24updater = None
rtc@google.comded22402009-10-26 22:36:21 +000025
Frank Farzan40160872011-12-12 18:39:18 -080026
Chris Sosab82107a2012-03-13 18:43:21 -070027def DevServerError(Exception):
28 """Exception class used by this module."""
29 pass
30
31
Scott Zawalski4647ce62012-01-03 17:17:28 -050032def _LeadingWhiteSpaceCount(string):
33 """Count the amount of leading whitespace in a string.
34
35 Args:
36 string: The string to count leading whitespace in.
37 Returns:
38 number of white space chars before characters start.
39 """
40 matched = re.match('^\s+', string)
41 if matched:
42 return len(matched.group())
43
44 return 0
45
46
47def _PrintDocStringAsHTML(func):
48 """Make a functions docstring somewhat HTML style.
49
50 Args:
51 func: The function to return the docstring from.
52 Returns:
53 A string that is somewhat formated for a web browser.
54 """
55 # TODO(scottz): Make this parse Args/Returns in a prettier way.
56 # Arguments could be bolded and indented etc.
57 html_doc = []
58 for line in func.__doc__.splitlines():
59 leading_space = _LeadingWhiteSpaceCount(line)
60 if leading_space > 0:
Chris Sosab82107a2012-03-13 18:43:21 -070061 line = ' ' * leading_space + line
Scott Zawalski4647ce62012-01-03 17:17:28 -050062
63 html_doc.append('<BR>%s' % line)
64
65 return '\n'.join(html_doc)
66
67
Chris Sosa7c931362010-10-11 19:49:01 -070068def _GetConfig(options):
69 """Returns the configuration for the devserver."""
70 base_config = { 'global':
71 { 'server.log_request_headers': True,
72 'server.protocol_version': 'HTTP/1.1',
Aaron Plattner2bfab982011-05-20 09:01:08 -070073 'server.socket_host': '::',
Chris Sosa7c931362010-10-11 19:49:01 -070074 'server.socket_port': int(options.port),
Chris Sosa374c62d2010-10-14 09:13:54 -070075 'server.socket_timeout': 6000,
76 'response.timeout': 6000,
Zdenek Behan1347a312011-02-10 03:59:17 +010077 'tools.staticdir.root':
78 os.path.dirname(os.path.abspath(sys.argv[0])),
Chris Sosa7c931362010-10-11 19:49:01 -070079 },
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070080 '/api':
81 {
82 # Gets rid of cherrypy parsing post file for args.
83 'request.process_request_body': False,
84 },
Chris Sosaa1ef0102010-10-21 16:22:35 -070085 '/build':
86 {
87 'response.timeout': 100000,
88 },
Chris Sosa7c931362010-10-11 19:49:01 -070089 '/update':
90 {
91 # Gets rid of cherrypy parsing post file for args.
92 'request.process_request_body': False,
Chris Sosaf65f4b92010-10-21 15:57:51 -070093 'response.timeout': 10000,
Chris Sosa7c931362010-10-11 19:49:01 -070094 },
95 # Sets up the static dir for file hosting.
96 '/static':
97 { 'tools.staticdir.dir': 'static',
98 'tools.staticdir.on': True,
Chris Sosaf65f4b92010-10-21 15:57:51 -070099 'response.timeout': 10000,
Chris Sosa7c931362010-10-11 19:49:01 -0700100 },
101 }
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -0500102
103 if options.log_dir:
104 base_config['global']['log.access_file'] = os.path.join(
105 options.log_dir, 'devserver_access.log')
106 base_config['global']['log.error_file'] = os.path.join(
107 options.log_dir, 'devserver_error.log')
108
Chris Sosa417e55d2011-01-25 16:40:48 -0800109 if options.production:
110 base_config['global']['server.environment'] = 'production'
111
Chris Sosa7c931362010-10-11 19:49:01 -0700112 return base_config
rtc@google.com64244662009-11-12 00:52:08 +0000113
Darin Petkove17164a2010-08-11 13:24:41 -0700114
Zdenek Behan608f46c2011-02-19 00:47:16 +0100115def _PrepareToServeUpdatesOnly(image_dir, static_dir):
Chris Sosa0356d3b2010-09-16 15:46:22 -0700116 """Sets up symlink to image_dir for serving purposes."""
117 assert os.path.exists(image_dir), '%s must exist.' % image_dir
118 # If we're serving out of an archived build dir (e.g. a
119 # buildbot), prepare this webserver's magic 'static/' dir with a
120 # link to the build archive.
Chris Sosa7c931362010-10-11 19:49:01 -0700121 cherrypy.log('Preparing autoupdate for "serve updates only" mode.',
122 'DEVSERVER')
Zdenek Behan608f46c2011-02-19 00:47:16 +0100123 if os.path.lexists('%s/archive' % static_dir):
124 if image_dir != os.readlink('%s/archive' % static_dir):
Chris Sosa7c931362010-10-11 19:49:01 -0700125 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER')
Zdenek Behan608f46c2011-02-19 00:47:16 +0100126 os.unlink('%s/archive' % static_dir)
127 os.symlink(image_dir, '%s/archive' % static_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700128 else:
Zdenek Behan608f46c2011-02-19 00:47:16 +0100129 os.symlink(image_dir, '%s/archive' % static_dir)
Chris Sosa7c931362010-10-11 19:49:01 -0700130 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir,
131 'DEVSERVER')
132
133
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700134class ApiRoot(object):
135 """RESTful API for Dev Server information."""
136 exposed = True
137
138 @cherrypy.expose
139 def hostinfo(self, ip):
140 """Returns a JSON dictionary containing information about the given ip.
141
142 Not all information may be known at the time the request is made. The
143 possible keys are:
144
145 last_event_type: int
146 Last update event type received.
147
148 last_event_status: int
149 Last update event status received.
150
151 last_known_version: string
152 Last known version recieved for update ping.
153
154 forced_update_label: string
155 Update label to force next update ping to use. Set by setnextupdate.
156
157 See the OmahaEvent class in update_engine/omaha_request_action.h for status
158 code definitions. If the ip does not exist an empty string is returned."""
159 return updater.HandleHostInfoPing(ip)
160
161 @cherrypy.expose
Gilad Arnold286a0062012-01-12 13:47:02 -0800162 def hostlog(self, ip):
163 """Returns a JSON object containing a log of events pertaining to a
164 particular host, or all hosts. Log events contain a timestamp and any
165 subset of the attributes listed for the hostinfo method."""
166 return updater.HandleHostLogPing(ip)
167
168 @cherrypy.expose
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700169 def setnextupdate(self, ip):
170 """Allows the response to the next update ping from a host to be set.
171
172 Takes the IP of the host and an update label as normally provided to the
173 /update command."""
174 body_length = int(cherrypy.request.headers['Content-Length'])
175 label = cherrypy.request.rfile.read(body_length)
176
177 if label:
178 label = label.strip()
179 if label:
180 return updater.HandleSetUpdatePing(ip, label)
181 raise cherrypy.HTTPError(400, 'No label provided.')
182
183
David Rochberg7c79a812011-01-19 14:24:45 -0500184class DevServerRoot(object):
Chris Sosa7c931362010-10-11 19:49:01 -0700185 """The Root Class for the Dev Server.
186
187 CherryPy works as follows:
188 For each method in this class, cherrpy interprets root/path
189 as a call to an instance of DevServerRoot->method_name. For example,
190 a call to http://myhost/build will call build. CherryPy automatically
191 parses http args and places them as keyword arguments in each method.
192 For paths http://myhost/update/dir1/dir2, you can use *args so that
193 cherrypy uses the update method and puts the extra paths in args.
194 """
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700195 api = ApiRoot()
Chris Sosa7c931362010-10-11 19:49:01 -0700196
David Rochberg7c79a812011-01-19 14:24:45 -0500197 def __init__(self):
Nick Sanders7dcaa2e2011-08-04 15:20:41 -0700198 self._builder = None
Chris Sosab82107a2012-03-13 18:43:21 -0700199 self._downloader_dict = {}
David Rochberg7c79a812011-01-19 14:24:45 -0500200
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700201 @cherrypy.expose
David Rochberg7c79a812011-01-19 14:24:45 -0500202 def build(self, board, pkg, **kwargs):
Chris Sosa7c931362010-10-11 19:49:01 -0700203 """Builds the package specified."""
Nick Sanders7dcaa2e2011-08-04 15:20:41 -0700204 import builder
205 if self._builder is None:
206 self._builder = builder.Builder()
David Rochberg7c79a812011-01-19 14:24:45 -0500207 return self._builder.Build(board, pkg, kwargs)
Chris Sosa7c931362010-10-11 19:49:01 -0700208
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700209 @cherrypy.expose
Frank Farzanbcb571e2012-01-03 11:48:17 -0800210 def download(self, **kwargs):
211 """Downloads and archives full/delta payloads from Google Storage.
212
Chris Sosab82107a2012-03-13 18:43:21 -0700213 This methods downloads artifacts. It may download artifacts in the
214 background in which case a caller should call wait_for_status to get
215 the status of the background artifact downloads. They should use the same
216 args passed to download.
217
Frank Farzanbcb571e2012-01-03 11:48:17 -0800218 Args:
219 archive_url: Google Storage URL for the build.
220
221 Example URL:
222 'http://myhost/download?archive_url=gs://chromeos-image-archive/'
223 'x86-generic/R17-1208.0.0-a1-b338'
224 """
Chris Sosab82107a2012-03-13 18:43:21 -0700225 downloader_instance = downloader.Downloader(updater.static_dir)
226 archive_url = kwargs.get('archive_url')
227 if not archive_url:
228 raise DevServerError("Didn't specify the archive_url in request")
229
230 return_obj = downloader_instance.Download(archive_url)
231 self._downloader_dict[archive_url] = downloader_instance
232 return return_obj
233
234 @cherrypy.expose
235 def wait_for_status(self, **kwargs):
236 """Waits for background artifacts to be downloaded from Google Storage.
237
238 Args:
239 archive_url: Google Storage URL for the build.
240
241 Example URL:
242 'http://myhost/wait_for_status?archive_url=gs://chromeos-image-archive/'
243 'x86-generic/R17-1208.0.0-a1-b338'
244 """
245 archive_url = kwargs.get('archive_url')
246 if not archive_url:
247 raise DevServerError("Didn't specify the archive_url in request")
248
249 downloader_instance = self._downloader_dict.get(archive_url)
250 if downloader_instance:
251 self._downloader_dict[archive_url] = None
252 return downloader_instance.GetStatusOfBackgroundDownloads()
253 else:
254 raise DevServerError('No download for the given archive_url found.')
Frank Farzan40160872011-12-12 18:39:18 -0800255
256 @cherrypy.expose
Scott Zawalski16954532012-03-20 15:31:36 -0400257 def latestbuild(self, **params):
258 """Return a string representing the latest build for a given target.
259
260 Args:
261 target: The build target, typically a combination of the board and the
262 type of build e.g. x86-mario-release.
263 milestone: The milestone to filter builds on. E.g. R16. Optional, if not
264 provided the latest RXX build will be returned.
265 Returns:
266 A string representation of the latest build if one exists, i.e.
267 R19-1993.0.0-a1-b1480.
268 An empty string if no latest could be found.
269 """
270 if not params:
271 return _PrintDocStringAsHTML(self.latestbuild)
272
273 if 'target' not in params:
274 raise cherrypy.HTTPError('500 Internal Server Error',
275 'Error: target= is required!')
276 try:
277 return devserver_util.GetLatestBuildVersion(
278 updater.static_dir, params['target'],
279 milestone=params.get('milestone'))
280 except devserver_util.DevServerUtilError as errmsg:
281 raise cherrypy.HTTPError('500 Internal Server Error', str(errmsg))
282
283 @cherrypy.expose
Scott Zawalski84a39c92012-01-13 15:12:42 -0500284 def controlfiles(self, **params):
Scott Zawalski4647ce62012-01-03 17:17:28 -0500285 """Return a control file or a list of all known control files.
286
287 Example URL:
288 To List all control files:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500289 http://dev-server/controlfiles?board=x86-alex-release&build=R18-1514.0.0
Scott Zawalski4647ce62012-01-03 17:17:28 -0500290 To return the contents of a path:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500291 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 -0500292
293 Args:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500294 build: The build i.e. x86-alex-release/R18-1514.0.0-a1-b1450.
Scott Zawalski4647ce62012-01-03 17:17:28 -0500295 control_path: If you want the contents of a control file set this
296 to the path. E.g. client/site_tests/sleeptest/control
297 Optional, if not provided return a list of control files is returned.
298 Returns:
299 Contents of a control file if control_path is provided.
300 A list of control files if no control_path is provided.
301 """
Scott Zawalski4647ce62012-01-03 17:17:28 -0500302 if not params:
303 return _PrintDocStringAsHTML(self.controlfiles)
304
Scott Zawalski84a39c92012-01-13 15:12:42 -0500305 if 'build' not in params:
Scott Zawalski4647ce62012-01-03 17:17:28 -0500306 raise cherrypy.HTTPError('500 Internal Server Error',
Scott Zawalski84a39c92012-01-13 15:12:42 -0500307 'Error: build= is required!')
Scott Zawalski4647ce62012-01-03 17:17:28 -0500308
309 if 'control_path' not in params:
310 return devserver_util.GetControlFileList(updater.static_dir,
Scott Zawalski84a39c92012-01-13 15:12:42 -0500311 params['build'])
Scott Zawalski4647ce62012-01-03 17:17:28 -0500312 else:
Scott Zawalski84a39c92012-01-13 15:12:42 -0500313 return devserver_util.GetControlFile(updater.static_dir, params['build'],
Scott Zawalski4647ce62012-01-03 17:17:28 -0500314 params['control_path'])
Frank Farzan40160872011-12-12 18:39:18 -0800315
316 @cherrypy.expose
Chris Sosa7c931362010-10-11 19:49:01 -0700317 def index(self):
318 return 'Welcome to the Dev Server!'
319
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700320 @cherrypy.expose
Chris Sosa7c931362010-10-11 19:49:01 -0700321 def update(self, *args):
322 label = '/'.join(args)
Gilad Arnold286a0062012-01-12 13:47:02 -0800323 body_length = int(cherrypy.request.headers.get('Content-Length', 0))
Chris Sosa7c931362010-10-11 19:49:01 -0700324 data = cherrypy.request.rfile.read(body_length)
325 return updater.HandleUpdatePing(data, label)
326
Chris Sosa0356d3b2010-09-16 15:46:22 -0700327
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700328if __name__ == '__main__':
329 usage = 'usage: %prog [options]'
Gilad Arnold286a0062012-01-12 13:47:02 -0800330 parser = optparse.OptionParser(usage=usage)
Sean O'Connore38ea152010-04-16 13:50:40 -0700331 parser.add_option('--archive_dir', dest='archive_dir',
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700332 help='serve archived builds only.')
Chris Sosae67b78f2010-11-04 17:33:16 -0700333 parser.add_option('--board', dest='board',
334 help='When pre-generating update, board for latest image.')
Don Garrett0c880e22010-11-17 18:13:37 -0800335 parser.add_option('--clear_cache', action='store_true', default=False,
Don Garrettf90edf02010-11-16 17:36:14 -0800336 help='Clear out all cached udpates and exit')
Greg Spencerc8b59b22011-03-15 14:15:23 -0700337 parser.add_option('--client_prefix', dest='client_prefix_deprecated',
338 help='No longer used. It is still here so we don\'t break '
339 'scripts that used it.', default='')
Satoru Takabayashid733cbe2011-11-15 09:36:32 -0800340 parser.add_option('--critical_update', dest='critical_update',
341 action='store_true', default=False,
342 help='Present update payload as critical')
Zdenek Behan5d21a2a2011-02-12 02:06:01 +0100343 parser.add_option('--data_dir', dest='data_dir',
344 help='Writable directory where static lives',
345 default=os.path.dirname(os.path.abspath(sys.argv[0])))
Don Garrett0c880e22010-11-17 18:13:37 -0800346 parser.add_option('--exit', action='store_true', default=False,
347 help='Don\'t start the server (still pregenerate or clear'
348 'cache).')
Andrew de los Reyes52620802010-04-12 13:40:07 -0700349 parser.add_option('--factory_config', dest='factory_config',
350 help='Config file for serving images from factory floor.')
Chris Sosa4136e692010-10-28 23:42:37 -0700351 parser.add_option('--for_vm', dest='vm', default=False, action='store_true',
352 help='Update is for a vm image.')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700353 parser.add_option('--image', dest='image',
354 help='Force update using this image.')
Chris Sosa2c048f12010-10-27 16:05:27 -0700355 parser.add_option('-p', '--pregenerate_update', action='store_true',
356 default=False, help='Pre-generate update payload.')
Don Garrett0c880e22010-11-17 18:13:37 -0800357 parser.add_option('--payload', dest='payload',
358 help='Use update payload from specified directory.')
Chris Sosa7c931362010-10-11 19:49:01 -0700359 parser.add_option('--port', default=8080,
Gilad Arnold286a0062012-01-12 13:47:02 -0800360 help='Port for the dev server to use (default: 8080).')
Chris Sosa0f1ec842011-02-14 16:33:22 -0800361 parser.add_option('--private_key', default=None,
362 help='Path to the private key in pem format.')
Chris Sosa417e55d2011-01-25 16:40:48 -0800363 parser.add_option('--production', action='store_true', default=False,
364 help='Have the devserver use production values.')
Don Garrett0ad09372010-12-06 16:20:30 -0800365 parser.add_option('--proxy_port', default=None,
366 help='Port to have the client connect to (testing support)')
Chris Sosa62f720b2010-10-26 21:39:48 -0700367 parser.add_option('--src_image', default='',
368 help='Image on remote machine for generating delta update.')
Sean O'Connor1f7fd362010-04-07 16:34:52 -0700369 parser.add_option('-t', action='store_true', dest='test_image')
370 parser.add_option('-u', '--urlbase', dest='urlbase',
371 help='base URL, other than devserver, for update images.')
Andrew de los Reyes52620802010-04-12 13:40:07 -0700372 parser.add_option('--validate_factory_config', action="store_true",
373 dest='validate_factory_config',
374 help='Validate factory config file, then exit.')
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -0500375 parser.add_option('-l', '--log-dir', default=None,
376 help=('Specify a directory for error and access logs. ',
377 'Default None, i.e. no logging.'))
Chris Sosa7c931362010-10-11 19:49:01 -0700378 (options, _) = parser.parse_args()
rtc@google.com21a5ca32009-11-04 18:23:23 +0000379
Chris Sosa7c931362010-10-11 19:49:01 -0700380 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
381 root_dir = os.path.realpath('%s/../..' % devserver_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700382 serve_only = False
383
Zdenek Behan608f46c2011-02-19 00:47:16 +0100384 static_dir = os.path.realpath('%s/static' % options.data_dir)
385 os.system('mkdir -p %s' % static_dir)
386
Scott Zawalski1c5e7cd2012-02-27 13:12:52 -0500387 if options.log_dir and not os.path.isdir(options.log_dir):
388 parser.error('%s is not a valid dir, provide a valid dir to --log-dir' %
389 options.log_dir)
390
Sean O'Connor14b6a0a2010-03-20 23:23:48 -0700391 if options.archive_dir:
Zdenek Behan608f46c2011-02-19 00:47:16 +0100392 # TODO(zbehan) Remove legacy support:
393 # archive_dir is the directory where static/archive will point.
394 # If this is an absolute path, all is fine. If someone calls this
395 # using a relative path, that is relative to src/platform/dev/.
396 # That use case is unmaintainable, but since applications use it
397 # with =./static, instead of a boolean flag, we'll make this relative
398 # to devserver_dir to keep these unbroken. For now.
399 archive_dir = options.archive_dir
400 if not os.path.isabs(archive_dir):
Chris Sosab82107a2012-03-13 18:43:21 -0700401 archive_dir = os.path.realpath(os.path.join(devserver_dir, archive_dir))
Zdenek Behan608f46c2011-02-19 00:47:16 +0100402 _PrepareToServeUpdatesOnly(archive_dir, static_dir)
Zdenek Behan6d93e552011-03-02 22:35:49 +0100403 static_dir = os.path.realpath(archive_dir)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700404 serve_only = True
Chris Sosa0356d3b2010-09-16 15:46:22 -0700405
Don Garrettf90edf02010-11-16 17:36:14 -0800406 cache_dir = os.path.join(static_dir, 'cache')
407 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER')
408
Don Garrettf90edf02010-11-16 17:36:14 -0800409 if os.path.exists(cache_dir):
Chris Sosa6b8c3742011-01-31 12:12:17 -0800410 if options.clear_cache:
411 # Clear the cache and exit on error.
412 if os.system('rm -rf %s/*' % cache_dir) != 0:
413 cherrypy.log('Failed to clear the cache with %s' % cmd,
414 'DEVSERVER')
415 sys.exit(1)
416
417 else:
418 # Clear all but the last N cached updates
419 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' %
420 (cache_dir, CACHED_ENTRIES))
421 if os.system(cmd) != 0:
422 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd,
423 'DEVSERVER')
424 sys.exit(1)
425 else:
426 os.makedirs(cache_dir)
Don Garrettf90edf02010-11-16 17:36:14 -0800427
Greg Spencerc8b59b22011-03-15 14:15:23 -0700428 if options.client_prefix_deprecated:
429 cherrypy.log('The --client_prefix argument is DEPRECATED, '
430 'and is no longer needed.', 'DEVSERVER')
431
Zdenek Behan5d21a2a2011-02-12 02:06:01 +0100432 cherrypy.log('Data dir is %s' % options.data_dir, 'DEVSERVER')
Chris Sosa7c931362010-10-11 19:49:01 -0700433 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER')
434 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER')
rtc@google.com21a5ca32009-11-04 18:23:23 +0000435
Andrew de los Reyes52620802010-04-12 13:40:07 -0700436 updater = autoupdate.Autoupdate(
437 root_dir=root_dir,
438 static_dir=static_dir,
Chris Sosa0356d3b2010-09-16 15:46:22 -0700439 serve_only=serve_only,
Andrew de los Reyes52620802010-04-12 13:40:07 -0700440 urlbase=options.urlbase,
441 test_image=options.test_image,
442 factory_config_path=options.factory_config,
Chris Sosa5d342a22010-09-28 16:54:41 -0700443 forced_image=options.image,
Don Garrett0c880e22010-11-17 18:13:37 -0800444 forced_payload=options.payload,
Chris Sosa62f720b2010-10-26 21:39:48 -0700445 port=options.port,
Don Garrett0ad09372010-12-06 16:20:30 -0800446 proxy_port=options.proxy_port,
Chris Sosa4136e692010-10-28 23:42:37 -0700447 src_image=options.src_image,
Chris Sosae67b78f2010-11-04 17:33:16 -0700448 vm=options.vm,
Chris Sosa08d55a22011-01-19 16:08:02 -0800449 board=options.board,
Chris Sosa0f1ec842011-02-14 16:33:22 -0800450 copy_to_static_root=not options.exit,
451 private_key=options.private_key,
Satoru Takabayashid733cbe2011-11-15 09:36:32 -0800452 critical_update=options.critical_update,
Chris Sosa0f1ec842011-02-14 16:33:22 -0800453 )
Chris Sosa7c931362010-10-11 19:49:01 -0700454
455 # Sanity-check for use of validate_factory_config.
456 if not options.factory_config and options.validate_factory_config:
457 parser.error('You need a factory_config to validate.')
rtc@google.com64244662009-11-12 00:52:08 +0000458
Chris Sosa0356d3b2010-09-16 15:46:22 -0700459 if options.factory_config:
Chris Sosa7c931362010-10-11 19:49:01 -0700460 updater.ImportFactoryConfigFile(options.factory_config,
Chris Sosa0356d3b2010-09-16 15:46:22 -0700461 options.validate_factory_config)
Chris Sosa7c931362010-10-11 19:49:01 -0700462 # We don't run the dev server with this option.
463 if options.validate_factory_config:
464 sys.exit(0)
Chris Sosa2c048f12010-10-27 16:05:27 -0700465 elif options.pregenerate_update:
Chris Sosae67b78f2010-11-04 17:33:16 -0700466 if not updater.PreGenerateUpdate():
467 sys.exit(1)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700468
Don Garrett0c880e22010-11-17 18:13:37 -0800469 # If the command line requested after setup, it's time to do it.
470 if not options.exit:
471 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))