[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 |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 6 | import os |
| 7 | import web |
[email protected] | 4dc2581 | 2009-10-27 23:46:26 | [diff] [blame] | 8 | import sys |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 9 | |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 10 | global updater |
| 11 | updater = None |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 12 | |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 13 | global buildbot |
| 14 | buildbot = None |
| 15 | |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 16 | class index: |
| 17 | def GET(self): |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 18 | pkgs = buildbot.GetPackages() |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 19 | return render.index(pkgs) |
| 20 | |
| 21 | class update: |
| 22 | """ |
| 23 | 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. |
| 25 | """ |
| 26 | def POST(self): |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 27 | return updater.HandleUpdatePing(web.data()) |
| 28 | |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 29 | class build: |
| 30 | """ |
| 31 | builds the package specified by the pkg parameter and returns the name |
| 32 | of the output file. |
| 33 | """ |
Ryan Cairns | dd1ceb8 | 2010-03-03 05:35:01 | [diff] [blame^] | 34 | def POST(self): |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 35 | input = web.input() |
Ryan Cairns | dd1ceb8 | 2010-03-03 05:35:01 | [diff] [blame^] | 36 | web.debug("emerging %s " % input.pkg) |
| 37 | emerge_command = "emerge-%s %s" % (input.board, input.pkg) |
| 38 | err = os.system(emerge_command) |
| 39 | if err != 0: |
| 40 | raise Exception("failed to execute %s" % emerge_command) |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 41 | |
[email protected] | 4dc2581 | 2009-10-27 23:46:26 | [diff] [blame] | 42 | if __name__ == "__main__": |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 43 | |
| 44 | root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.argv[0]))) |
[email protected] | 47660d8 | 2009-10-28 23:11:51 | [diff] [blame] | 45 | static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sys.argv[0]))) |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 46 | web.debug("dev root is %s" % root_dir) |
[email protected] | 4dc2581 | 2009-10-27 23:46:26 | [diff] [blame] | 47 | web.debug("Serving images from %s" % static_dir) |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 48 | os.system("mkdir -p %s" % static_dir) |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 49 | |
| 50 | updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir) |
| 51 | |
| 52 | urls = ('/', 'index', |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 53 | '/update', 'update', |
| 54 | '/webbuild', 'webbuild', |
| 55 | '/build', 'build') |
| 56 | |
[email protected] | 21a5ca3 | 2009-11-04 18:23:23 | [diff] [blame] | 57 | app = web.application(urls, globals()) |
| 58 | render = web.template.render('templates/') |
| 59 | |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 60 | app.run() |