summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-10-25 08:46:46 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-10-25 08:46:46 -0400
commit9e7c443341bd49ecc8becb19e5212abe079b22ba (patch)
tree1bda25937ce1128dc2ed14639e10e544184da6c0
parent41059ebc2aec817c5535b3de4270f50dc40fcdcd (diff)
downloadbuild_tools-9e7c443341bd49ecc8becb19e5212abe079b22ba.zip
build_tools-9e7c443341bd49ecc8becb19e5212abe079b22ba.tar.gz
build_tools-9e7c443341bd49ecc8becb19e5212abe079b22ba.tar.xz
Initial commit of koji-build.py
-rw-r--r--koji-build.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/koji-build.py b/koji-build.py
new file mode 100644
index 0000000..487449c
--- /dev/null
+++ b/koji-build.py
@@ -0,0 +1,101 @@
+import os
+import koji
+import optparse
+import time
+import random
+import string
+import urlgrabber
+import urlgrabber.progress
+
+def _unique_path(prefix):
+ """Create a unique path fragment by appending a path component
+ to prefix. The path component will consist of a string of letter and numbers
+ that is unlikely to be a duplicate, but is not guaranteed to be unique."""
+ # Use time() in the dirname to provide a little more information when
+ # browsing the filesystem.
+ # For some reason repr(time.time()) includes 4 or 5
+ # more digits of precision than str(time.time())
+ return '%s/%r.%s' % (prefix, time.time(),
+ ''.join([random.choice(string.ascii_letters) for i in range(8)]))
+
+
+HOME = os.getenv('HOME')
+BASEURL = 'http://kojipkgs.fedoraproject.org/work/'
+
+usage = 'usage: %prog [options] <srpm> <target>'
+parser = optparse.OptionParser(usage=usage)
+parser.add_option('--verbose', action='store_true',
+ default=False,
+ help = "Display verbose progress")
+parser.add_option('--quiet', action='store_true',
+ default=False,
+ help = "Only print errors")
+
+opts, args = parser.parse_args()
+
+if len(args) < 1:
+ parser.error('Must specify SRPM to build')
+
+srpm = args[0]
+
+target = 'dist-rawhide'
+if len(args) == 2:
+ target=args[1]
+
+if __name__ == "__main__":
+ session = koji.ClientSession('http://koji.fedoraproject.org/kojihub')
+ session.ssl_login(HOME+'/.fedora.cert',
+ HOME+'/.fedora-upload-ca.cert',
+ HOME+'/.fedora-server-ca.cert')
+ serverdir = _unique_path('cli-build')
+
+ if not opts.quiet:
+ print "Uploading %s" % srpm
+ session.uploadWrapper(srpm, serverdir)
+ source = "%s/%s" % (serverdir, os.path.basename(srpm))
+
+ if not opts.quiet:
+ print "Upload complete. Building."
+ task_id = session.build(source, target, {'scratch': True})
+
+ '''Wait for it to finish'''
+ finished = False
+ while not finished:
+ if opts.verbose:
+ print "Waiting for task %s to complete. Sleeping 60 seconds" % task_id
+ time.sleep(60)
+ task = session.getTaskInfo(task_id, request=True)
+ if task['state'] == koji.TASK_STATES['CLOSED']:
+ finished = True
+ succeeded = True
+ elif task['state'] not in (koji.TASK_STATES['FREE'], koji.TASK_STATES['OPEN']):
+ finished = True
+ succeeded = False
+
+ if not succeeded:
+ print "Build %d failed" % task_id
+ os.exit(1)
+
+ # Download the finished build
+ tasks = session.listTasks(opts={'parent': task_id,
+ 'method': 'buildArch',
+ 'state': [koji.TASK_STATES['CLOSED']],
+ 'decode': True})
+
+ prog_meter = urlgrabber.progress.TextMeter()
+ if opts.quiet:
+ prog_meter = None
+
+ for task in tasks:
+ if not opts.quiet:
+ print 'Downloading rpms from task %i: %s' % (task['id'], koji.taskLabel(task))
+
+ base_path = koji.pathinfo.taskrelpath(task['id'])
+ output = session.listTaskOutput(task['id'])
+ for filename in output:
+ download = False
+ if filename.endswith('.rpm'):
+ download = True
+ if download:
+ urlgrabber.grabber.urlgrab(BASEURL + base_path + '/' + filename,
+ progress_obj=prog_meter)