3 """Validate and add a new item to the Invirt build queue.
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
10 The expected arguments are
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
27 from invirt.config import structs as config
28 import invirt.common as c
29 import invirt.builder as b
33 parser = optparse.OptionParser('Usage: %prog pocket package commit')
34 opts, args = parser.parse_args()
38 pocket, package, commit = args
39 principal = os.environ['REMOTE_USER']
40 request_time = datetime.datetime.utcnow()
41 q_path = os.path.join(b._QUEUE_DIR,
42 '%s_%s' % (request_time.strftime('%Y%m%d%H%M%S'),
46 # TODO: clean up this interface.
47 b.ensureValidPackage(package)
48 if config.build.get('mirror'):
49 c.captureOutput(['git', 'fetch'], cwd=b.getRepo(package))
50 commit = b.canonicalize_commit(package, commit)
51 b.validateBuild(pocket, package, commit)
52 except b.InvalidBuild, e:
54 print >>sys.stderr, msg
55 # Prevent an attack by submitting excessively long arguments
56 args = [arg[:min(len(arg), 80)] for arg in (pocket, package, commit)]
57 b.runHook('failed-submit', args + [principal], stdin_str=msg)
60 # To keep from triggering the Invirtibuilder before we've actually
61 # written the file out, first write the queue entry to a temporary
62 # file, and then move it into the queue directory.
63 q_fd, q_name = tempfile.mkstemp()
64 q = os.fdopen(q_fd, 'r+')
65 print >>q, "%s %s %s %s" % (pocket, package, commit, principal)
67 os.rename(q_name, q_path)
68 short_commit = b.canonicalize_commit(package, commit, shorten=True)
69 b.runHook('post-submit', [pocket, package, short_commit, principal])
70 print '%s, your job to build %s for %s:%s has been submitted!' % (principal, short_commit, package, pocket)
73 if __name__ == '__main__':