OLD | NEW |
1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import autoupdate | 5 import autoupdate |
| 6 import buildutil |
| 7 import optparse |
6 import os | 8 import os |
| 9 import SimpleHTTPServer |
7 import web | 10 import web |
8 import sys | 11 import sys |
9 | 12 |
10 global updater | 13 global updater |
11 updater = None | 14 updater = None |
12 | 15 |
13 global buildbot | 16 global buildbot |
14 buildbot = None | 17 buildbot = None |
15 | 18 |
16 class index: | 19 class index: |
17 def GET(self): | 20 def GET(self): |
18 pkgs = buildbot.GetPackages() | 21 pkgs = buildbot.GetPackages() |
19 return render.index(pkgs) | 22 return render.index(pkgs) |
20 | 23 |
21 class update: | 24 class update: |
22 """ | 25 """ |
23 Processes updates from the client machine. If an update is found, the url | 26 Processes updates from the client machine. If an update is found, the url |
24 references a static link that can be served automagically from web.py. | 27 references a static link that can be served automagically from web.py. |
25 """ | 28 """ |
26 def POST(self): | 29 def POST(self, args=None): |
27 return updater.HandleUpdatePing(web.data()) | 30 return updater.HandleUpdatePing(web.data(), args) |
28 | 31 |
29 class build: | 32 class build: |
30 """ | 33 """ |
31 builds the package specified by the pkg parameter and returns the name | 34 builds the package specified by the pkg parameter and returns the name |
32 of the output file. | 35 of the output file. |
33 """ | 36 """ |
34 def POST(self): | 37 def POST(self): |
35 input = web.input() | 38 input = web.input() |
36 web.debug("emerging %s " % input.pkg) | 39 web.debug('emerging %s ' % input.pkg) |
37 emerge_command = "emerge-%s %s" % (input.board, input.pkg) | 40 emerge_command = 'emerge-%s %s' % (input.board, input.pkg) |
38 err = os.system(emerge_command) | 41 err = os.system(emerge_command) |
39 if err != 0: | 42 if err != 0: |
40 raise Exception("failed to execute %s" % emerge_command) | 43 raise Exception('failed to execute %s' % emerge_command) |
41 | 44 |
42 if __name__ == "__main__": | 45 if __name__ == '__main__': |
| 46 usage = 'usage: %prog [options]' |
| 47 parser = optparse.OptionParser(usage) |
| 48 parser.add_option('-a', '--archive_dir', dest='archive_dir', |
| 49 help='serve archived builds only.') |
| 50 parser.add_option("-t", action="store_true", dest="test_image") |
| 51 options, args = parser.parse_args() |
| 52 # clean up the args, due to httpserver's hardcoded use of sys.argv |
| 53 if options.archive_dir: |
| 54 sys.argv.remove('-a') |
| 55 sys.argv.remove(options.archive_dir) |
| 56 if options.test_image: |
| 57 sys.argv.remove('-t') |
43 | 58 |
44 root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.a
rgv[0]))) | |
45 static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sy
s.argv[0]))) | |
46 web.debug("dev root is %s" % root_dir) | |
47 web.debug("Serving images from %s" % static_dir) | |
48 os.system("mkdir -p %s" % static_dir) | |
49 | 59 |
50 updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir) | 60 root_dir = os.path.realpath('%s/../..' % |
| 61 os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 62 if options.archive_dir: |
| 63 static_dir = os.path.realpath(options.archive_dir) |
| 64 assert os.path.exists(static_dir), '%s must exist.' % options.archive_dir |
| 65 web.debug('using archive dir: %s' % static_dir) |
| 66 else: |
| 67 static_dir = os.path.realpath('%s/static' % |
| 68 os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 69 web.debug('dev root is %s' % root_dir) |
| 70 os.system('mkdir -p %s' % static_dir) |
| 71 web.debug('Serving images from %s' % static_dir) |
51 | 72 |
| 73 updater = autoupdate.Autoupdate(root_dir=root_dir, |
| 74 static_dir=static_dir, |
| 75 serve_only=options.archive_dir, |
| 76 test_image=options.test_image) |
52 urls = ('/', 'index', | 77 urls = ('/', 'index', |
53 '/update', 'update', | 78 '/update', 'update', |
| 79 '/update/(.+)', 'update', |
54 '/webbuild', 'webbuild', | 80 '/webbuild', 'webbuild', |
55 '/build', 'build') | 81 '/build', 'build') |
56 | 82 |
57 app = web.application(urls, globals()) | 83 app = web.application(urls, globals(), autoreload=True) |
58 render = web.template.render('templates/') | 84 render = web.template.render('templates/') |
59 | |
60 app.run() | 85 app.run() |
OLD | NEW |