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

Side by Side Diff: devserver.py

Issue 6469046: devserver: better handling of archive directory (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/dev-util.git@master
Patch Set: omg 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 | 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
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 'tools.staticdir.on': True, 49 'tools.staticdir.on': True,
50 'response.timeout': 10000, 50 'response.timeout': 10000,
51 }, 51 },
52 } 52 }
53 if options.production: 53 if options.production:
54 base_config['global']['server.environment'] = 'production' 54 base_config['global']['server.environment'] = 'production'
55 55
56 return base_config 56 return base_config
57 57
58 58
59 def _PrepareToServeUpdatesOnly(image_dir): 59 def _PrepareToServeUpdatesOnly(image_dir, static_dir):
60 """Sets up symlink to image_dir for serving purposes.""" 60 """Sets up symlink to image_dir for serving purposes."""
61 assert os.path.exists(image_dir), '%s must exist.' % image_dir 61 assert os.path.exists(image_dir), '%s must exist.' % image_dir
62 # If we're serving out of an archived build dir (e.g. a 62 # If we're serving out of an archived build dir (e.g. a
63 # buildbot), prepare this webserver's magic 'static/' dir with a 63 # buildbot), prepare this webserver's magic 'static/' dir with a
64 # link to the build archive. 64 # link to the build archive.
65 cherrypy.log('Preparing autoupdate for "serve updates only" mode.', 65 cherrypy.log('Preparing autoupdate for "serve updates only" mode.',
66 'DEVSERVER') 66 'DEVSERVER')
67 if os.path.lexists('static/archive'): 67 if os.path.lexists('%s/archive' % static_dir):
68 if image_dir != os.readlink('static/archive'): 68 if image_dir != os.readlink('%s/archive' % static_dir):
69 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER') 69 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER')
70 os.unlink('static/archive') 70 os.unlink('%s/archive' % static_dir)
71 os.symlink(image_dir, 'static/archive') 71 os.symlink(image_dir, '%s/archive' % static_dir)
72 else: 72 else:
73 os.symlink(image_dir, 'static/archive') 73 os.symlink(image_dir, '%s/archive' % static_dir)
74 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir, 74 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir,
75 'DEVSERVER') 75 'DEVSERVER')
76 76
77 77
78 class DevServerRoot(object): 78 class DevServerRoot(object):
79 """The Root Class for the Dev Server. 79 """The Root Class for the Dev Server.
80 80
81 CherryPy works as follows: 81 CherryPy works as follows:
82 For each method in this class, cherrpy interprets root/path 82 For each method in this class, cherrpy interprets root/path
83 as a call to an instance of DevServerRoot->method_name. For example, 83 as a call to an instance of DevServerRoot->method_name. For example,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 parser.add_option('--validate_factory_config', action="store_true", 153 parser.add_option('--validate_factory_config', action="store_true",
154 dest='validate_factory_config', 154 dest='validate_factory_config',
155 help='Validate factory config file, then exit.') 155 help='Validate factory config file, then exit.')
156 parser.set_usage(parser.format_help()) 156 parser.set_usage(parser.format_help())
157 (options, _) = parser.parse_args() 157 (options, _) = parser.parse_args()
158 158
159 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 159 devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
160 root_dir = os.path.realpath('%s/../..' % devserver_dir) 160 root_dir = os.path.realpath('%s/../..' % devserver_dir)
161 serve_only = False 161 serve_only = False
162 162
163 static_dir = os.path.realpath('%s/static' % options.data_dir)
164 os.system('mkdir -p %s' % static_dir)
165
163 if options.archive_dir: 166 if options.archive_dir:
164 static_dir = os.path.realpath(options.archive_dir) 167 # TODO(zbehan) Remove legacy support:
165 _PrepareToServeUpdatesOnly(static_dir) 168 # archive_dir is the directory where static/archive will point.
169 # If this is an absolute path, all is fine. If someone calls this
170 # using a relative path, that is relative to src/platform/dev/.
171 # That use case is unmaintainable, but since applications use it
172 # with =./static, instead of a boolean flag, we'll make this relative
173 # to devserver_dir to keep these unbroken. For now.
174 archive_dir = options.archive_dir
175 if not os.path.isabs(archive_dir):
176 archive_dir = os.path.realpath(os.path.join(devserver_dir,archive_dir))
177 _PrepareToServeUpdatesOnly(archive_dir, static_dir)
166 serve_only = True 178 serve_only = True
167 else:
168 static_dir = os.path.realpath('%s/static' % options.data_dir)
169 os.system('mkdir -p %s' % static_dir)
170 179
171 cache_dir = os.path.join(static_dir, 'cache') 180 cache_dir = os.path.join(static_dir, 'cache')
172 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER') 181 cherrypy.log('Using cache directory %s' % cache_dir, 'DEVSERVER')
173 182
174 if os.path.exists(cache_dir): 183 if os.path.exists(cache_dir):
175 if options.clear_cache: 184 if options.clear_cache:
176 # Clear the cache and exit on error. 185 # Clear the cache and exit on error.
177 if os.system('rm -rf %s/*' % cache_dir) != 0: 186 if os.system('rm -rf %s/*' % cache_dir) != 0:
178 cherrypy.log('Failed to clear the cache with %s' % cmd, 187 cherrypy.log('Failed to clear the cache with %s' % cmd,
179 'DEVSERVER') 188 'DEVSERVER')
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 # We don't run the dev server with this option. 232 # We don't run the dev server with this option.
224 if options.validate_factory_config: 233 if options.validate_factory_config:
225 sys.exit(0) 234 sys.exit(0)
226 elif options.pregenerate_update: 235 elif options.pregenerate_update:
227 if not updater.PreGenerateUpdate(): 236 if not updater.PreGenerateUpdate():
228 sys.exit(1) 237 sys.exit(1)
229 238
230 # If the command line requested after setup, it's time to do it. 239 # If the command line requested after setup, it's time to do it.
231 if not options.exit: 240 if not options.exit:
232 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) 241 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698