blob: 67db0ff88ee879f84b2af0c57ad9c443f0b6f921 [file] [log] [blame]
rtc@google.comded22402009-10-26 22:36:21 +00001# 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
5import autoupdate
6import buildutil
7import os
8import web
chocobo@google.com4dc25812009-10-27 23:46:26 +00009import sys
rtc@google.comded22402009-10-26 22:36:21 +000010
rtc@google.com21a5ca32009-11-04 18:23:23 +000011global updater
12updater = None
rtc@google.comded22402009-10-26 22:36:21 +000013
rtc@google.com64244662009-11-12 00:52:08 +000014global buildbot
15buildbot = None
16
rtc@google.comded22402009-10-26 22:36:21 +000017class index:
18 def GET(self):
rtc@google.com64244662009-11-12 00:52:08 +000019 pkgs = buildbot.GetPackages()
rtc@google.comded22402009-10-26 22:36:21 +000020 return render.index(pkgs)
21
22class 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.com21a5ca32009-11-04 18:23:23 +000028 return updater.HandleUpdatePing(web.data())
29
rtc@google.com64244662009-11-12 00:52:08 +000030class webbuild:
31 """
32 builds the package specified by the pkg parameter. Then redirects to index
33 """
rtc@google.com21a5ca32009-11-04 18:23:23 +000034 def GET(self):
rtc@google.com64244662009-11-12 00:52:08 +000035 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
41class 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.comded22402009-10-26 22:36:21 +000050
chocobo@google.com4dc25812009-10-27 23:46:26 +000051if __name__ == "__main__":
rtc@google.com21a5ca32009-11-04 18:23:23 +000052
53 root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.argv[0])))
dhg@google.com47660d82009-10-28 23:11:51 +000054 static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sys.argv[0])))
rtc@google.com21a5ca32009-11-04 18:23:23 +000055 web.debug("dev root is %s" % root_dir)
chocobo@google.com4dc25812009-10-27 23:46:26 +000056 web.debug("Serving images from %s" % static_dir)
rtc@google.comded22402009-10-26 22:36:21 +000057 os.system("mkdir -p %s" % static_dir)
rtc@google.com21a5ca32009-11-04 18:23:23 +000058
59 updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir)
rtc@google.com64244662009-11-12 00:52:08 +000060 buildbot = buildutil.BuildUtil(root_dir=root_dir, static_dir=static_dir)
rtc@google.com21a5ca32009-11-04 18:23:23 +000061
62 urls = ('/', 'index',
rtc@google.com64244662009-11-12 00:52:08 +000063 '/update', 'update',
64 '/webbuild', 'webbuild',
65 '/build', 'build')
66
rtc@google.com21a5ca32009-11-04 18:23:23 +000067 app = web.application(urls, globals())
68 render = web.template.render('templates/')
69
rtc@google.comded22402009-10-26 22:36:21 +000070 app.run()