blob: a65fff29d9fb6c23797f1c3d701e8351d7a7c48b [file] [log] [blame]
Sylvain Munautaa55d302010-11-12 19:36:21 +01001#!/usr/bin/env python
2
3import urllib2
4import os
5import sys
6import zipfile
7
8try:
9 import cStringIO as StringIO
10except:
11 import StringIO
12
13
Sylvain Munaut8b5e0c72013-12-13 15:41:01 +010014SRC = "http://www.3gpp.org/ftp/Specs/archive/06_series/06.06/0606-421.zip"
Sylvain Munautaa55d302010-11-12 19:36:21 +010015
16
17def get_zipfile(data):
18 return zipfile.ZipFile(StringIO.StringIO(data))
19
20
21def get_subfile_data(data, filename):
22 z = get_zipfile(data)
23 return z.read(filename)
24
25
26def process_file(z, e):
Sylvain Munaut89668462015-12-30 10:56:13 +010027 fh = open(os.path.basename(e.filename.lower()), 'w')
Sylvain Munautaa55d302010-11-12 19:36:21 +010028 d = z.read(e).replace('\r','')
29 fh.write(d)
30 fh.close()
31
32
33def main(*args):
34
35 # Args
36 if len(args) != 2:
37 print "Usage: %s target_dir" % args[0]
38 return
39
40 tgt = args[1]
41
42 # Create and go to target dir
43 if not os.path.isdir(tgt):
44 os.mkdir(tgt)
45 os.chdir(tgt)
46
47 # Get the original data
48 u = urllib2.urlopen(SRC)
49 d = u.read()
50
51 # Get DISK.zip
52 d = get_subfile_data(d, 'DISK.zip')
53
54 # Get Dir_C.zip
55 d = get_subfile_data(d, 'Dir_C.zip')
56
57 # Get zip file object
58 z = get_zipfile(d)
59
60 # Save each file
61 for e in z.filelist:
62 process_file(z, e)
63
64
65if __name__ == '__main__':
66 main(*sys.argv)