--- /dev/null
+#!/usr/bin/python
+
+"""Validate and add a new item to the Invirt build queue.
+
+This script, intended to be invoked by remctl, first validates the
+build submitted parameters, and then adds a new item to the
+Invirtibuilder build queue, triggering the Invirtibuilder to start the
+build.
+
+The expected arguments are
+
+ pocket package commit
+
+This script will also automatically extract the Kerberos principal
+used to submit the job, and include that in the queue file for records
+keeping.
+"""
+
+
+import datetime
+import os
+import sys
+import tempfile
+import uuid
+
+import invirt.builder as b
+
+
+def main():
+ pocket, package, commit = sys.argv[1:4]
+ principal = os.environ['REMOTE_USER']
+ request_time = datetime.datetime.utcnow()
+ q_path = os.path.join(b._QUEUE_DIR,
+ '%s_%s' % (request_time.strftime('%Y%m%d%H%M%S'),
+ uuid.uuid4()))
+
+ try:
+ validateBuild(pocket, package, commit)
+ except b.InvalidBuild, e:
+ print >>sys.stderr, "E: %s" % e
+ sys.exit(1)
+
+ # To keep from triggering the Invirtibuilder before we've actually
+ # written the file out, first write the queue entry to a temporary
+ # file, and then move it into the queue directory.
+ q = tempfile.NamedTemporaryFile(delete=False)
+ print >>q, "%s %s %s %s" % (pocket, package, commit, principal)
+ os.rename(q.name, q_path)
+
+
+if __name__ == '__main__':
+ main()