blob: 3a5ffe14a5a62e399907a639b51d207dc619d69a [file] [log] [blame]
[email protected]ded22402009-10-26 22:36:211# 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
Sean O'Connor14b6a0a2010-03-21 06:23:486import buildutil
7import optparse
[email protected]ded22402009-10-26 22:36:218import os
Sean O'Connor14b6a0a2010-03-21 06:23:489import SimpleHTTPServer
[email protected]ded22402009-10-26 22:36:2110import web
[email protected]4dc25812009-10-27 23:46:2611import sys
[email protected]ded22402009-10-26 22:36:2112
[email protected]21a5ca32009-11-04 18:23:2313global updater
14updater = None
[email protected]ded22402009-10-26 22:36:2115
[email protected]64244662009-11-12 00:52:0816global buildbot
17buildbot = None
18
[email protected]ded22402009-10-26 22:36:2119class index:
20 def GET(self):
[email protected]64244662009-11-12 00:52:0821 pkgs = buildbot.GetPackages()
[email protected]ded22402009-10-26 22:36:2122 return render.index(pkgs)
23
24class update:
25 """
26 Processes updates from the client machine. If an update is found, the url
27 references a static link that can be served automagically from web.py.
28 """
Sean O'Connor14b6a0a2010-03-21 06:23:4829 def POST(self, args=None):
30 return updater.HandleUpdatePing(web.data(), args)
[email protected]21a5ca32009-11-04 18:23:2331
[email protected]64244662009-11-12 00:52:0832class build:
33 """
34 builds the package specified by the pkg parameter and returns the name
35 of the output file.
36 """
Ryan Cairnsdd1ceb82010-03-03 05:35:0137 def POST(self):
[email protected]64244662009-11-12 00:52:0838 input = web.input()
Sean O'Connor14b6a0a2010-03-21 06:23:4839 web.debug('emerging %s ' % input.pkg)
40 emerge_command = 'emerge-%s %s' % (input.board, input.pkg)
Ryan Cairnsdd1ceb82010-03-03 05:35:0141 err = os.system(emerge_command)
42 if err != 0:
Sean O'Connor14b6a0a2010-03-21 06:23:4843 raise Exception('failed to execute %s' % emerge_command)
[email protected]ded22402009-10-26 22:36:2144
Sean O'Connor14b6a0a2010-03-21 06:23:4845if __name__ == '__main__':
46 usage = 'usage: %prog [options]'
47 parser = optparse.OptionParser(usage)
48 parser.add_option('-a', '--archive_dir', dest='archive_dir',
49 help='serve archived builds only.')
50 parser.add_option("-t", action="store_true", dest="test_image")
51 options, args = parser.parse_args()
52 # clean up the args, due to httpserver's hardcoded use of sys.argv
53 if options.archive_dir:
54 sys.argv.remove('-a')
55 sys.argv.remove(options.archive_dir)
56 if options.test_image:
57 sys.argv.remove('-t')
[email protected]21a5ca32009-11-04 18:23:2358
[email protected]21a5ca32009-11-04 18:23:2359
Sean O'Connor14b6a0a2010-03-21 06:23:4860 root_dir = os.path.realpath('%s/../..' %
61 os.path.dirname(os.path.abspath(sys.argv[0])))
62 if options.archive_dir:
63 static_dir = os.path.realpath(options.archive_dir)
64 assert os.path.exists(static_dir), '%s must exist.' % options.archive_dir
65 web.debug('using archive dir: %s' % static_dir)
66 else:
67 static_dir = os.path.realpath('%s/static' %
68 os.path.dirname(os.path.abspath(sys.argv[0])))
69 web.debug('dev root is %s' % root_dir)
70 os.system('mkdir -p %s' % static_dir)
71 web.debug('Serving images from %s' % static_dir)
[email protected]21a5ca32009-11-04 18:23:2372
Sean O'Connor14b6a0a2010-03-21 06:23:4873 updater = autoupdate.Autoupdate(root_dir=root_dir,
74 static_dir=static_dir,
75 serve_only=options.archive_dir,
76 test_image=options.test_image)
[email protected]21a5ca32009-11-04 18:23:2377 urls = ('/', 'index',
[email protected]64244662009-11-12 00:52:0878 '/update', 'update',
Sean O'Connor14b6a0a2010-03-21 06:23:4879 '/update/(.+)', 'update',
[email protected]64244662009-11-12 00:52:0880 '/webbuild', 'webbuild',
81 '/build', 'build')
82
Sean O'Connor14b6a0a2010-03-21 06:23:4883 app = web.application(urls, globals(), autoreload=True)
[email protected]21a5ca32009-11-04 18:23:2384 render = web.template.render('templates/')
[email protected]ded22402009-10-26 22:36:2185 app.run()