rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 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 |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import autoupdate |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 6 | import buildutil |
| 7 | import optparse |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 8 | import os |
chocobo@google.com | 4dc2581 | 2009-10-27 23:46:26 +0000 | [diff] [blame] | 9 | import sys |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 10 | import web |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 11 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 12 | global updater |
| 13 | updater = None |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 14 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 15 | global buildbot |
| 16 | buildbot = None |
| 17 | |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 18 | class index: |
| 19 | def GET(self): |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 20 | pkgs = buildbot.GetPackages() |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 21 | return render.index(pkgs) |
| 22 | |
| 23 | class update: |
| 24 | """ |
| 25 | Processes updates from the client machine. If an update is found, the url |
| 26 | references a static link that can be served automagically from web.py. |
| 27 | """ |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 28 | def POST(self, args=None): |
| 29 | return updater.HandleUpdatePing(web.data(), args) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 30 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 31 | class build: |
| 32 | """ |
| 33 | builds the package specified by the pkg parameter and returns the name |
| 34 | of the output file. |
| 35 | """ |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 36 | def POST(self): |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 37 | input = web.input() |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 38 | web.debug('emerging %s ' % input.pkg) |
| 39 | emerge_command = 'emerge-%s %s' % (input.board, input.pkg) |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 40 | err = os.system(emerge_command) |
| 41 | if err != 0: |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 42 | raise Exception('failed to execute %s' % emerge_command) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 43 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 44 | if __name__ == '__main__': |
| 45 | usage = 'usage: %prog [options]' |
| 46 | parser = optparse.OptionParser(usage) |
Sean O'Connor | e38ea15 | 2010-04-16 13:50:40 -0700 | [diff] [blame] | 47 | parser.add_option('--archive_dir', dest='archive_dir', |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 48 | help='serve archived builds only.') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 49 | parser.add_option('--factory_config', dest='factory_config', |
| 50 | help='Config file for serving images from factory floor.') |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 51 | parser.add_option('-t', action='store_true', dest='test_image') |
| 52 | parser.add_option('-u', '--urlbase', dest='urlbase', |
| 53 | help='base URL, other than devserver, for update images.') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 54 | parser.add_option('--validate_factory_config', action="store_true", |
| 55 | dest='validate_factory_config', |
| 56 | help='Validate factory config file, then exit.') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 57 | options, args = parser.parse_args() |
| 58 | # clean up the args, due to httpserver's hardcoded use of sys.argv |
| 59 | if options.archive_dir: |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 60 | sys.argv.remove('--archive_dir') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 61 | sys.argv.remove(options.archive_dir) |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 62 | if options.factory_config: |
| 63 | sys.argv.remove('--factory_config') |
| 64 | sys.argv.remove(options.factory_config) |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 65 | if options.test_image: |
| 66 | sys.argv.remove('-t') |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 67 | if options.urlbase: |
| 68 | sys.argv.remove('-u') |
| 69 | sys.argv.remove(options.urlbase) |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 70 | if options.validate_factory_config: |
| 71 | sys.argv.remove('--validate_factory_config') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 72 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 73 | root_dir = os.path.realpath('%s/../..' % |
| 74 | os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 75 | if options.archive_dir: |
| 76 | static_dir = os.path.realpath(options.archive_dir) |
| 77 | assert os.path.exists(static_dir), '%s must exist.' % options.archive_dir |
| 78 | web.debug('using archive dir: %s' % static_dir) |
| 79 | else: |
| 80 | static_dir = os.path.realpath('%s/static' % |
| 81 | os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 82 | web.debug('dev root is %s' % root_dir) |
| 83 | os.system('mkdir -p %s' % static_dir) |
| 84 | web.debug('Serving images from %s' % static_dir) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 85 | |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 86 | updater = autoupdate.Autoupdate( |
| 87 | root_dir=root_dir, |
| 88 | static_dir=static_dir, |
| 89 | serve_only=options.archive_dir, |
| 90 | urlbase=options.urlbase, |
| 91 | test_image=options.test_image, |
| 92 | factory_config_path=options.factory_config, |
| 93 | validate_factory_config=options.validate_factory_config) |
| 94 | if options.validate_factory_config: |
| 95 | sys.exit(0) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 96 | urls = ('/', 'index', |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 97 | '/update', 'update', |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 98 | '/update/(.+)', 'update', |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 99 | '/webbuild', 'webbuild', |
| 100 | '/build', 'build') |
| 101 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 102 | app = web.application(urls, globals(), autoreload=True) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 103 | render = web.template.render('templates/') |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 104 | app.run() |