summaryrefslogtreecommitdiffstats
path: root/rpm-pyconfig
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2010-03-13 21:45:40 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2010-03-13 21:45:40 -0500
commitb2ffb264b02361c7e6de82b1cd2f9c6010b94167 (patch)
tree68a8c9eb8c8bfa6328fea640e10ff0d1fe733b70 /rpm-pyconfig
parentf575952276433712639658cad92e001908b579c6 (diff)
downloadrpm-pyconfig-b2ffb264b02361c7e6de82b1cd2f9c6010b94167.tar.gz
rpm-pyconfig-b2ffb264b02361c7e6de82b1cd2f9c6010b94167.tar.xz
rpm-pyconfig-b2ffb264b02361c7e6de82b1cd2f9c6010b94167.zip
Revamp --exe so that the example specfile actually builds
Diffstat (limited to 'rpm-pyconfig')
-rwxr-xr-xrpm-pyconfig66
1 files changed, 39 insertions, 27 deletions
diff --git a/rpm-pyconfig b/rpm-pyconfig
index d6d168d..24fca41 100755
--- a/rpm-pyconfig
+++ b/rpm-pyconfig
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-
+import os
class PyConfig(object):
'''A specific Python configuration e.g. "Python 2.7 --with-pydebug"
@@ -10,6 +10,29 @@ class PyConfig(object):
self.pkgname = pkgname
self.description = description
+ def capture_stdout(self, command):
+ from subprocess import Popen, PIPE
+ p = Popen([conf.binname, '-c', command], stdout=PIPE)
+ stdout, stderr = p.communicate()
+ return stdout
+
+ def eval(self, fmt):
+ # use "@" as the metacharacter, to avoid confusion with shell "$" and
+ # specfiles "%". (Possible issues with email addresses?)
+ fmt = fmt.replace('@confbin', self.binname)
+ fmt = fmt.replace('@confpkg', self.pkgname)
+ fmt = fmt.replace('@confdescline',
+ "This package is for %s" % self.description)
+ fmt = fmt.replace('@confdesc', self.description)
+
+ fmt = fmt.replace('@confsrcdir', '%s-src' % self.pkgname)
+
+ if '@conf_sitearch' in fmt:
+ conf_sitearch = self.capture_stdout("from distutils.sysconfig import get_python_lib; print(get_python_lib(1))").strip()
+ fmt = fmt.replace('@conf_sitearch', conf_sitearch)
+
+ return fmt
+
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-v', "--verbose", action="store_true", dest="verbose",
@@ -18,8 +41,8 @@ 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("--exe", action="store", dest="execute",
+ help="Execute shell command (with formatting)")
parser.add_option("--eval", action="store", type="string", dest="eval",
help="Print a formatted string")
@@ -37,34 +60,23 @@ if 1:
]
if 0:
# Combinatorial fun - but what will we want in the future?
- 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'),
+ configs = [PyConfig('python2.6', 'python26', 'the standard build of Python 2.6'),
+ PyConfig('python2.6-dbg', 'python26-dbg', 'the debug build of Python 2.6'),
+ PyConfig('python2.7', 'python27', 'the standard build of Python 2.7'),
+ PyConfig('python2.7-dbg', 'python27-dbg', 'the debug build of Python 2.7'),
+ PyConfig('python3.1', 'python31', 'the standard build of Python 3.1'),
+ PyConfig('python3.1-dbg', 'python31-dbg', 'the debug build of Python 3.1'),
+ PyConfig('python3.2', 'python32', 'standard thebuild of Python 3.2'),
+ PyConfig('python3.2-dbg', 'python32-dbg', 'the 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('@confbin', conf.binname)
- fmt = fmt.replace('@confpkg', conf.pkgname)
- fmt = fmt.replace('@confdescline',
- "This package is for the %s" % conf.description)
- fmt = fmt.replace('@confdesc', conf.description)
-
- print fmt
-
+# is the --foreach option redundant ?
if options.foreach:
for conf in configs:
- if options.execute_args:
- from subprocess import Popen
- p = Popen([conf.binname] + args)
- p.wait()
+ if options.execute:
+ cmd = conf.eval(options.execute)
+ os.system(cmd)
elif options.eval:
- do_eval(conf, options.eval)
+ print conf.eval(options.eval)
else:
print conf.pkgname