3 '''A script to buildMoonshot potentially using a schroot for install testing.
6 from contextlib import contextmanager
7 import os, subprocess, exceptions
10 from optparse import OptionParser
11 from shutil import copy
15 # These variables can be overridden by options. If packages is not
16 # set, then it is read from the rpm_packages file
17 packages = [] # Set of packages to build
19 class CommandError(exceptions.StandardError):
23 return re.match('^.*\\.tar\\.gz', name)
26 match = re.match('([^/-]*/)?([^-/]+)', t)
30 def current_directory(dir):
31 "Change the current directory as a context manager; when the context exits, return."
38 def run_cmd(args, **kwords):
39 rcode = subprocess.call( args, **kwords)
41 raise CommandError(args)
43 def command_output(args) :
44 p = subprocess.Popen(args, stdout=subprocess.PIPE)
45 output = p.communicate()
48 raise CommandError(args)
52 run_cmd(['rpmbuild', '-ta', package])
57 '''Read in the packages file from rpm_packages
59 try: pf = file("rpm_packages")
61 print "Error: rpm_packages file not found"
64 if re.match("^\\s*#", line): return False
65 if "#" in line: raise ValueError(
66 "Source package line contains a comment but not at beginning")
68 return map(lambda(x): x.rstrip(),
69 filter(is_comment, pf.readlines()))
74 opt.usage = "%prog [options] distributions_dir [packages]"
75 (options, args) = opt.parse_args()
77 print "Distributions directory required"
82 if len(packages) == 0: packages = read_packages()
85 tarballs = filter(is_tarball, os.listdir(dist_dir))
87 package_order[trim_tarball(t)] = count
94 with current_directory(dist_dir):
95 tarballs.sort (key = lambda x: package_order[trim_tarball(x)])
98 except CommandError as c:
99 print "Error:" + str(c.args)