Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 3 | # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 7 | """A CherryPy-based webserver to host images and build packages.""" |
| 8 | |
| 9 | import cherrypy |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 10 | import optparse |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 11 | import os |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 12 | import subprocess |
chocobo@google.com | 4dc2581 | 2009-10-27 23:46:26 +0000 | [diff] [blame] | 13 | import sys |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 14 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 15 | import autoupdate |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 16 | |
Frank Farzan | 4016087 | 2011-12-12 18:39:18 -0800 | [diff] [blame] | 17 | |
Chris Sosa | 417e55d | 2011-01-25 16:40:48 -0800 | [diff] [blame] | 18 | CACHED_ENTRIES = 12 |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 19 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 20 | # Sets up global to share between classes. |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 21 | global updater |
| 22 | updater = None |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 23 | |
Frank Farzan | 4016087 | 2011-12-12 18:39:18 -0800 | [diff] [blame] | 24 | |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 25 | def _GetConfig(options): |
| 26 | """Returns the configuration for the devserver.""" |
| 27 | base_config = { 'global': |
| 28 | { 'server.log_request_headers': True, |
| 29 | 'server.protocol_version': 'HTTP/1.1', |
Aaron Plattner | 2bfab98 | 2011-05-20 09:01:08 -0700 | [diff] [blame] | 30 | 'server.socket_host': '::', |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 31 | 'server.socket_port': int(options.port), |
Chris Sosa | 374c62d | 2010-10-14 09:13:54 -0700 | [diff] [blame] | 32 | 'server.socket_timeout': 6000, |
| 33 | 'response.timeout': 6000, |
Zdenek Behan | 1347a31 | 2011-02-10 03:59:17 +0100 | [diff] [blame] | 34 | 'tools.staticdir.root': |
| 35 | os.path.dirname(os.path.abspath(sys.argv[0])), |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 36 | }, |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 37 | '/api': |
| 38 | { |
| 39 | # Gets rid of cherrypy parsing post file for args. |
| 40 | 'request.process_request_body': False, |
| 41 | }, |
Chris Sosa | a1ef010 | 2010-10-21 16:22:35 -0700 | [diff] [blame] | 42 | '/build': |
| 43 | { |
| 44 | 'response.timeout': 100000, |
| 45 | }, |
Frank Farzan | 4016087 | 2011-12-12 18:39:18 -0800 | [diff] [blame] | 46 | '/download': |
| 47 | { |
| 48 | # Gets rid of cherrypy parsing post file for args. |
| 49 | 'request.process_request_body': False, |
| 50 | }, |
| 51 | '/controlfile': |
| 52 | { |
| 53 | # Gets rid of cherrypy parsing post file for args. |
| 54 | 'request.process_request_body': False, |
| 55 | }, |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 56 | '/update': |
| 57 | { |
| 58 | # Gets rid of cherrypy parsing post file for args. |
| 59 | 'request.process_request_body': False, |
Chris Sosa | f65f4b9 | 2010-10-21 15:57:51 -0700 | [diff] [blame] | 60 | 'response.timeout': 10000, |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 61 | }, |
| 62 | # Sets up the static dir for file hosting. |
| 63 | '/static': |
| 64 | { 'tools.staticdir.dir': 'static', |
| 65 | 'tools.staticdir.on': True, |
Chris Sosa | f65f4b9 | 2010-10-21 15:57:51 -0700 | [diff] [blame] | 66 | 'response.timeout': 10000, |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 67 | }, |
| 68 | } |
Chris Sosa | 417e55d | 2011-01-25 16:40:48 -0800 | [diff] [blame] | 69 | if options.production: |
| 70 | base_config['global']['server.environment'] = 'production' |
| 71 | |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 72 | return base_config |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 73 | |
Darin Petkov | e17164a | 2010-08-11 13:24:41 -0700 | [diff] [blame] | 74 | |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 75 | def _PrepareToServeUpdatesOnly(image_dir, static_dir): |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 76 | """Sets up symlink to image_dir for serving purposes.""" |
| 77 | assert os.path.exists(image_dir), '%s must exist.' % image_dir |
| 78 | # If we're serving out of an archived build dir (e.g. a |
| 79 | # buildbot), prepare this webserver's magic 'static/' dir with a |
| 80 | # link to the build archive. |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 81 | cherrypy.log('Preparing autoupdate for "serve updates only" mode.', |
| 82 | 'DEVSERVER') |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 83 | if os.path.lexists('%s/archive' % static_dir): |
| 84 | if image_dir != os.readlink('%s/archive' % static_dir): |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 85 | cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER') |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 86 | os.unlink('%s/archive' % static_dir) |
| 87 | os.symlink(image_dir, '%s/archive' % static_dir) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 88 | else: |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 89 | os.symlink(image_dir, '%s/archive' % static_dir) |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 90 | cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir, |
| 91 | 'DEVSERVER') |
| 92 | |
| 93 | |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 94 | class ApiRoot(object): |
| 95 | """RESTful API for Dev Server information.""" |
| 96 | exposed = True |
| 97 | |
| 98 | @cherrypy.expose |
| 99 | def hostinfo(self, ip): |
| 100 | """Returns a JSON dictionary containing information about the given ip. |
| 101 | |
| 102 | Not all information may be known at the time the request is made. The |
| 103 | possible keys are: |
| 104 | |
| 105 | last_event_type: int |
| 106 | Last update event type received. |
| 107 | |
| 108 | last_event_status: int |
| 109 | Last update event status received. |
| 110 | |
| 111 | last_known_version: string |
| 112 | Last known version recieved for update ping. |
| 113 | |
| 114 | forced_update_label: string |
| 115 | Update label to force next update ping to use. Set by setnextupdate. |
| 116 | |
| 117 | See the OmahaEvent class in update_engine/omaha_request_action.h for status |
| 118 | code definitions. If the ip does not exist an empty string is returned.""" |
| 119 | return updater.HandleHostInfoPing(ip) |
| 120 | |
| 121 | @cherrypy.expose |
| 122 | def setnextupdate(self, ip): |
| 123 | """Allows the response to the next update ping from a host to be set. |
| 124 | |
| 125 | Takes the IP of the host and an update label as normally provided to the |
| 126 | /update command.""" |
| 127 | body_length = int(cherrypy.request.headers['Content-Length']) |
| 128 | label = cherrypy.request.rfile.read(body_length) |
| 129 | |
| 130 | if label: |
| 131 | label = label.strip() |
| 132 | if label: |
| 133 | return updater.HandleSetUpdatePing(ip, label) |
| 134 | raise cherrypy.HTTPError(400, 'No label provided.') |
| 135 | |
| 136 | |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 137 | class DevServerRoot(object): |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 138 | """The Root Class for the Dev Server. |
| 139 | |
| 140 | CherryPy works as follows: |
| 141 | For each method in this class, cherrpy interprets root/path |
| 142 | as a call to an instance of DevServerRoot->method_name. For example, |
| 143 | a call to http://myhost/build will call build. CherryPy automatically |
| 144 | parses http args and places them as keyword arguments in each method. |
| 145 | For paths http://myhost/update/dir1/dir2, you can use *args so that |
| 146 | cherrypy uses the update method and puts the extra paths in args. |
| 147 | """ |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 148 | api = ApiRoot() |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 149 | |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 150 | def __init__(self): |
Nick Sanders | 7dcaa2e | 2011-08-04 15:20:41 -0700 | [diff] [blame] | 151 | self._builder = None |
Frank Farzan | 4016087 | 2011-12-12 18:39:18 -0800 | [diff] [blame] | 152 | self._downloader = None |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 153 | |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 154 | @cherrypy.expose |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 155 | def build(self, board, pkg, **kwargs): |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 156 | """Builds the package specified.""" |
Nick Sanders | 7dcaa2e | 2011-08-04 15:20:41 -0700 | [diff] [blame] | 157 | import builder |
| 158 | if self._builder is None: |
| 159 | self._builder = builder.Builder() |
David Rochberg | 7c79a81 | 2011-01-19 14:24:45 -0500 | [diff] [blame] | 160 | return self._builder.Build(board, pkg, kwargs) |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 161 | |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 162 | @cherrypy.expose |
Frank Farzan | 4016087 | 2011-12-12 18:39:18 -0800 | [diff] [blame] | 163 | def download(self, *args): |
| 164 | """Downloads and archives full/delta payloads from Google Storage.""" |
| 165 | import downloader |
| 166 | archive_url = '/'.join(args) |
| 167 | if self._downloader is None: |
| 168 | self._downloader = downloader.Downloader(updater.static_dir) |
| 169 | return self._downloader.Download(archive_url) |
| 170 | |
| 171 | @cherrypy.expose |
| 172 | def controlfile(self, board, build, *args): |
| 173 | """Return the content of the control file.""" |
| 174 | import devserver_util |
| 175 | control_path = os.path.sep.join(args) |
| 176 | return devserver_util.GetControlFile(updater.static_dir, board, build, |
| 177 | control_path) |
| 178 | |
| 179 | @cherrypy.expose |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 180 | def index(self): |
| 181 | return 'Welcome to the Dev Server!' |
| 182 | |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 183 | @cherrypy.expose |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 184 | def update(self, *args): |
| 185 | label = '/'.join(args) |
| 186 | body_length = int(cherrypy.request.headers['Content-Length']) |
| 187 | data = cherrypy.request.rfile.read(body_length) |
| 188 | return updater.HandleUpdatePing(data, label) |
| 189 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 190 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 191 | if __name__ == '__main__': |
| 192 | usage = 'usage: %prog [options]' |
| 193 | parser = optparse.OptionParser(usage) |
Sean O'Connor | e38ea15 | 2010-04-16 13:50:40 -0700 | [diff] [blame] | 194 | parser.add_option('--archive_dir', dest='archive_dir', |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 195 | help='serve archived builds only.') |
Chris Sosa | e67b78f | 2010-11-04 17:33:16 -0700 | [diff] [blame] | 196 | parser.add_option('--board', dest='board', |
| 197 | help='When pre-generating update, board for latest image.') |
Don Garrett | 0c880e2 | 2010-11-17 18:13:37 -0800 | [diff] [blame] | 198 | parser.add_option('--clear_cache', action='store_true', default=False, |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 199 | help='Clear out all cached udpates and exit') |
Greg Spencer | c8b59b2 | 2011-03-15 14:15:23 -0700 | [diff] [blame] | 200 | parser.add_option('--client_prefix', dest='client_prefix_deprecated', |
| 201 | help='No longer used. It is still here so we don\'t break ' |
| 202 | 'scripts that used it.', default='') |
Satoru Takabayashi | d733cbe | 2011-11-15 09:36:32 -0800 | [diff] [blame] | 203 | parser.add_option('--critical_update', dest='critical_update', |
| 204 | action='store_true', default=False, |
| 205 | help='Present update payload as critical') |
Zdenek Behan | 5d21a2a | 2011-02-12 02:06:01 +0100 | [diff] [blame] | 206 | parser.add_option('--data_dir', dest='data_dir', |
| 207 | help='Writable directory where static lives', |
| 208 | default=os.path.dirname(os.path.abspath(sys.argv[0]))) |
Don Garrett | 0c880e2 | 2010-11-17 18:13:37 -0800 | [diff] [blame] | 209 | parser.add_option('--exit', action='store_true', default=False, |
| 210 | help='Don\'t start the server (still pregenerate or clear' |
| 211 | 'cache).') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 212 | parser.add_option('--factory_config', dest='factory_config', |
| 213 | help='Config file for serving images from factory floor.') |
Chris Sosa | 4136e69 | 2010-10-28 23:42:37 -0700 | [diff] [blame] | 214 | parser.add_option('--for_vm', dest='vm', default=False, action='store_true', |
| 215 | help='Update is for a vm image.') |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 216 | parser.add_option('--image', dest='image', |
| 217 | help='Force update using this image.') |
Chris Sosa | 2c048f1 | 2010-10-27 16:05:27 -0700 | [diff] [blame] | 218 | parser.add_option('-p', '--pregenerate_update', action='store_true', |
| 219 | default=False, help='Pre-generate update payload.') |
Don Garrett | 0c880e2 | 2010-11-17 18:13:37 -0800 | [diff] [blame] | 220 | parser.add_option('--payload', dest='payload', |
| 221 | help='Use update payload from specified directory.') |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 222 | parser.add_option('--port', default=8080, |
| 223 | help='Port for the dev server to use.') |
Chris Sosa | 0f1ec84 | 2011-02-14 16:33:22 -0800 | [diff] [blame] | 224 | parser.add_option('--private_key', default=None, |
| 225 | help='Path to the private key in pem format.') |
Chris Sosa | 417e55d | 2011-01-25 16:40:48 -0800 | [diff] [blame] | 226 | parser.add_option('--production', action='store_true', default=False, |
| 227 | help='Have the devserver use production values.') |
Don Garrett | 0ad0937 | 2010-12-06 16:20:30 -0800 | [diff] [blame] | 228 | parser.add_option('--proxy_port', default=None, |
| 229 | help='Port to have the client connect to (testing support)') |
Chris Sosa | 62f720b | 2010-10-26 21:39:48 -0700 | [diff] [blame] | 230 | parser.add_option('--src_image', default='', |
| 231 | help='Image on remote machine for generating delta update.') |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 232 | parser.add_option('-t', action='store_true', dest='test_image') |
| 233 | parser.add_option('-u', '--urlbase', dest='urlbase', |
| 234 | help='base URL, other than devserver, for update images.') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 235 | parser.add_option('--validate_factory_config', action="store_true", |
| 236 | dest='validate_factory_config', |
| 237 | help='Validate factory config file, then exit.') |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 238 | parser.set_usage(parser.format_help()) |
| 239 | (options, _) = parser.parse_args() |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 240 | |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 241 | devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 242 | root_dir = os.path.realpath('%s/../..' % devserver_dir) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 243 | serve_only = False |
| 244 | |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 245 | static_dir = os.path.realpath('%s/static' % options.data_dir) |
| 246 | os.system('mkdir -p %s' % static_dir) |
| 247 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 248 | if options.archive_dir: |
Zdenek Behan | 608f46c | 2011-02-19 00:47:16 +0100 | [diff] [blame] | 249 | # TODO(zbehan) Remove legacy support: |
| 250 | # archive_dir is the directory where static/archive will point. |
| 251 | # If this is an absolute path, all is fine. If someone calls this |
| 252 | # using a relative path, that is relative to src/platform/dev/. |
| 253 | # That use case is unmaintainable, but since applications use it |
| 254 | # with =./static, instead of a boolean flag, we'll make this relative |
| 255 | # to devserver_dir to keep these unbroken. For now. |
| 256 | archive_dir = options.archive_dir |
| 257 | if not os.path.isabs(archive_dir): |
| 258 | archive_dir = os.path.realpath(os.path.join(devserver_dir,archive_dir)) |
| 259 | _PrepareToServeUpdatesOnly(archive_dir, static_dir) |
Zdenek Behan | 6d93e55 | 2011-03-02 22:35:49 +0100 | [diff] [blame] | 260 | static_dir = os.path.realpath(archive_dir) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 261 | serve_only = True |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 262 | |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 263 | cache_dir = os.path.join(static_dir, 'cache') |
| 264 | cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') |
| 265 | |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 266 | if os.path.exists(cache_dir): |
Chris Sosa | 6b8c374 | 2011-01-31 12:12:17 -0800 | [diff] [blame] | 267 | if options.clear_cache: |
| 268 | # Clear the cache and exit on error. |
| 269 | if os.system('rm -rf %s/*' % cache_dir) != 0: |
| 270 | cherrypy.log('Failed to clear the cache with %s' % cmd, |
| 271 | 'DEVSERVER') |
| 272 | sys.exit(1) |
| 273 | |
| 274 | else: |
| 275 | # Clear all but the last N cached updates |
| 276 | cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' % |
| 277 | (cache_dir, CACHED_ENTRIES)) |
| 278 | if os.system(cmd) != 0: |
| 279 | cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, |
| 280 | 'DEVSERVER') |
| 281 | sys.exit(1) |
| 282 | else: |
| 283 | os.makedirs(cache_dir) |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 284 | |
Greg Spencer | c8b59b2 | 2011-03-15 14:15:23 -0700 | [diff] [blame] | 285 | if options.client_prefix_deprecated: |
| 286 | cherrypy.log('The --client_prefix argument is DEPRECATED, ' |
| 287 | 'and is no longer needed.', 'DEVSERVER') |
| 288 | |
Zdenek Behan | 5d21a2a | 2011-02-12 02:06:01 +0100 | [diff] [blame] | 289 | cherrypy.log('Data dir is %s' % options.data_dir, 'DEVSERVER') |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 290 | cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') |
| 291 | cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 292 | |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 293 | updater = autoupdate.Autoupdate( |
| 294 | root_dir=root_dir, |
| 295 | static_dir=static_dir, |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 296 | serve_only=serve_only, |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 297 | urlbase=options.urlbase, |
| 298 | test_image=options.test_image, |
| 299 | factory_config_path=options.factory_config, |
Chris Sosa | 5d342a2 | 2010-09-28 16:54:41 -0700 | [diff] [blame] | 300 | forced_image=options.image, |
Don Garrett | 0c880e2 | 2010-11-17 18:13:37 -0800 | [diff] [blame] | 301 | forced_payload=options.payload, |
Chris Sosa | 62f720b | 2010-10-26 21:39:48 -0700 | [diff] [blame] | 302 | port=options.port, |
Don Garrett | 0ad0937 | 2010-12-06 16:20:30 -0800 | [diff] [blame] | 303 | proxy_port=options.proxy_port, |
Chris Sosa | 4136e69 | 2010-10-28 23:42:37 -0700 | [diff] [blame] | 304 | src_image=options.src_image, |
Chris Sosa | e67b78f | 2010-11-04 17:33:16 -0700 | [diff] [blame] | 305 | vm=options.vm, |
Chris Sosa | 08d55a2 | 2011-01-19 16:08:02 -0800 | [diff] [blame] | 306 | board=options.board, |
Chris Sosa | 0f1ec84 | 2011-02-14 16:33:22 -0800 | [diff] [blame] | 307 | copy_to_static_root=not options.exit, |
| 308 | private_key=options.private_key, |
Satoru Takabayashi | d733cbe | 2011-11-15 09:36:32 -0800 | [diff] [blame] | 309 | critical_update=options.critical_update, |
Chris Sosa | 0f1ec84 | 2011-02-14 16:33:22 -0800 | [diff] [blame] | 310 | ) |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 311 | |
| 312 | # Sanity-check for use of validate_factory_config. |
| 313 | if not options.factory_config and options.validate_factory_config: |
| 314 | parser.error('You need a factory_config to validate.') |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 315 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 316 | if options.factory_config: |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 317 | updater.ImportFactoryConfigFile(options.factory_config, |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 318 | options.validate_factory_config) |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 319 | # We don't run the dev server with this option. |
| 320 | if options.validate_factory_config: |
| 321 | sys.exit(0) |
Chris Sosa | 2c048f1 | 2010-10-27 16:05:27 -0700 | [diff] [blame] | 322 | elif options.pregenerate_update: |
Chris Sosa | e67b78f | 2010-11-04 17:33:16 -0700 | [diff] [blame] | 323 | if not updater.PreGenerateUpdate(): |
| 324 | sys.exit(1) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 325 | |
Don Garrett | 0c880e2 | 2010-11-17 18:13:37 -0800 | [diff] [blame] | 326 | # If the command line requested after setup, it's time to do it. |
| 327 | if not options.exit: |
| 328 | cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |