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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 default=False, help='Pre-generate update payload.') | 126 default=False, help='Pre-generate update payload.') |
127 parser.add_option('--port', default=8080, | 127 parser.add_option('--port', default=8080, |
128 help='Port for the dev server to use.') | 128 help='Port for the dev server to use.') |
129 parser.add_option('--src_image', default='', | 129 parser.add_option('--src_image', default='', |
130 help='Image on remote machine for generating delta update.') | 130 help='Image on remote machine for generating delta update.') |
131 parser.add_option('-t', action='store_true', dest='test_image') | 131 parser.add_option('-t', action='store_true', dest='test_image') |
132 parser.add_option('-u', '--urlbase', dest='urlbase', | 132 parser.add_option('-u', '--urlbase', dest='urlbase', |
133 help='base URL, other than devserver, for update images.') | 133 help='base URL, other than devserver, for update images.') |
134 parser.add_option('--use_cached', action="store_true", default=False, | 134 parser.add_option('--use_cached', action="store_true", default=False, |
135 help='Prefer cached image regardless of timestamps.') | 135 help='Prefer cached image regardless of timestamps.') |
136 parser.add_option('--clear_cache', action="store_true", default=False, | |
137 help='Clear out all cached deltas and exit') | |
sosa
2010/11/15 21:59:17
Just deltas?
| |
136 parser.add_option('--validate_factory_config', action="store_true", | 138 parser.add_option('--validate_factory_config', action="store_true", |
137 dest='validate_factory_config', | 139 dest='validate_factory_config', |
138 help='Validate factory config file, then exit.') | 140 help='Validate factory config file, then exit.') |
139 parser.set_usage(parser.format_help()) | 141 parser.set_usage(parser.format_help()) |
140 (options, _) = parser.parse_args() | 142 (options, _) = parser.parse_args() |
141 | 143 |
142 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | 144 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
143 root_dir = os.path.realpath('%s/../..' % devserver_dir) | 145 root_dir = os.path.realpath('%s/../..' % devserver_dir) |
144 serve_only = False | 146 serve_only = False |
145 | 147 |
146 if options.archive_dir: | 148 if options.archive_dir: |
147 static_dir = os.path.realpath(options.archive_dir) | 149 static_dir = os.path.realpath(options.archive_dir) |
148 _PrepareToServeUpdatesOnly(static_dir) | 150 _PrepareToServeUpdatesOnly(static_dir) |
149 serve_only = True | 151 serve_only = True |
150 else: | 152 else: |
151 static_dir = os.path.realpath('%s/static' % devserver_dir) | 153 static_dir = os.path.realpath('%s/static' % devserver_dir) |
152 os.system('mkdir -p %s' % static_dir) | 154 os.system('mkdir -p %s' % static_dir) |
153 | 155 |
156 cache_dir = os.path.join(static_dir, 'cache') | |
157 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') | |
158 if options.clear_cache: | |
159 # Clear the cache and exit | |
160 sys.exit(os.system('sudo rm -rf %s' % cache_dir)) | |
sosa
2010/11/15 21:59:17
Why not just clean and then startup?
dgarrett
2010/11/15 23:32:39
I wanted a way to clean and exit as well as clean
| |
161 else: | |
162 if os.path.exists(cache_dir): | |
163 # Clear all but the last 12 cached deltas | |
sosa
2010/11/15 21:59:17
Set as a module constant i.e. CACHED_ENTRIES=12
| |
164 cmd = 'cd %s; ls -1tr | head --lines=-12 | xargs rm -rf' % cache_dir | |
165 if os.system(cmd) != 0: | |
sosa
2010/11/15 21:59:17
Return return code?
dgarrett
2010/11/15 23:32:39
You can't since you aren't in a function. I wrote
| |
166 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, | |
167 'DEVSERVER') | |
168 sys.exit(1) | |
169 | |
154 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') | 170 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') |
155 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') | 171 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') |
156 | 172 |
157 updater = autoupdate.Autoupdate( | 173 updater = autoupdate.Autoupdate( |
158 root_dir=root_dir, | 174 root_dir=root_dir, |
159 static_dir=static_dir, | 175 static_dir=static_dir, |
160 serve_only=serve_only, | 176 serve_only=serve_only, |
161 urlbase=options.urlbase, | 177 urlbase=options.urlbase, |
162 test_image=options.test_image, | 178 test_image=options.test_image, |
163 factory_config_path=options.factory_config, | 179 factory_config_path=options.factory_config, |
(...skipping 13 matching lines...) Expand all Loading... | |
177 updater.ImportFactoryConfigFile(options.factory_config, | 193 updater.ImportFactoryConfigFile(options.factory_config, |
178 options.validate_factory_config) | 194 options.validate_factory_config) |
179 # We don't run the dev server with this option. | 195 # We don't run the dev server with this option. |
180 if options.validate_factory_config: | 196 if options.validate_factory_config: |
181 sys.exit(0) | 197 sys.exit(0) |
182 elif options.pregenerate_update: | 198 elif options.pregenerate_update: |
183 if not updater.PreGenerateUpdate(): | 199 if not updater.PreGenerateUpdate(): |
184 sys.exit(1) | 200 sys.exit(1) |
185 | 201 |
186 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) | 202 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |
OLD | NEW |