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