~ubuntu-branches/ubuntu/trusty/bittornado/trusty-proposed

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
#!/usr/bin/env python
# Written by John Hoffman

from time import strftime
from zlib import compress
from binascii import b2a_base64
from traceback import print_exc
import sys
from os.path import join
from BitTornado import version

icons = [ 'icon_bt.ico', 'icon_done.ico',
          'black.ico', 'blue.ico', 'green.ico', 'red.ico', 'white.ico', 'yellow.ico',
          'black1.ico', 'green1.ico', 'yellow1.ico', 'alloc.gif' ]

width = 60

normalstdout = sys.stdout
try:
    f = open('CreateIcons.py','w')
    sys.stdout = f

    print '# Generated from bt_MakeCreateIcons - '+strftime('%x %X')
    print '# '+version
    print ''
    print 'from binascii import a2b_base64'
    print 'from zlib import decompress'
    print 'from os.path import join'
    print ''

    print 'icons = {'
    for icon in icons:
        print '    "'+icon+'":'
        ff = open(join('icons',icon),'rb')
        d = b2a_base64(compress(ff.read())).strip()
        ff.close()
        while d:
            d1 = d[:width]
            d = d[width:]
            if d:
                extra = ' +'
            elif icon != icons[-1]:
                extra = ','
            else:
                extra = ''
            print '        "'+d1+'"'+extra
    print '}'
    print ''
    print 'def GetIcons():'
    print '    return icons.keys()'
    print ''
    print 'def CreateIcon(icon, savedir):'
    print '    try:'
    print '        f = open(join(savedir,icon),"wb")'
    print '        f.write(decompress(a2b_base64(icons[icon])))'
    print '        success = 1'
    print '    except:'
    print '        success = 0'
    print '    try:'
    print '        f.close()'
    print '    except:'
    print '        pass'
    print '    return success'

except:
    sys.stdout = normalstdout
    print_exc()
    try:
        ff.close()
    except:
        pass

sys.stdout = normalstdout
try:
    f.close()
except:
    pass


# here's the output code used

def GetIcons():
    return icons.keys()

def CreateIcon(icon, savedir):
    try:
        f = open(icon,'wb')
        f.write(decompress(a2b_base64(icons[icon])))
        success = 1
    except:
        success = 0
    try:
        f.close()
    except:
        pass
    return success