summaryrefslogtreecommitdiffstats
path: root/bin/src2bin_text.py
blob: 87354b288e2e2f949211f25a473520b22c1c5aee (plain) (blame)
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
#!/usr/bin/env python2

import sys
import os
import fileinput

ca_path = '/etc/ssl/ca-debian'
if os.path.isdir(ca_path):
    os.environ['SSL_CERT_DIR'] = ca_path

default_url = 'https://packages.qa.debian.org/cgi-bin/soap-alpha.cgi'

def soappy_query(url, method, **kwargs):
    import SOAPpy

    ws = SOAPpy.SOAPProxy(url)
    return getattr(ws, method)(**kwargs)

def joinEN(words):
    if len(words) == 1: return words[0]
    if len(words) == 2: return ' and '.join(words)
    if len(words) >= 3: return ', '.join(words[:-1]+ ['and %s' % words[-1]])

def filterPkg(bins,rms):
    for rm in rms:
        bins = filter(lambda x: not x.endswith('-%s' % rm), bins)
    return bins
    
def getBin(srcPkg):
    bins = soappy_query(default_url,'binary_names',source=srcPkg)
    if type(bins) == str: bins = [bins]
    return [ i for i in bins]

def word_wrap(string, width=80, ind1=0, ind2=0, prefix=''):
    """ word wrapping function.
        string: the string to wrap
        width: the column number to wrap at
        prefix: prefix each line with this string (goes before any indentation)
        ind1: number of characters to indent the first line
        ind2: number of characters to indent the rest of the lines
    """
    string = prefix + ind1 * " " + string
    newstring = ""
    while len(string) > width:
        # find position of nearest whitespace char to the left of "width"
        marker = width - 1
        while not string[marker].isspace():
            marker = marker - 1

        # remove line from original string and add it to the new string
        newline = string[0:marker] + "\n"
        newstring = newstring + newline
        string = prefix + ind2 * " " + string[marker + 1:]

    return newstring + string

def change(line, toRemove):
    srcPkg = line[35:-11]
    bins = filterPkg(getBin(srcPkg),toRemove)
    return joinEN(bins)

if __name__ == '__main__':
    exclude = []
    if '-x' in sys.argv:
       i = sys.argv.index('-x')
       exclude = sys.argv[i+1:]
       sys.argv = sys.argv[:i]
    for line in fileinput.input():
       if 'We recommend that you upgrade your' in line:
	 line = word_wrap("%s: %s.\n" % (line[:-2],change(line,exclude)),width=73)
       print(line)

© 2014-2024 Faster IT GmbH | imprint | privacy policy