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

Side by Side Diff: devserver.py

Issue 6305004: Modify devserver and gmerge to be friendlier (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/dev-util.git@master
Patch Set: Numerous code review fixes. Added --USE flag as well Created 9 years, 11 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 | « builder_test.py ('k') | gmerge » ('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
11 import os 11 import os
12 import subprocess
12 import sys 13 import sys
13 14
14 import autoupdate 15 import autoupdate
16 import builder
15 17
16 CACHED_ENTRIES=12 18 CACHED_ENTRIES=12
17 19
18 # Sets up global to share between classes. 20 # Sets up global to share between classes.
19 global updater 21 global updater
20 updater = None 22 updater = None
21 23
22 def _GetConfig(options): 24 def _GetConfig(options):
23 """Returns the configuration for the devserver.""" 25 """Returns the configuration for the devserver."""
24 base_config = { 'global': 26 base_config = { 'global':
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if image_dir != os.readlink('static/archive'): 64 if image_dir != os.readlink('static/archive'):
63 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER') 65 cherrypy.log('removing stale symlink to %s' % image_dir, 'DEVSERVER')
64 os.unlink('static/archive') 66 os.unlink('static/archive')
65 os.symlink(image_dir, 'static/archive') 67 os.symlink(image_dir, 'static/archive')
66 else: 68 else:
67 os.symlink(image_dir, 'static/archive') 69 os.symlink(image_dir, 'static/archive')
68 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir, 70 cherrypy.log('archive dir: %s ready to be used to serve images.' % image_dir,
69 'DEVSERVER') 71 'DEVSERVER')
70 72
71 73
72 class DevServerRoot: 74 class DevServerRoot(object):
73 """The Root Class for the Dev Server. 75 """The Root Class for the Dev Server.
74 76
75 CherryPy works as follows: 77 CherryPy works as follows:
76 For each method in this class, cherrpy interprets root/path 78 For each method in this class, cherrpy interprets root/path
77 as a call to an instance of DevServerRoot->method_name. For example, 79 as a call to an instance of DevServerRoot->method_name. For example,
78 a call to http://myhost/build will call build. CherryPy automatically 80 a call to http://myhost/build will call build. CherryPy automatically
79 parses http args and places them as keyword arguments in each method. 81 parses http args and places them as keyword arguments in each method.
80 For paths http://myhost/update/dir1/dir2, you can use *args so that 82 For paths http://myhost/update/dir1/dir2, you can use *args so that
81 cherrypy uses the update method and puts the extra paths in args. 83 cherrypy uses the update method and puts the extra paths in args.
82 """ 84 """
83 85
84 def build(self, board, pkg): 86 def __init__(self):
87 self._builder = builder.Builder()
88
89 def build(self, board, pkg, **kwargs):
85 """Builds the package specified.""" 90 """Builds the package specified."""
86 cherrypy.log('emerging %s' % pkg, 'BUILD') 91 return self._builder.Build(board, pkg, kwargs)
87 emerge_command = 'emerge-%s %s' % (board, pkg)
88 err = os.system(emerge_command)
89 if err != 0:
90 raise Exception('failed to execute %s' % emerge_command)
91 eclean_command = 'eclean-%s -d packages' % board
92 err = os.system(eclean_command)
93 if err != 0:
94 raise Exception('failed to execute %s' % emerge_command)
95 92
96 def index(self): 93 def index(self):
97 return 'Welcome to the Dev Server!' 94 return 'Welcome to the Dev Server!'
98 95
99 def update(self, *args): 96 def update(self, *args):
100 label = '/'.join(args) 97 label = '/'.join(args)
101 body_length = int(cherrypy.request.headers['Content-Length']) 98 body_length = int(cherrypy.request.headers['Content-Length'])
102 data = cherrypy.request.rfile.read(body_length) 99 data = cherrypy.request.rfile.read(body_length)
103 return updater.HandleUpdatePing(data, label) 100 return updater.HandleUpdatePing(data, label)
104 101
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 # We don't run the dev server with this option. 205 # We don't run the dev server with this option.
209 if options.validate_factory_config: 206 if options.validate_factory_config:
210 sys.exit(0) 207 sys.exit(0)
211 elif options.pregenerate_update: 208 elif options.pregenerate_update:
212 if not updater.PreGenerateUpdate(): 209 if not updater.PreGenerateUpdate():
213 sys.exit(1) 210 sys.exit(1)
214 211
215 # If the command line requested after setup, it's time to do it. 212 # If the command line requested after setup, it's time to do it.
216 if not options.exit: 213 if not options.exit:
217 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options)) 214 cherrypy.quickstart(DevServerRoot(), config=_GetConfig(options))
OLDNEW
« no previous file with comments | « builder_test.py ('k') | gmerge » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698