Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: devserver.py

Issue 4906001: Reworked devserver so that update images generated are cached in directories named after (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/dev-util.git@master
Patch Set: Revised based on comments. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « autoupdate_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 sys 12 import sys
13 13
14 import autoupdate 14 import autoupdate
15 15
16 CACHED_ENTRIES=12
17
16 # Sets up global to share between classes. 18 # Sets up global to share between classes.
17 global updater 19 global updater
18 updater = None 20 updater = None
19 21
20 def _GetConfig(options): 22 def _GetConfig(options):
21 """Returns the configuration for the devserver.""" 23 """Returns the configuration for the devserver."""
22 base_config = { 'global': 24 base_config = { 'global':
23 { 'server.log_request_headers': True, 25 { 'server.log_request_headers': True,
24 'server.protocol_version': 'HTTP/1.1', 26 'server.protocol_version': 'HTTP/1.1',
25 'server.socket_host': '0.0.0.0', 27 'server.socket_host': '0.0.0.0',
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 index.exposed = True 108 index.exposed = True
107 109
108 110
109 if __name__ == '__main__': 111 if __name__ == '__main__':
110 usage = 'usage: %prog [options]' 112 usage = 'usage: %prog [options]'
111 parser = optparse.OptionParser(usage) 113 parser = optparse.OptionParser(usage)
112 parser.add_option('--archive_dir', dest='archive_dir', 114 parser.add_option('--archive_dir', dest='archive_dir',
113 help='serve archived builds only.') 115 help='serve archived builds only.')
114 parser.add_option('--board', dest='board', 116 parser.add_option('--board', dest='board',
115 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,
119 help='Clear out all cached udpates and exit')
116 parser.add_option('--client_prefix', dest='client_prefix', 120 parser.add_option('--client_prefix', dest='client_prefix',
117 help='Required prefix for client software version.', 121 help='Required prefix for client software version.',
118 default='MementoSoftwareUpdate') 122 default='MementoSoftwareUpdate')
119 parser.add_option('--factory_config', dest='factory_config', 123 parser.add_option('--factory_config', dest='factory_config',
120 help='Config file for serving images from factory floor.') 124 help='Config file for serving images from factory floor.')
121 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', 125 parser.add_option('--for_vm', dest='vm', default=False, action='store_true',
122 help='Update is for a vm image.') 126 help='Update is for a vm image.')
123 parser.add_option('--image', dest='image', 127 parser.add_option('--image', dest='image',
124 help='Force update using this image.') 128 help='Force update using this image.')
125 parser.add_option('-p', '--pregenerate_update', action='store_true', 129 parser.add_option('-p', '--pregenerate_update', action='store_true',
126 default=False, help='Pre-generate update payload.') 130 default=False, help='Pre-generate update payload.')
127 parser.add_option('--port', default=8080, 131 parser.add_option('--port', default=8080,
128 help='Port for the dev server to use.') 132 help='Port for the dev server to use.')
129 parser.add_option('--src_image', default='', 133 parser.add_option('--src_image', default='',
130 help='Image on remote machine for generating delta update.') 134 help='Image on remote machine for generating delta update.')
131 parser.add_option('-t', action='store_true', dest='test_image') 135 parser.add_option('-t', action='store_true', dest='test_image')
132 parser.add_option('-u', '--urlbase', dest='urlbase', 136 parser.add_option('-u', '--urlbase', dest='urlbase',
133 help='base URL, other than devserver, for update images.') 137 help='base URL, other than devserver, for update images.')
134 parser.add_option('--use_cached', action="store_true", default=False,
135 help='Prefer cached image regardless of timestamps.')
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
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 N cached updates
165 cmd = ('cd %s; ls -1tr | head --lines=-%d | xargs rm -rf' %
166 (cache_dir, CACHED_ENTRIES))
167 if os.system(cmd) != 0:
168 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd,
169 'DEVSERVER')
170 sys.exit(1)
171
154 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') 172 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER')
155 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') 173 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER')
156 174
157 updater = autoupdate.Autoupdate( 175 updater = autoupdate.Autoupdate(
158 root_dir=root_dir, 176 root_dir=root_dir,
159 static_dir=static_dir, 177 static_dir=static_dir,
160 serve_only=serve_only, 178 serve_only=serve_only,
161 urlbase=options.urlbase, 179 urlbase=options.urlbase,
162 test_image=options.test_image, 180 test_image=options.test_image,
163 factory_config_path=options.factory_config, 181 factory_config_path=options.factory_config,
164 client_prefix=options.client_prefix, 182 client_prefix=options.client_prefix,
165 forced_image=options.image, 183 forced_image=options.image,
166 use_cached=options.use_cached,
167 port=options.port, 184 port=options.port,
168 src_image=options.src_image, 185 src_image=options.src_image,
169 vm=options.vm, 186 vm=options.vm,
170 board=options.board) 187 board=options.board)
171 188
172 # Sanity-check for use of validate_factory_config. 189 # Sanity-check for use of validate_factory_config.
173 if not options.factory_config and options.validate_factory_config: 190 if not options.factory_config and options.validate_factory_config:
174 parser.error('You need a factory_config to validate.') 191 parser.error('You need a factory_config to validate.')
175 192
176 if options.factory_config: 193 if options.factory_config:
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))
OLDNEW
« no previous file with comments | « autoupdate_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698