File: generate-control

package info (click to toggle)
python-oss 0.0.0.20010624-6.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 400 kB
  • ctags: 211
  • sloc: ansic: 1,349; python: 110; makefile: 81
file content (110 lines) | stat: -rw-r--r-- 2,872 bytes parent folder | download | duplicates (4)
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
103
104
105
106
107
108
109
110
#!/usr/bin/python
import os, os.path, commands
import formatter, StringIO

PYTHON_VERSIONS=['2.1', '2.2', '2.3']
PYTHON_VERSION_DEFAULT='2.3'
PYTHON_VERSION_TOOBIG='2.4'

def reflow(s):
    out=StringIO.StringIO()
    w=formatter.DumbWriter(out)
    for para in s.split('\n\n'):
        if para[:1]==' ':
            w.send_literal_data(para)
        else:
            w.send_flowing_data(para)
            w.send_literal_data('\n')
        w.send_paragraph(1)

    l=[]
    for line in out.getvalue().split('\n'):
        if line=='':
            l.append(' .')
        else:
            l.append(' '+line)
    while l and l[-1]==' .':
        del l[-1]
    return '\n'.join(l)
            

class CmdDict:
    def __init__(self, setup=None, **kwargs):
        self.setup=setup
        self.vars=kwargs

    def handle_var(self, var):
        return self.vars[var]
        
    def handle_setup(self, cmd):
        assert self.setup
        return self.handle_shell('python %s %s'%(self.setup, cmd))
        
    def handle_shell(self, cmd):
        status, output = commands.getstatusoutput(cmd)
        if status:
            raise 'Command %s failed with exit status %d.' \
                  % (repr(cmd), status)
        return output
    
    def handle_forpython(self, s):
        l=[]
        for pyver in PYTHON_VERSIONS:
            l.append(s % pyver)
        return ', '.join(l)

    def __getitem__(self, s):
        first, rest = s.split(None, 1)
        f=getattr(self, 'handle_'+first)
        return f(rest)

pypackage = """
Package: %(var package)s
Architecture: %(var arch)s
Depends: python%(var python_version)s
Description: %(setup --description)s
"""

package='python-oss'

print """\
Source: %(shell dpkg-parsechangelog|sed -n 's/^Source: //p')s
Section: sound
Priority: optional
Maintainer: %(setup --contact)s <%(setup --contact-email)s>
Standards-Version: 3.5.6
Build-Depends: %(forpython python%s-dev)s, texinfo, texi2html
""" % CmdDict('setup.py')

c = CmdDict('setup.py',

            #ugly hack
            python_version=' (>= %s), python (<< %s), python%s-oss' \
            % (PYTHON_VERSION_DEFAULT,
               PYTHON_VERSION_TOOBIG,
               PYTHON_VERSION_DEFAULT),

            package=package,
            arch='all')
print pypackage.strip() % c
print reflow('%(setup --long-description)s' % c)
print ' .'
print '''\
 This is a dummy package that depends on the correct version of
 %s for the default version of Python.
'''.rstrip() % package
print

for pyver in PYTHON_VERSIONS:
    pkgname='python'+pyver+'-'+package[len('python-'):]
    c=CmdDict(
        'setup.py',
        package=pkgname,
        python_version=pyver,
        arch='any',
        )
    print pypackage.strip() % c
    print reflow('%(setup --long-description)s' % c)
    print ' .'
    print ' This version is usable with python%s' % pyver
    print