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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 index.exposed = True | 106 index.exposed = True |
107 | 107 |
108 | 108 |
109 if __name__ == '__main__': | 109 if __name__ == '__main__': |
110 usage = 'usage: %prog [options]' | 110 usage = 'usage: %prog [options]' |
111 parser = optparse.OptionParser(usage) | 111 parser = optparse.OptionParser(usage) |
112 parser.add_option('--archive_dir', dest='archive_dir', | 112 parser.add_option('--archive_dir', dest='archive_dir', |
113 help='serve archived builds only.') | 113 help='serve archived builds only.') |
114 parser.add_option('--board', dest='board', | 114 parser.add_option('--board', dest='board', |
115 help='When pre-generating update, board for latest image.') | 115 help='When pre-generating update, board for latest image.') |
| 116 parser.add_option('--clear_cache', action="store_true", default=False, |
| 117 help='Clear out all cached deltas and exit') |
116 parser.add_option('--client_prefix', dest='client_prefix', | 118 parser.add_option('--client_prefix', dest='client_prefix', |
117 help='Required prefix for client software version.', | 119 help='Required prefix for client software version.', |
118 default='MementoSoftwareUpdate') | 120 default='MementoSoftwareUpdate') |
119 parser.add_option('--factory_config', dest='factory_config', | 121 parser.add_option('--factory_config', dest='factory_config', |
120 help='Config file for serving images from factory floor.') | 122 help='Config file for serving images from factory floor.') |
121 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', | 123 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', |
122 help='Update is for a vm image.') | 124 help='Update is for a vm image.') |
123 parser.add_option('--image', dest='image', | 125 parser.add_option('--image', dest='image', |
124 help='Force update using this image.') | 126 help='Force update using this image.') |
125 parser.add_option('-p', '--pregenerate_update', action='store_true', | 127 parser.add_option('-p', '--pregenerate_update', action='store_true', |
(...skipping 18 matching lines...) Expand all Loading... |
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 |
| 159 if options.clear_cache: |
| 160 # Clear the cache and exit |
| 161 sys.exit(os.system('sudo rm -rf %s' % cache_dir)) |
| 162 |
| 163 if os.path.exists(cache_dir): |
| 164 # Clear all but the last 12 cached deltas |
| 165 cmd = 'cd %s; ls -1tr | head --lines=-12 | xargs rm -rf' % cache_dir |
| 166 if os.system(cmd) != 0: |
| 167 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, |
| 168 'DEVSERVER') |
| 169 sys.exit(1) |
| 170 |
154 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') | 171 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') |
155 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') | 172 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') |
156 | 173 |
157 updater = autoupdate.Autoupdate( | 174 updater = autoupdate.Autoupdate( |
158 root_dir=root_dir, | 175 root_dir=root_dir, |
159 static_dir=static_dir, | 176 static_dir=static_dir, |
160 serve_only=serve_only, | 177 serve_only=serve_only, |
161 urlbase=options.urlbase, | 178 urlbase=options.urlbase, |
162 test_image=options.test_image, | 179 test_image=options.test_image, |
163 factory_config_path=options.factory_config, | 180 factory_config_path=options.factory_config, |
(...skipping 13 matching lines...) Expand all Loading... |
177 updater.ImportFactoryConfigFile(options.factory_config, | 194 updater.ImportFactoryConfigFile(options.factory_config, |
178 options.validate_factory_config) | 195 options.validate_factory_config) |
179 # We don't run the dev server with this option. | 196 # We don't run the dev server with this option. |
180 if options.validate_factory_config: | 197 if options.validate_factory_config: |
181 sys.exit(0) | 198 sys.exit(0) |
182 elif options.pregenerate_update: | 199 elif options.pregenerate_update: |
183 if not updater.PreGenerateUpdate(): | 200 if not updater.PreGenerateUpdate(): |
184 sys.exit(1) | 201 sys.exit(1) |
185 | 202 |
186 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) | 203 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) |
OLD | NEW |