summaryrefslogtreecommitdiffstats
path: root/rpm-pyconfig
blob: d6d168df5c4c0370b42398f745b78e2c557fa979 (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
#!/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
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', '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('@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

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