blob: da11242a62f2ae89e02311c76ba079b90ffea6b3 [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.comded22402009-10-26 22:36:21 +000011
rtc@google.com21a5ca32009-11-04 18:23:23 +000012global updater
13updater = None
rtc@google.comded22402009-10-26 22:36:21 +000014
15class index:
16 def GET(self):
17 pkgs = buildutil.GetPackages()
18 return render.index(pkgs)
19
20class update:
21 """
22 Processes updates from the client machine. If an update is found, the url
23 references a static link that can be served automagically from web.py.
24 """
25 def POST(self):
rtc@google.com21a5ca32009-11-04 18:23:23 +000026 return updater.HandleUpdatePing(web.data())
27
28 def GET(self):
29 web.debug("Value of updater is %s" % updater)
rtc@google.comded22402009-10-26 22:36:21 +000030
chocobo@google.com4dc25812009-10-27 23:46:26 +000031if __name__ == "__main__":
rtc@google.com21a5ca32009-11-04 18:23:23 +000032
33 root_dir = os.path.realpath("%s/../.." % os.path.dirname(os.path.abspath(sys.argv[0])))
dhg@google.com47660d82009-10-28 23:11:51 +000034 static_dir = os.path.realpath("%s/static" % os.path.dirname(os.path.abspath(sys.argv[0])))
rtc@google.com21a5ca32009-11-04 18:23:23 +000035 web.debug("dev root is %s" % root_dir)
chocobo@google.com4dc25812009-10-27 23:46:26 +000036 web.debug("Serving images from %s" % static_dir)
rtc@google.comded22402009-10-26 22:36:21 +000037 os.system("mkdir -p %s" % static_dir)
rtc@google.com21a5ca32009-11-04 18:23:23 +000038
39 updater = autoupdate.Autoupdate(root_dir=root_dir, static_dir=static_dir)
40
41 urls = ('/', 'index',
42 '/update', 'update')
43 app = web.application(urls, globals())
44 render = web.template.render('templates/')
45
rtc@google.comded22402009-10-26 22:36:21 +000046 app.run()