File: update-xanim-modules

package info (click to toggle)
xanim-modules 2.80.1.7
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 40 kB
  • ctags: 20
  • sloc: python: 139; makefile: 44; sh: 15
file content (180 lines) | stat: -rwxr-xr-x 6,410 bytes parent folder | download
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/python
# Download updated modules for xanim from the Mark Podlipec's FTP site
#
# (C) 1999 Chris Lawrence.
# You may freely distribute this file under the terms of the GNU General
# Public License, version 2 or later.

import commands, sys, fnmatch, string, tempfile, os, string, popen2, urllib

def my_read(fp, length=None):
    input = ''
    count = 0
    if length is not None:
        while len(input) < length:
            desired = length - len(input)
            if desired > 2048: desired=2048
            stuff = fp.read(desired)
            if stuff:
                input = input+stuff
                sys.stderr.write('.')
                sys.stderr.flush()
            else:
                break
    else:
        stuff = fp.read(2048)
        input = input+stuff
        sys.stderr.write('.')
        sys.stderr.flush()
        while stuff:
            stuff = fp.read(2048)
            input = input+stuff
            sys.stderr.write('.')
            sys.stderr.flush()
    
    return input

# FTP site and directory
URLROOT='ftp://xanim.va.pubnix.com/dlls/'

# Where the module file registry goes; don't change this location!
LOGFILE='/usr/lib/xanim/xanim-modules'

# Mapping from Debian architectures to Mark's
ARCHMAP = { 'powerpc' : 'linuxELFppc',
            'alpha' : 'linuxELFalpha',
            'i386' : 'linuxELFx86g21' }

# Mapping of available modules and versions
FILEMAP = { 'powerpc' : ('cvid_2.1', 'cyuv_1.0', 'h261_1.0', 'h263_1.0',
                         'iv32_2.1', 'iv41_1.1', 'iv50_1.0'),
            'alpha' : ('cvid_2.1', 'cyuv_1.0', 'h261_1.0', 'h263_1.0',
                       'iv32_2.1', 'iv41_1.1', 'iv50_1.0'),
            'i386' : ('cvid_2.0', 'cyuv_1.0', 'h261_1.0', 'h263_1.0',
                      'iv32_2.1', 'iv41_1.0', 'iv50_1.0')
            }

# Mapping of modules and their long names
MODNAMES = { 'cvid' : 'Radius Cinepak',
             'cyuv' : 'Creative CYUV',
             'h261' : 'CCITT H.261',
             'h263' : 'CCITT H.263',
             'iv32' : 'Intel Indeo 3.1, 3.2',
             'iv41' : 'Intel Indeo 4.1',
             'iv50' : 'Intel Indeo 5.0' }

def main():
    if len(sys.argv) > 1 and sys.argv[1] == '--sanitation':
        if not os.path.exists(LOGFILE):
            sys.exit(0)

        print 'update-xanim-modules: Fixing module paths and permissions'
        installed = map(string.strip, open(LOGFILE).readlines())
        installed = map(lambda x: os.path.join('/usr/lib/xanim', x), installed)
        newinst = []

        fp = open(LOGFILE, 'w', 0644)
        for file in installed:
            if '\0' in file: continue
            if not file in newinst:
                file = os.path.join('/usr/lib/xanim', file)
                (dir, filename) = os.path.split(file)

                # Throw out any bogus files
                if dir != '/usr/lib/xanim': continue
                if not os.path.exists(file): continue

                fp.write(file+'\n')
                os.chmod(file, 0644)
                os.chown(file, 0, 0)
                newinst.append(file)

        fp.close()
        sys.exit(0)

    arch = commands.getoutput('dpkg --print-installation-architecture')

    xanim_arch = ARCHMAP.get(arch)
    needed = FILEMAP.get(arch)

    if not xanim_arch or not needed:
        print 'No xanim modules are available for '+arch
        sys.exit(0)

    if len(sys.argv) > 1:
        urlroot = 'file:'+os.path.abspath(sys.argv[1])+'/'
    else:
        urlroot = URLROOT
        print """These modules may be useful if you have animations in
egregiously non-free formats you wish to display.  However, because the author
is unable to distribute source for them, you should consider whether you
trust him enough to install his code sight-unseen on your system.  I
(Chris Lawrence) have not seen the source code for these modules and
therefore cannot make any guarantees as to their security implications.
Caveat downloader."""
        print

        ok = ''
        while ok != 'y':
            ok = raw_input('Download xanim modules? [yes/no] ')
            if ok: ok = string.lower(ok[0])

            if ok == 'n':
                print
                print 'You can also install the modules by downloading the'
                print 'following files from '+URLROOT+':'
                for module in needed:
                    print '  vid_%s_%s.tgz' % (module, xanim_arch)
                print 'Then run "update-xanim-modules DIR", where DIR is the'
                print 'name of the directory that contains those files.'
                sys.exit(0)
            elif ok != 'y':
                print 'Please say yes or no.'

    if os.path.exists(LOGFILE):
        installed = map(string.strip, open(LOGFILE).readlines())
        installed = map(lambda x: os.path.join('/usr/lib/xanim', x), installed)
        installed = filter(lambda x: ('\0' not in x) and
                           (os.path.split(x)[0] == '/usr/lib/xanim')
                           and os.path.exists(x), installed)
    else:
        installed = []

    tempfile.tempdir = os.environ.get('TMPDIR', '/tmp')
    print 'Downloading and installing from '+urlroot
    for module in needed:
        # Filenames in this directory are "vid_TYPE_VER_ARCH.tgz"
        file = 'vid_%s_%s.tgz' % (module, xanim_arch)
        (type, version) = string.split(module, '_')
        type = MODNAMES.get(type, type+' support')
        sys.stderr.write('    %s (%s) ' % (file, type))
        sys.stderr.flush()
        (fpout, fpin) = popen2.popen2('tar -C /usr/lib/xanim -zxvf -')
        urlfp = urllib.urlopen(urlroot+file)
        sys.stderr.write('+')
        sys.stderr.flush()
        # Use our cute hashmark printer
        fpin.write(my_read(urlfp))
        fpin.close()
        sys.stderr.write('\n')

        newfiles = map(string.strip, fpout.readlines())
        newfiles = map(lambda x: os.path.join('/usr/lib/xanim', x), newfiles)
        for nf in newfiles:
            while installed.count(nf) > 1: installed.remove(nf)
            if nf not in installed: installed.append(nf)

        fpout.close()

    installed.sort()
    fp = open(LOGFILE, 'w', 0644)
    for file in installed:
        file = os.path.join('/usr/lib/xanim', file)
        fp.write(file+'\n')
        os.chmod(file, 0644)
        os.chown(file, 0, 0)

    print 'All modules downloaded and installed.'

if __name__ == '__main__':
    main()