summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2010-03-13 20:32:16 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2010-03-13 20:32:16 -0500
commitc71bd544dbeace47ce8fed45d5ce87809da55a8c (patch)
tree0b8a911518b8c18c4f50b44486c09b0c966182fc
parentcd5b140623a78b634466ca43de6bbf24cfb7980d (diff)
downloadrpm-pyconfig-c71bd544dbeace47ce8fed45d5ce87809da55a8c.tar.gz
rpm-pyconfig-c71bd544dbeace47ce8fed45d5ce87809da55a8c.tar.xz
rpm-pyconfig-c71bd544dbeace47ce8fed45d5ce87809da55a8c.zip
Initial implementation of rpm-pyconfig; update specfile to use it
-rw-r--r--python-coverage.spec16
-rwxr-xr-xrpm-pyconfig60
2 files changed, 68 insertions, 8 deletions
diff --git a/python-coverage.spec b/python-coverage.spec
index aaed9e5..c1d44df 100644
--- a/python-coverage.spec
+++ b/python-coverage.spec
@@ -24,7 +24,7 @@ BuildRequires: python3-setuptools, python3-devel
# Macro for defining subpackages:
%define variant_package() \
%package -n %{1}\
-Summary: Code coverage testing module for %{2}\
+Summary: Code coverage testing module for %{1}\
Group: System Environment/Libraries\
%description -n %{1}\
Coverage.py is a Python module that measures code coverage during Python \
@@ -32,12 +32,12 @@ execution. It uses the code analysis tools and tracing hooks provided in the \
Python standard library to determine which lines are executable, and which \
have been executed.\
\
-This is the build for the %{3} variant of Python.\
+This is the build for the %{1} variant of Python.\
%{nil}
-%(for f in python26 python27 python31 python32 ; do
- echo "%{variant_package $f $f $f}"
-done)
+%(./rpm-pyconfig --foreach \
+ --eval "%{variant_package @pkgname-coverage}"
+)
%description
Coverage.py is a Python module that measures code coverage during Python
@@ -118,9 +118,9 @@ rm -rf %{buildroot}
%doc README.txt \
%{nil}
-%(for f in python26 python27 python31 python32 ; do
- echo "%{variant_files $f}"
-done)
+%(./rpm-pyconfig --foreach \
+ --eval "%{variant_files @pkgname-coverage}"
+)
%changelog
diff --git a/rpm-pyconfig b/rpm-pyconfig
new file mode 100755
index 0000000..840d81d
--- /dev/null
+++ b/rpm-pyconfig
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+
+class PyConfig(object):
+ '''A specific Python configuration e.g. "Python 2.7 --with-pydebug"
+ '''
+
+ def __init__(self, binname, pkgname, description):
+ self.binname = binname
+ self.pkgname = pkgname
+ self.description = description
+
+from optparse import OptionParser
+parser = OptionParser()
+parser.add_option('-v', "--verbose", action="store_true", dest="verbose",
+ help="Display additional debugging information")
+parser.add_option("--foreach", action="store_true", dest="foreach",
+ help="Iterate over all Python configurations")
+
+
+parser.add_option("--exe", action="store_true", dest="execute_args",
+ help="Execute args with python")
+parser.add_option("--eval", action="store", type="string", dest="eval",
+ help="Print a formatted string")
+
+(options, args) = parser.parse_args()
+
+if options.verbose:
+ print (options, args)
+
+
+# FIXME: this would eventually come from /etc/rpm-pyconfig.d/*.conf
+configs = [PyConfig('python2.6', 'python26', 'standard build of Python 2.6'),
+ PyConfig('python2.6-dbg', 'python26-dbg', 'debug build of Python 2.6'),
+ PyConfig('python2.7', 'python27', 'standard build of Python 2.7'),
+ PyConfig('python2.7-dbg', 'python27-dbg', 'debug build of Python 2.7'),
+ PyConfig('python3.1', 'python31', 'standard build of Python 3.1'),
+ PyConfig('python3.1-dbg', 'python31-dbg', 'debug build of Python 3.1'),
+ PyConfig('python3.2', 'python32', 'standard build of Python 3.2'),
+ PyConfig('python3.2-dbg', 'python32-dbg', 'debug build of Python 3.2'),
+ ]
+
+def do_eval(conf, fmt):
+ # use "@" as the metacharacter, to avoid confusion with shell "$" and
+ # specfiles "%"
+ fmt = fmt.replace('@binname', conf.binname)
+ fmt = fmt.replace('@pkgname', conf.pkgname)
+ fmt = fmt.replace('@description', conf.description)
+ print fmt
+
+if options.foreach:
+ for conf in configs:
+ if options.execute_args:
+ from subprocess import Popen
+ p = Popen([conf.binname] + args)
+ p.wait()
+ elif options.eval:
+ do_eval(conf, options.eval)
+ else:
+ print conf.pkgname