Initial version of rpm-builder and source packages modified to work with it
authorSam hartman <hartmans@painless-security.com>
Tue, 20 Dec 2011 21:38:37 +0000 (21:38 +0000)
committerSam hartman <hartmans@painless-security.com>
Thu, 12 Jan 2012 20:18:23 +0000 (20:18 +0000)
builder
rpm-builder [new file with mode: 0755]
rpm_packages [new file with mode: 0644]

diff --git a/builder b/builder
index 8e11a89..490722c 100755 (executable)
--- a/builder
+++ b/builder
@@ -69,18 +69,18 @@ def command_output(args) :
 def build(package):
     with current_directory(package):
         run_cmd(('autoreconf', '-i', '-f'))
-        configure_command = ' '.join([
-                                      './configure'] + configure_opts)
+        configure_command = [
+                                      './configure'] + configure_opts
         if len(schroot_command) > 0:
-            configure_command = schroot_command + " -- " \
+            configure_command = [schroot_command , "--"] \
                 + configure_command
-        print configure_command
+        print ' '.join(configure_command)
         sys.stdout.flush()
-        run_cmd(configure_command, shell=True)
+        run_cmd(configure_command, shell=False)
         if dist:
             try: os.mkdir('doc/api')
             except: pass
-            run_cmd(schroot_command +' make dist-gzip', shell=True)
+            run_cmd(root_command +' make dist-gzip', shell=True)
             run_cmd('cp *.tar.gz ' +dist_dir, shell=True)
         run_cmd(schroot_command + ' make', shell=True)
 
diff --git a/rpm-builder b/rpm-builder
new file mode 100755 (executable)
index 0000000..8749c4b
--- /dev/null
@@ -0,0 +1,104 @@
+#!/usr/bin/python
+
+'''A script to buildMoonshot  potentially using a schroot for install testing.
+'''
+
+from contextlib import contextmanager
+import os, subprocess, exceptions
+import re
+import sys
+from optparse import OptionParser
+from shutil import copy
+
+
+
+# These variables can be overridden by options. If packages is not
+# set, then it is read from the rpm_packages file
+packages = []  # Set of packages to build
+
+class CommandError(exceptions.StandardError):
+    pass
+
+def is_tarball(name):
+    return re.match('^.*\\.tar\\.gz', name)
+
+def trim_tarball(t):
+    match = re.match('([^/-]*/)?([^-/]+)', t)
+    return match.group(2)
+
+@contextmanager
+def current_directory(dir):
+    "Change the current directory as a context manager; when the context exits, return."
+    cwd = os.getcwd()
+    os.chdir(dir)
+    yield
+    os.chdir(cwd)
+
+
+def run_cmd(args, **kwords):
+    rcode =  subprocess.call( args, **kwords)
+    if rcode <> 0:
+        raise CommandError(args)
+
+def command_output(args) :
+    p = subprocess.Popen(args, stdout=subprocess.PIPE)
+    output = p.communicate()
+    output = output[0]
+    if p.returncode != 0:
+        raise CommandError(args)
+    return output.strip()
+
+def build(package):
+    run_cmd(['rpmbuild', '-ta', package])
+
+
+
+def read_packages():
+    '''Read in the packages file from rpm_packages
+    '''
+    try: pf = file("rpm_packages")
+    except IOError:
+        print "Error: rpm_packages file not found"
+        exit(1)
+    def is_comment(line):
+        if re.match("^\\s*#", line): return False
+        if "#" in line: raise ValueError(
+            "Source package line contains a comment but not at beginning")
+        return True
+    return map(lambda(x): x.rstrip(),
+        filter(is_comment, pf.readlines()))
+
+
+# main program
+opt = OptionParser()
+opt.usage = "%prog [options] distributions_dir [packages]"
+(options, args) = opt.parse_args()
+if len(args) == 0:
+    print "Distributions directory required"
+    exit(1)
+dist_dir = args[0]
+packages = args[1:]
+
+if len(packages) == 0: packages = read_packages()
+package_order = {}
+count = 0
+tarballs = filter(is_tarball, os.listdir(dist_dir))
+for t in packages:
+    package_order[trim_tarball(t)] = count
+    count += 1
+    
+
+os.umask(022)
+
+try:
+    with current_directory(dist_dir):
+        tarballs.sort (key = lambda x: package_order[trim_tarball(x)])
+        for t in tarballs:
+            build(t)
+except CommandError as c:
+    print "Error:" + str(c.args)
+    exit(1)
+
+
+    
+
diff --git a/rpm_packages b/rpm_packages
new file mode 100644 (file)
index 0000000..36436f0
--- /dev/null
@@ -0,0 +1,11 @@
+# This file contains a list of directories containing 
+# Debian source packages one per line.
+# Lines starting with # are comments
+shibboleth/xmltooling
+shibboleth/opensaml
+shibboleth
+shibboleth-resolver
+libradsec
+jansson
+mech_eap
+#cyrus-sasl