1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/usr/bin/env python
import os
import sys
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
# Optimize this?
self.major_version = self.capture_stdout('import sys; print (sys.version_info[0])').strip()
self.minor_version = self.capture_stdout('import sys; print (sys.version_info[1])').strip()
def capture_stdout(self, command):
from subprocess import Popen, PIPE
p = Popen([self.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 self.major_version == '3':
# fmt = fmt.replace('@confsrcdir', '%{py3dir}')
#else:
# fmt = fmt.replace('@confsrcdir', '.')
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",
help="Display additional debugging information")
parser.add_option("--foreach", action="store_true", dest="foreach",
help="Iterate over all Python configurations")
parser.add_option("--foreach-2", action="store_true", dest="foreach2",
help="Iterate over all Python 2 configurations")
parser.add_option("--foreach-3", action="store_true", dest="foreach3",
help="Iterate over all Python 3 configurations")
parser.add_option("--ifany-2", action="store_true", dest="ifany2")
parser.add_option("--ifany-3", action="store_true", dest="ifany3")
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")
(options, args) = parser.parse_args()
if options.verbose:
print (options, args)
# FIXME: this would eventually come from /etc/rpm-pyconfig.d/*.conf
if 1:
# The two Fedora 13 python runtimes
configs = [PyConfig('python2.6', 'python2', 'Python 2'),
PyConfig('python3.1', 'python3', 'Python 3'),
]
if 0:
# Combinatorial fun - but what will we want in the future?
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'),
]
# is the --foreach option redundant ?
if options.ifany3:
sys.exit(0) # FIXME
for conf in configs:
if (options.foreach
or (options.foreach2 and conf.major_version=='2')
or (options.foreach3 and conf.major_version=='3')):
if options.execute:
cmd = conf.eval(options.execute)
os.system(cmd)
elif options.eval:
print conf.eval(options.eval)
else:
print conf.pkgname
|