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 |
| 6 | import buildutil |
| 7 | import os |
| 8 | import web |
chocobo@google.com | 4dc2581 | 2009-10-27 23:46:26 +0000 | [diff] [blame] | 9 | import sys |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 10 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 11 | global updater |
| 12 | updater = None |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 13 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 14 | global buildbot |
| 15 | buildbot = None |
| 16 | |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 17 | class index: |
| 18 | def GET(self): |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 19 | pkgs = buildbot.GetPackages() |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 20 | return render.index(pkgs) |
| 21 | |
| 22 | class update: |
| 23 | """ |
| 24 | Processes updates from the client machine. If an update is found, the url |
| 25 | references a static link that can be served automagically from web.py. |
| 26 | """ |
| 27 | def POST(self): |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 28 | return updater.HandleUpdatePing(web.data()) |
| 29 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 30 | class webbuild: |
| 31 | """ |
| 32 | builds the package specified by the pkg parameter. Then redirects to index |
| 33 | """ |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 34 | def GET(self): |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 35 | input = web.input() |
| 36 | web.debug("called %s " % input.pkg) |
| 37 | output = buildbot.BuildPackage(input.pkg) |
| 38 | web.debug("copied %s to static" % output) |
| 39 | raise web.seeother('/') |
| 40 | |
| 41 | class build: |
| 42 | """ |
| 43 | builds the package specified by the pkg parameter and returns the name |
| 44 | of the output file. |
| 45 | """ |
| 46 | def GET(self): |
| 47 | input = web.input() |
| 48 | web.debug("called %s " % input.pkg) |
| 49 | return buildbot.BuildPackage(input.pkg) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 50 | |
chocobo@google.com | 4dc2581 | 2009-10-27 23:46:26 +0000 | [diff] [blame] | 51 | if __name__ == "__main__": |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 52 | |
| 53 | root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.argv[0]))) |
dhg@google.com | 47660d8 | 2009-10-28 23:11:51 +0000 | [diff] [blame] | 54 | static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sys.argv[0]))) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 55 | web.debug("dev root is %s" % root_dir) |
chocobo@google.com | 4dc2581 | 2009-10-27 23:46:26 +0000 | [diff] [blame] | 56 | web.debug("Serving images from %s" % static_dir) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 57 | os.system("mkdir -p %s" % static_dir) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 58 | |
| 59 | updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir) |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 60 | buildbot = buildutil.BuildUtil(root_dir=root_dir, static_dir=static_dir) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 61 | |
| 62 | urls = ('/', 'index', |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 63 | '/update', 'update', |
| 64 | '/webbuild', 'webbuild', |
| 65 | '/build', 'build') |
| 66 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 67 | app = web.application(urls, globals()) |
| 68 | render = web.template.render('templates/') |
| 69 | |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 70 | app.run() |