1 | #!/usr/bin/python |
---|
2 | |
---|
3 | """Validate and add a new item to the Invirt build queue. |
---|
4 | |
---|
5 | This script, intended to be invoked by remctl, first validates the |
---|
6 | build submitted parameters, and then adds a new item to the |
---|
7 | Invirtibuilder build queue, triggering the Invirtibuilder to start the |
---|
8 | build. |
---|
9 | |
---|
10 | The expected arguments are |
---|
11 | |
---|
12 | pocket package commit |
---|
13 | |
---|
14 | This script will also automatically extract the Kerberos principal |
---|
15 | used to submit the job, and include that in the queue file for records |
---|
16 | keeping. |
---|
17 | """ |
---|
18 | |
---|
19 | |
---|
20 | import datetime |
---|
21 | import os |
---|
22 | import sys |
---|
23 | import tempfile |
---|
24 | import uuid |
---|
25 | |
---|
26 | import invirt.builder as b |
---|
27 | |
---|
28 | |
---|
29 | def main(): |
---|
30 | pocket, package, commit = sys.argv[1:4] |
---|
31 | principal = os.environ['REMOTE_USER'] |
---|
32 | request_time = datetime.datetime.utcnow() |
---|
33 | q_path = os.path.join(b._QUEUE_DIR, |
---|
34 | '%s_%s' % (request_time.strftime('%Y%m%d%H%M%S'), |
---|
35 | uuid.uuid4())) |
---|
36 | |
---|
37 | try: |
---|
38 | validateBuild(pocket, package, commit) |
---|
39 | except b.InvalidBuild, e: |
---|
40 | print >>sys.stderr, "E: %s" % e |
---|
41 | sys.exit(1) |
---|
42 | |
---|
43 | # To keep from triggering the Invirtibuilder before we've actually |
---|
44 | # written the file out, first write the queue entry to a temporary |
---|
45 | # file, and then move it into the queue directory. |
---|
46 | q = tempfile.NamedTemporaryFile(delete=False) |
---|
47 | print >>q, "%s %s %s %s" % (pocket, package, commit, principal) |
---|
48 | os.rename(q.name, q_path) |
---|
49 | |
---|
50 | |
---|
51 | if __name__ == '__main__': |
---|
52 | main() |
---|