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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 static_dir = os.path.realpath(options.archive_dir) | 158 static_dir = os.path.realpath(options.archive_dir) |
159 _PrepareToServeUpdatesOnly(static_dir) | 159 _PrepareToServeUpdatesOnly(static_dir) |
160 serve_only = True | 160 serve_only = True |
161 else: | 161 else: |
162 static_dir = os.path.realpath('%s/static' % devserver_dir) | 162 static_dir = os.path.realpath('%s/static' % devserver_dir) |
163 os.system('mkdir -p %s' % static_dir) | 163 os.system('mkdir -p %s' % static_dir) |
164 | 164 |
165 cache_dir = os.path.join(static_dir, 'cache') | 165 cache_dir = os.path.join(static_dir, 'cache') |
166 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') | 166 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') |
167 | 167 |
168 if options.clear_cache: | 168 if os.path.exists(cache_dir): |
169 # Clear the cache and exit on error | 169 if options.clear_cache: |
170 if os.system('sudo rm -rf %s' % cache_dir) != 0: | 170 # Clear the cache and exit on error. |
171 cherrypy.log('Failed to clear the cache with %s' % cmd, | 171 if os.system('rm -rf %s/*' % cache_dir) != 0: |
172 'DEVSERVER') | 172 cherrypy.log('Failed to clear the cache with %s' % cmd, |
173 sys.exit(1) | 173 'DEVSERVER') |
| 174 sys.exit(1) |
174 | 175 |
175 if os.path.exists(cache_dir): | 176 else: |
176 # Clear all but the last N cached updates | 177 # Clear all but the last N cached updates |
177 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' % | 178 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' % |
178 (cache_dir, CACHED_ENTRIES)) | 179 (cache_dir, CACHED_ENTRIES)) |
179 if os.system(cmd) != 0: | 180 if os.system(cmd) != 0: |
180 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, | 181 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, |
181 'DEVSERVER') | 182 'DEVSERVER') |
182 sys.exit(1) | 183 sys.exit(1) |
| 184 else: |
| 185 os.makedirs(cache_dir) |
183 | 186 |
184 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') | 187 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') |
185 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') | 188 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') |
186 | 189 |
187 updater = autoupdate.Autoupdate( | 190 updater = autoupdate.Autoupdate( |
188 root_dir=root_dir, | 191 root_dir=root_dir, |
189 static_dir=static_dir, | 192 static_dir=static_dir, |
190 serve_only=serve_only, | 193 serve_only=serve_only, |
191 urlbase=options.urlbase, | 194 urlbase=options.urlbase, |
192 test_image=options.test_image, | 195 test_image=options.test_image, |
(...skipping 18 matching lines...) Expand all Loading... |
211 # We don't run the dev server with this option. | 214 # We don't run the dev server with this option. |
212 if options.validate_factory_config: | 215 if options.validate_factory_config: |
213 sys.exit(0) | 216 sys.exit(0) |
214 elif options.pregenerate_update: | 217 elif options.pregenerate_update: |
215 if not updater.PreGenerateUpdate(): | 218 if not updater.PreGenerateUpdate(): |
216 sys.exit(1) | 219 sys.exit(1) |
217 | 220 |
218 # If the command line requested after setup, it's time to do it. | 221 # If the command line requested after setup, it's time to do it. |
219 if not options.exit: | 222 if not options.exit: |
220 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) | 223 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |
OLD | NEW |