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 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 index.exposed = True | 108 index.exposed = True |
109 | 109 |
110 | 110 |
111 if __name__ == '__main__': | 111 if __name__ == '__main__': |
112 usage = 'usage: %prog [options]' | 112 usage = 'usage: %prog [options]' |
113 parser = optparse.OptionParser(usage) | 113 parser = optparse.OptionParser(usage) |
114 parser.add_option('--archive_dir', dest='archive_dir', | 114 parser.add_option('--archive_dir', dest='archive_dir', |
115 help='serve archived builds only.') | 115 help='serve archived builds only.') |
116 parser.add_option('--board', dest='board', | 116 parser.add_option('--board', dest='board', |
117 help='When pre-generating update, board for latest image.') | 117 help='When pre-generating update, board for latest image.') |
118 parser.add_option('--clear_cache', action="store_true", default=False, | 118 parser.add_option('--clear_cache', action='store_true', default=False, |
119 help='Clear out all cached udpates and exit') | 119 help='Clear out all cached udpates and exit') |
120 parser.add_option('--client_prefix', dest='client_prefix', | 120 parser.add_option('--client_prefix', dest='client_prefix', |
121 help='Required prefix for client software version.', | 121 help='Required prefix for client software version.', |
122 default='MementoSoftwareUpdate') | 122 default='MementoSoftwareUpdate') |
123 parser.add_option('--exit', action='store_true', default=False, | |
124 help='Don\'t start the server (still pregenerate or clear' | |
125 'cache).') | |
123 parser.add_option('--factory_config', dest='factory_config', | 126 parser.add_option('--factory_config', dest='factory_config', |
124 help='Config file for serving images from factory floor.') | 127 help='Config file for serving images from factory floor.') |
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.') |
134 parser.add_option('--payload', dest='payload', | |
135 help='Use update payload from specified directory.') | |
131 parser.add_option('--port', default=8080, | 136 parser.add_option('--port', default=8080, |
132 help='Port for the dev server to use.') | 137 help='Port for the dev server to use.') |
133 parser.add_option('--src_image', default='', | 138 parser.add_option('--src_image', default='', |
134 help='Image on remote machine for generating delta update.') | 139 help='Image on remote machine for generating delta update.') |
135 parser.add_option('-t', action='store_true', dest='test_image') | 140 parser.add_option('-t', action='store_true', dest='test_image') |
136 parser.add_option('-u', '--urlbase', dest='urlbase', | 141 parser.add_option('-u', '--urlbase', dest='urlbase', |
137 help='base URL, other than devserver, for update images.') | 142 help='base URL, other than devserver, for update images.') |
138 parser.add_option('--validate_factory_config', action="store_true", | 143 parser.add_option('--validate_factory_config', action="store_true", |
139 dest='validate_factory_config', | 144 dest='validate_factory_config', |
140 help='Validate factory config file, then exit.') | 145 help='Validate factory config file, then exit.') |
141 parser.set_usage(parser.format_help()) | 146 parser.set_usage(parser.format_help()) |
142 (options, _) = parser.parse_args() | 147 (options, _) = parser.parse_args() |
143 | 148 |
144 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | 149 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
145 root_dir = os.path.realpath('%s/../..' % devserver_dir) | 150 root_dir = os.path.realpath('%s/../..' % devserver_dir) |
146 serve_only = False | 151 serve_only = False |
147 | 152 |
148 if options.archive_dir: | 153 if options.archive_dir: |
149 static_dir = os.path.realpath(options.archive_dir) | 154 static_dir = os.path.realpath(options.archive_dir) |
150 _PrepareToServeUpdatesOnly(static_dir) | 155 _PrepareToServeUpdatesOnly(static_dir) |
151 serve_only = True | 156 serve_only = True |
152 else: | 157 else: |
153 static_dir = os.path.realpath('%s/static' % devserver_dir) | 158 static_dir = os.path.realpath('%s/static' % devserver_dir) |
154 os.system('mkdir -p %s' % static_dir) | 159 os.system('mkdir -p %s' % static_dir) |
155 | 160 |
156 cache_dir = os.path.join(static_dir, 'cache') | 161 cache_dir = os.path.join(static_dir, 'cache') |
157 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') | 162 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') |
158 | 163 |
159 if options.clear_cache: | 164 if options.clear_cache: |
160 # Clear the cache and exit | 165 # Clear the cache and exit on error |
161 sys.exit(os.system('sudo rm -rf %s' % cache_dir)) | 166 if os.system('sudo rm -rf %s' % cache_dir) != 0: |
167 cherrypy.log('Failed to clear the cache with %s' % cmd, | |
168 'DEVSERVER') | |
169 sys.exit(1) | |
162 | 170 |
163 if os.path.exists(cache_dir): | 171 if os.path.exists(cache_dir): |
164 # Clear all but the last N cached updates | 172 # Clear all but the last N cached updates |
165 cmd = ('cd %s; ls -1tr | head --lines=-%d | xargs rm -rf' % | 173 cmd = ('cd %s; ls -1tr | head --lines=-%d | xargs rm -rf' % |
166 (cache_dir, CACHED_ENTRIES)) | 174 (cache_dir, CACHED_ENTRIES)) |
167 if os.system(cmd) != 0: | 175 if os.system(cmd) != 0: |
168 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, | 176 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, |
169 'DEVSERVER') | 177 'DEVSERVER') |
170 sys.exit(1) | 178 sys.exit(1) |
171 | 179 |
172 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') | 180 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') |
173 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') | 181 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') |
174 | 182 |
175 updater = autoupdate.Autoupdate( | 183 updater = autoupdate.Autoupdate( |
176 root_dir=root_dir, | 184 root_dir=root_dir, |
177 static_dir=static_dir, | 185 static_dir=static_dir, |
178 serve_only=serve_only, | 186 serve_only=serve_only, |
179 urlbase=options.urlbase, | 187 urlbase=options.urlbase, |
180 test_image=options.test_image, | 188 test_image=options.test_image, |
181 factory_config_path=options.factory_config, | 189 factory_config_path=options.factory_config, |
182 client_prefix=options.client_prefix, | 190 client_prefix=options.client_prefix, |
183 forced_image=options.image, | 191 forced_image=options.image, |
192 forced_payload=options.payload, | |
184 port=options.port, | 193 port=options.port, |
185 src_image=options.src_image, | 194 src_image=options.src_image, |
186 vm=options.vm, | 195 vm=options.vm, |
187 board=options.board) | 196 board=options.board) |
188 | 197 |
189 # Sanity-check for use of validate_factory_config. | 198 # Sanity-check for use of validate_factory_config. |
190 if not options.factory_config and options.validate_factory_config: | 199 if not options.factory_config and options.validate_factory_config: |
191 parser.error('You need a factory_config to validate.') | 200 parser.error('You need a factory_config to validate.') |
192 | 201 |
193 if options.factory_config: | 202 if options.factory_config: |
194 updater.ImportFactoryConfigFile(options.factory_config, | 203 updater.ImportFactoryConfigFile(options.factory_config, |
195 options.validate_factory_config) | 204 options.validate_factory_config) |
196 # We don't run the dev server with this option. | 205 # We don't run the dev server with this option. |
197 if options.validate_factory_config: | 206 if options.validate_factory_config: |
198 sys.exit(0) | 207 sys.exit(0) |
199 elif options.pregenerate_update: | 208 elif options.pregenerate_update: |
200 if not updater.PreGenerateUpdate(): | 209 if not updater.PreGenerateUpdate(): |
201 sys.exit(1) | 210 sys.exit(1) |
202 | 211 |
212 # If the command line requested after setup, it's time to do it. | |
213 if options.exit: | |
sosa
2010/11/18 01:47:43
if not options.exit start dev server
| |
214 sys.exit(0) | |
215 | |
203 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) | 216 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |
OLD | NEW |