source: trunk/packages/invirt-dev/invirt-submit-build @ 3028

Last change on this file since 3028 was 3028, checked in by gdb, 14 years ago

Make invirtibuilder work

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/usr/bin/python
2
3"""Validate and add a new item to the Invirt build queue.
4
5This script, intended to be invoked by remctl, first validates the
6build submitted parameters, and then adds a new item to the
7Invirtibuilder build queue, triggering the Invirtibuilder to start the
8build.
9
10The expected arguments are
11
12  pocket package commit
13
14This script will also automatically extract the Kerberos principal
15used to submit the job, and include that in the queue file for records
16keeping.
17"""
18
19
20import datetime
21import optparse
22import os
23import sys
24import tempfile
25import uuid
26
27import invirt.builder as b
28
29
30def main():
31    parser = optparse.OptionParser('Usage: %prog pocket package commit')
32    opts, args = parser.parse_args()
33    if len(args) != 3:
34        parser.print_help()
35        return 1
36    pocket, package, commit = args
37    principal = os.environ['REMOTE_USER']
38    request_time = datetime.datetime.utcnow()
39    q_path = os.path.join(b._QUEUE_DIR,
40                          '%s_%s' % (request_time.strftime('%Y%m%d%H%M%S'),
41                                     uuid.uuid4()))
42
43    try:
44        b.validateBuild(pocket, package, commit)
45    except b.InvalidBuild, e:
46        print >>sys.stderr, "E: %s" % e
47        sys.exit(1)
48
49    # To keep from triggering the Invirtibuilder before we've actually
50    # written the file out, first write the queue entry to a temporary
51    # file, and then move it into the queue directory.
52    q_fd, q_name = tempfile.mkstemp()
53    q = os.fdopen(q_fd, 'r+')
54    print >>q, "%s %s %s %s" % (pocket, package, commit, principal)
55    q.close()
56    os.rename(q_name, q_path)
57
58
59if __name__ == '__main__':
60    main()
Note: See TracBrowser for help on using the repository browser.