blob: ad6ece69b033a8a8d1718bc2f6c66f62dc2b1ad0 [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
rtc@google.comded22402009-10-26 22:36:21 +00006import os
7import web
chocobo@google.com4dc25812009-10-27 23:46:26 +00008import sys
rtc@google.comded22402009-10-26 22:36:21 +00009
rtc@google.com21a5ca32009-11-04 18:23:23 +000010global updater
11updater = None
rtc@google.comded22402009-10-26 22:36:21 +000012
rtc@google.com64244662009-11-12 00:52:08 +000013global buildbot
14buildbot = None
15
rtc@google.comded22402009-10-26 22:36:21 +000016class index:
17 def GET(self):
rtc@google.com64244662009-11-12 00:52:08 +000018 pkgs = buildbot.GetPackages()
rtc@google.comded22402009-10-26 22:36:21 +000019 return render.index(pkgs)
20
21class 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):
rtc@google.com21a5ca32009-11-04 18:23:23 +000027 return updater.HandleUpdatePing(web.data())
28
rtc@google.com64244662009-11-12 00:52:08 +000029class build:
30 """
31 builds the package specified by the pkg parameter and returns the name
32 of the output file.
33 """
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080034 def POST(self):
rtc@google.com64244662009-11-12 00:52:08 +000035 input = web.input()
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080036 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)
rtc@google.comded22402009-10-26 22:36:21 +000041
chocobo@google.com4dc25812009-10-27 23:46:26 +000042if __name__ == "__main__":
rtc@google.com21a5ca32009-11-04 18:23:23 +000043
44 root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.argv[0])))
dhg@google.com47660d82009-10-28 23:11:51 +000045 static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sys.argv[0])))
rtc@google.com21a5ca32009-11-04 18:23:23 +000046 web.debug("dev root is %s" % root_dir)
chocobo@google.com4dc25812009-10-27 23:46:26 +000047 web.debug("Serving images from %s" % static_dir)
rtc@google.comded22402009-10-26 22:36:21 +000048 os.system("mkdir -p %s" % static_dir)
rtc@google.com21a5ca32009-11-04 18:23:23 +000049
50 updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir)
51
52 urls = ('/', 'index',
rtc@google.com64244662009-11-12 00:52:08 +000053 '/update', 'update',
54 '/webbuild', 'webbuild',
55 '/build', 'build')
56
rtc@google.com21a5ca32009-11-04 18:23:23 +000057 app = web.application(urls, globals())
58 render = web.template.render('templates/')
59
rtc@google.comded22402009-10-26 22:36:21 +000060 app.run()