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

Side by Side Diff: devserver.py

Issue 6508001: devserver: introduce --datadir option to override where devserver puts static (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/dev-util.git@master
Patch Set: Fixes Created 9 years, 10 months 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 | « no previous file | devserver_test.py » ('j') | 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
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 parser = optparse.OptionParser(usage) 114 parser = optparse.OptionParser(usage)
115 parser.add_option('--archive_dir', dest='archive_dir', 115 parser.add_option('--archive_dir', dest='archive_dir',
116 help='serve archived builds only.') 116 help='serve archived builds only.')
117 parser.add_option('--board', dest='board', 117 parser.add_option('--board', dest='board',
118 help='When pre-generating update, board for latest image.') 118 help='When pre-generating update, board for latest image.')
119 parser.add_option('--clear_cache', action='store_true', default=False, 119 parser.add_option('--clear_cache', action='store_true', default=False,
120 help='Clear out all cached udpates and exit') 120 help='Clear out all cached udpates and exit')
121 parser.add_option('--client_prefix', dest='client_prefix', 121 parser.add_option('--client_prefix', dest='client_prefix',
122 help='Required prefix for client software version.', 122 help='Required prefix for client software version.',
123 default='MementoSoftwareUpdate') 123 default='MementoSoftwareUpdate')
124 parser.add_option('--data_dir', dest='data_dir',
125 help='Writable directory where static lives',
126 default=os.path.dirname(os.path.abspath(sys.argv[0])))
124 parser.add_option('--exit', action='store_true', default=False, 127 parser.add_option('--exit', action='store_true', default=False,
125 help='Don\'t start the server (still pregenerate or clear' 128 help='Don\'t start the server (still pregenerate or clear'
126 'cache).') 129 'cache).')
127 parser.add_option('--factory_config', dest='factory_config', 130 parser.add_option('--factory_config', dest='factory_config',
128 help='Config file for serving images from factory floor.') 131 help='Config file for serving images from factory floor.')
129 parser.add_option('--for_vm', dest='vm', default=False, action='store_true', 132 parser.add_option('--for_vm', dest='vm', default=False, action='store_true',
130 help='Update is for a vm image.') 133 help='Update is for a vm image.')
131 parser.add_option('--image', dest='image', 134 parser.add_option('--image', dest='image',
132 help='Force update using this image.') 135 help='Force update using this image.')
133 parser.add_option('-p', '--pregenerate_update', action='store_true', 136 parser.add_option('-p', '--pregenerate_update', action='store_true',
(...skipping 19 matching lines...) Expand all
153 156
154 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 157 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
155 root_dir = os.path.realpath('%s/../..' % devserver_dir) 158 root_dir = os.path.realpath('%s/../..' % devserver_dir)
156 serve_only = False 159 serve_only = False
157 160
158 if options.archive_dir: 161 if options.archive_dir:
159 static_dir = os.path.realpath(options.archive_dir) 162 static_dir = os.path.realpath(options.archive_dir)
160 _PrepareToServeUpdatesOnly(static_dir) 163 _PrepareToServeUpdatesOnly(static_dir)
161 serve_only = True 164 serve_only = True
162 else: 165 else:
163 static_dir = os.path.realpath('%s/static' % devserver_dir) 166 static_dir = os.path.realpath('%s/static' % options.data_dir)
164 os.system('mkdir -p %s' % static_dir) 167 os.system('mkdir -p %s' % static_dir)
165 168
166 cache_dir = os.path.join(static_dir, 'cache') 169 cache_dir = os.path.join(static_dir, 'cache')
167 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') 170 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER')
168 171
169 if os.path.exists(cache_dir): 172 if os.path.exists(cache_dir):
170 if options.clear_cache: 173 if options.clear_cache:
171 # Clear the cache and exit on error. 174 # Clear the cache and exit on error.
172 if os.system('rm -rf %s/*' % cache_dir) != 0: 175 if os.system('rm -rf %s/*' % cache_dir) != 0:
173 cherrypy.log('Failed to clear the cache with %s' % cmd, 176 cherrypy.log('Failed to clear the cache with %s' % cmd,
174 'DEVSERVER') 177 'DEVSERVER')
175 sys.exit(1) 178 sys.exit(1)
176 179
177 else: 180 else:
178 # Clear all but the last N cached updates 181 # Clear all but the last N cached updates
179 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' % 182 cmd = ('cd %s; ls -tr | head --lines=-%d | xargs rm -rf' %
180 (cache_dir, CACHED_ENTRIES)) 183 (cache_dir, CACHED_ENTRIES))
181 if os.system(cmd) != 0: 184 if os.system(cmd) != 0:
182 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd, 185 cherrypy.log('Failed to clean up old delta cache files with %s' % cmd,
183 'DEVSERVER') 186 'DEVSERVER')
184 sys.exit(1) 187 sys.exit(1)
185 else: 188 else:
186 os.makedirs(cache_dir) 189 os.makedirs(cache_dir)
187 190
191 cherrypy.log('Data dir is %s' % options.data_dir, 'DEVSERVER')
188 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER') 192 cherrypy.log('Source root is %s' % root_dir, 'DEVSERVER')
189 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER') 193 cherrypy.log('Serving from %s' % static_dir, 'DEVSERVER')
190 194
191 updater = autoupdate.Autoupdate( 195 updater = autoupdate.Autoupdate(
192 root_dir=root_dir, 196 root_dir=root_dir,
193 static_dir=static_dir, 197 static_dir=static_dir,
194 serve_only=serve_only, 198 serve_only=serve_only,
195 urlbase=options.urlbase, 199 urlbase=options.urlbase,
196 test_image=options.test_image, 200 test_image=options.test_image,
197 factory_config_path=options.factory_config, 201 factory_config_path=options.factory_config,
(...skipping 17 matching lines...) Expand all
215 # We don't run the dev server with this option. 219 # We don't run the dev server with this option.
216 if options.validate_factory_config: 220 if options.validate_factory_config:
217 sys.exit(0) 221 sys.exit(0)
218 elif options.pregenerate_update: 222 elif options.pregenerate_update:
219 if not updater.PreGenerateUpdate(): 223 if not updater.PreGenerateUpdate():
220 sys.exit(1) 224 sys.exit(1)
221 225
222 # If the command line requested after setup, it's time to do it. 226 # If the command line requested after setup, it's time to do it.
223 if not options.exit: 227 if not options.exit:
224 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) 228 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))
OLDNEW
« no previous file with comments | « no previous file | devserver_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698