OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """A CherryPy-based webserver to host images and build packages.""" | 7 """A CherryPy-based webserver to host images and build packages.""" |
8 | 8 |
9 import cherrypy | 9 import cherrypy |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 | 14 |
15 import autoupdate | 15 import autoupdate |
16 import builder | 16 import builder |
17 | 17 |
18 CACHED_ENTRIES=12 | 18 CACHED_ENTRIES = 12 |
19 | 19 |
20 # Sets up global to share between classes. | 20 # Sets up global to share between classes. |
21 global updater | 21 global updater |
22 updater = None | 22 updater = None |
23 | 23 |
24 def _GetConfig(options): | 24 def _GetConfig(options): |
25 """Returns the configuration for the devserver.""" | 25 """Returns the configuration for the devserver.""" |
26 base_config = { 'global': | 26 base_config = { 'global': |
27 { 'server.log_request_headers': True, | 27 { 'server.log_request_headers': True, |
28 'server.protocol_version': 'HTTP/1.1', | 28 'server.protocol_version': 'HTTP/1.1', |
(...skipping 13 matching lines...) Expand all Loading... |
42 'request.process_request_body': False, | 42 'request.process_request_body': False, |
43 'response.timeout': 10000, | 43 'response.timeout': 10000, |
44 }, | 44 }, |
45 # Sets up the static dir for file hosting. | 45 # Sets up the static dir for file hosting. |
46 '/static': | 46 '/static': |
47 { 'tools.staticdir.dir': 'static', | 47 { 'tools.staticdir.dir': 'static', |
48 'tools.staticdir.on': True, | 48 'tools.staticdir.on': True, |
49 'response.timeout': 10000, | 49 'response.timeout': 10000, |
50 }, | 50 }, |
51 } | 51 } |
| 52 if options.production: |
| 53 base_config['global']['server.environment'] = 'production' |
| 54 |
52 return base_config | 55 return base_config |
53 | 56 |
54 | 57 |
55 def _PrepareToServeUpdatesOnly(image_dir): | 58 def _PrepareToServeUpdatesOnly(image_dir): |
56 """Sets up symlink to image_dir for serving purposes.""" | 59 """Sets up symlink to image_dir for serving purposes.""" |
57 assert os.path.exists(image_dir), '%s must exist.' % image_dir | 60 assert os.path.exists(image_dir), '%s must exist.' % image_dir |
58 # If we're serving out of an archived build dir (e.g. a | 61 # If we're serving out of an archived build dir (e.g. a |
59 # buildbot), prepare this webserver's magic 'static/' dir with a | 62 # buildbot), prepare this webserver's magic 'static/' dir with a |
60 # link to the build archive. | 63 # link to the build archive. |
61 cherrypy.log('Preparing autoupdate for "serve updates only" mode.', | 64 cherrypy.log('Preparing autoupdate for "serve updates only" mode.', |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', | 128 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', |
126 help='Update is for a vm image.') | 129 help='Update is for a vm image.') |
127 parser.add_option('--image', dest='image', | 130 parser.add_option('--image', dest='image', |
128 help='Force update using this image.') | 131 help='Force update using this image.') |
129 parser.add_option('-p', '--pregenerate_update', action='store_true', | 132 parser.add_option('-p', '--pregenerate_update', action='store_true', |
130 default=False, help='Pre-generate update payload.') | 133 default=False, help='Pre-generate update payload.') |
131 parser.add_option('--payload', dest='payload', | 134 parser.add_option('--payload', dest='payload', |
132 help='Use update payload from specified directory.') | 135 help='Use update payload from specified directory.') |
133 parser.add_option('--port', default=8080, | 136 parser.add_option('--port', default=8080, |
134 help='Port for the dev server to use.') | 137 help='Port for the dev server to use.') |
| 138 parser.add_option('--production', action='store_true', default=False, |
| 139 help='Have the devserver use production values.') |
135 parser.add_option('--proxy_port', default=None, | 140 parser.add_option('--proxy_port', default=None, |
136 help='Port to have the client connect to (testing support)') | 141 help='Port to have the client connect to (testing support)') |
137 parser.add_option('--src_image', default='', | 142 parser.add_option('--src_image', default='', |
138 help='Image on remote machine for generating delta update.') | 143 help='Image on remote machine for generating delta update.') |
139 parser.add_option('-t', action='store_true', dest='test_image') | 144 parser.add_option('-t', action='store_true', dest='test_image') |
140 parser.add_option('-u', '--urlbase', dest='urlbase', | 145 parser.add_option('-u', '--urlbase', dest='urlbase', |
141 help='base URL, other than devserver, for update images.') | 146 help='base URL, other than devserver, for update images.') |
142 parser.add_option('--validate_factory_config', action="store_true", | 147 parser.add_option('--validate_factory_config', action="store_true", |
143 dest='validate_factory_config', | 148 dest='validate_factory_config', |
144 help='Validate factory config file, then exit.') | 149 help='Validate factory config file, then exit.') |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 # We don't run the dev server with this option. | 211 # We don't run the dev server with this option. |
207 if options.validate_factory_config: | 212 if options.validate_factory_config: |
208 sys.exit(0) | 213 sys.exit(0) |
209 elif options.pregenerate_update: | 214 elif options.pregenerate_update: |
210 if not updater.PreGenerateUpdate(): | 215 if not updater.PreGenerateUpdate(): |
211 sys.exit(1) | 216 sys.exit(1) |
212 | 217 |
213 # If the command line requested after setup, it's time to do it. | 218 # If the command line requested after setup, it's time to do it. |
214 if not options.exit: | 219 if not options.exit: |
215 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) | 220 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |
OLD | NEW |