summaryrefslogtreecommitdiffstats
path: root/rpm-pyconfig
blob: 24fca41c19fd8a5afa0521307218635b4e28e1c1 (plain)
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
#!/usr/bin/env python
import os

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

    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",
                  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", 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.foreach:
    for conf in configs:
        if options.execute:
            cmd = conf.eval(options.execute)
            os.system(cmd)
        elif options.eval:
            print conf.eval(options.eval)
        else:
            print conf.pkgname