From caf97c8e8cd2b6d8a7819848888556064b403c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Wed, 25 Nov 2009 23:27:24 +0100 Subject: start on a build option, creating an equivalent of 'mdvsys build' --- MgaRepo/commands/buildrpm.py | 31 +++++++++++++++++++++++++++++++ MgaRepo/rpmutil.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 MgaRepo/commands/buildrpm.py (limited to 'MgaRepo') diff --git a/MgaRepo/commands/buildrpm.py b/MgaRepo/commands/buildrpm.py new file mode 100644 index 0000000..8bb681d --- /dev/null +++ b/MgaRepo/commands/buildrpm.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# +from MgaRepo import Error, config +from MgaRepo.command import * +from MgaRepo.layout import package_url +from MgaRepo.rpmutil import build_rpm +import tempfile +import shutil +from optparse import * +import glob +import sys +import os + +HELP = """\ +Usage: repsys buildrpm [OPTIONS] + +Builds the binary RPM(s) (.rpm) file(s) of a given package. +""" + +def parse_options(): + parser = OptionParser(HELP) + parser.add_option("-b", dest="build_cmd", default="a") + parser.add_option("-P", dest="packager", default="") + parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False) + opts, args = parser.parse_args() + return opts + +def main(): + do_command(parse_options, build_rpm) + +# vim:et:ts=4:sw=4 diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py index 1b6f261..201ba0b 100644 --- a/MgaRepo/rpmutil.py +++ b/MgaRepo/rpmutil.py @@ -375,6 +375,43 @@ def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None, log="Copying release %s-%s to releases/ directory." % (version, srpm.release)) +def build_rpm(build_cmd="a", + verbose=False, + packager = "", + macros = []): + top = os.getcwd() + topdir = "_topdir %s" % top + builddir = "_builddir %s/%s" % (top, "BUILD") + rpmdir = "_rpmdir %s/%s" % (top, "RPMS") + sourcedir = "_sourcedir %s/%s" % (top, "SOURCES") + specdir = "_specdir %s/%s" % (top, "SPECS") + srcrpmdir = "_srcrpmdir %s/%s" % (top, "SRPMS") + patchdir = "_patchdir %s/%s" % (top, "SOURCES") + + build = os.path.join(top, "BUILD") + if not os.path.exists(build): + os.mkdir(build) + specsdir = os.path.join(top, "SPECS") + speclist = glob.glob(os.path.join(specsdir, "*.spec")) + if not speclist: + raise Error("no spec files found") + spec = speclist[0] + + rpmdefs = [("--define", expr) for expr in (topdir, builddir, rpmdir, + sourcedir, specdir, srcrpmdir, patchdir)] + + if packager: + rpmdefs.append(("--define", "packager %s" % packager)) + + rpmbuild = config.get("helper", "rpmbuild", "rpmbuild") + args = [rpmbuild, "-bb", spec] + for pair in rpmdefs: + args.extend(pair) + for pair in macros: + args.extend(("--define", "%s %s" % pair)) + os.environ["LC_ALL"] = "C" + execcmd(*args, show=verbose) + def create_package(pkgdirurl, log="", verbose=0): svn = detectVCS(pkgdirurl) tmpdir = tempfile.mktemp() -- cgit v1.2.1