summaryrefslogtreecommitdiffstats
path: root/koji-build.py
diff options
context:
space:
mode:
Diffstat (limited to 'koji-build.py')
-rwxr-xr-x[-rw-r--r--]koji-build.py107
1 files changed, 78 insertions, 29 deletions
diff --git a/koji-build.py b/koji-build.py
index 487449c..2a1c99d 100644..100755
--- a/koji-build.py
+++ b/koji-build.py
@@ -1,4 +1,8 @@
+#! /usr/bin/env python
+
import os
+import sys
+import errno
import koji
import optparse
import time
@@ -7,6 +11,18 @@ import string
import urlgrabber
import urlgrabber.progress
+HOME = os.getenv('HOME')
+BASEURL = 'http://kojipkgs.fedoraproject.org/work/'
+workingdir = os.getcwd()
+
+def mkdir_p(path):
+ try:
+ os.makedirs(path)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST:
+ pass
+ else: raise
+
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
@@ -19,34 +35,11 @@ def _unique_path(prefix):
''.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__":
+def _build_srpm(opts, srpm):
session = koji.ClientSession('http://koji.fedoraproject.org/kojihub')
- session.ssl_login(HOME+'/.fedora.cert',
- HOME+'/.fedora-upload-ca.cert',
- HOME+'/.fedora-server-ca.cert')
+ 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:
@@ -56,7 +49,7 @@ if __name__ == "__main__":
if not opts.quiet:
print "Upload complete. Building."
- task_id = session.build(source, target, {'scratch': True})
+ task_id = session.build(source, opts.target, {'scratch': True})
'''Wait for it to finish'''
finished = False
@@ -74,11 +67,12 @@ if __name__ == "__main__":
if not succeeded:
print "Build %d failed" % task_id
- os.exit(1)
+ return 1
# Download the finished build
tasks = session.listTasks(opts={'parent': task_id,
'method': 'buildArch',
+ 'arch': ['i386', 'x86_64'],
'state': [koji.TASK_STATES['CLOSED']],
'decode': True})
@@ -87,6 +81,14 @@ if __name__ == "__main__":
prog_meter = None
for task in tasks:
+ if (opts.build_id):
+ basepath = '%s/%s' % (workingdir, opts.build_id)
+ else:
+ basepath = '%s/output' % workingdir
+ outputpath = '%s/%s' % (basepath, task['arch'])
+ mkdir_p(outputpath)
+ os.chdir(outputpath)
+
if not opts.quiet:
print 'Downloading rpms from task %i: %s' % (task['id'], koji.taskLabel(task))
@@ -94,8 +96,55 @@ if __name__ == "__main__":
output = session.listTaskOutput(task['id'])
for filename in output:
download = False
+
if filename.endswith('.rpm'):
download = True
+ if (filename.find('debuginfo') != -1):
+ debugpath = '%s/%s' % (outputpath, 'DEBUGINFO')
+ mkdir_p(debugpath)
+ os.chdir(debugpath)
+ else:
+ if filename.endswith('.src.rpm'):
+ srpmpath = '%s/%s' % (basepath, 'SRPMS')
+ mkdir_p(srpmpath)
+ os.chdir(srpmpath)
+ else:
+ rpmpath = '%s/%s' % (outputpath, 'RPMS')
+ mkdir_p(rpmpath)
+ os.chdir(rpmpath)
+ if filename.endswith('.log'):
+ download = True
+ logpath = '%s/%s' % (outputpath, 'logs')
+ mkdir_p(logpath)
+ os.chdir(logpath)
+
if download:
urlgrabber.grabber.urlgrab(BASEURL + base_path + '/' + filename,
progress_obj=prog_meter)
+ # Return to our original working directory
+ os.chdir(workingdir)
+ return 0
+
+if __name__ == "__main__":
+ 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")
+ parser.add_option('--build_id', dest='build_id', default=None,
+ help='Specify a build_id for the output')
+ parser.add_option('--target', dest='target', default='dist-rawhide',
+ help='Specify the target platform (default: dist-rawhide)')
+
+ opts, args = parser.parse_args()
+
+ if len(args) < 1:
+ parser.error('Must specify SRPM to build')
+
+ srpm = args[0]
+
+ ret = _build_srpm(opts, srpm)
+ sys.exit(ret)