summaryrefslogtreecommitdiffstats
path: root/libgsmhr/fetch_sources.py
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2010-11-12 19:36:21 +0100
committerSylvain Munaut <tnt@246tNt.com>2010-11-12 20:47:30 +0100
commitaa55d30d20bf419deb36301010337b4642770964 (patch)
tree802cf24eaa8dc2494679b10738e4f83b324b5db9 /libgsmhr/fetch_sources.py
parent0d2a82c312056046ecafba318e60a930df395ea2 (diff)
[2/4] HR support: Add logic to fetch reference source code and build it
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'libgsmhr/fetch_sources.py')
-rwxr-xr-xlibgsmhr/fetch_sources.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/libgsmhr/fetch_sources.py b/libgsmhr/fetch_sources.py
new file mode 100755
index 0000000..cb37e0c
--- /dev/null
+++ b/libgsmhr/fetch_sources.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import urllib2
+import os
+import sys
+import zipfile
+
+try:
+ import cStringIO as StringIO
+except:
+ import StringIO
+
+
+SRC = "http://ftp.3gpp.org/Specs/2001-06/Ph2/06_series/0606-421/0606_421.zip"
+
+
+def get_zipfile(data):
+ return zipfile.ZipFile(StringIO.StringIO(data))
+
+
+def get_subfile_data(data, filename):
+ z = get_zipfile(data)
+ return z.read(filename)
+
+
+def process_file(z, e):
+ fh = open(e.filename.lower(), 'w')
+ d = z.read(e).replace('\r','')
+ fh.write(d)
+ fh.close()
+
+
+def main(*args):
+
+ # Args
+ if len(args) != 2:
+ print "Usage: %s target_dir" % args[0]
+ return
+
+ tgt = args[1]
+
+ # Create and go to target dir
+ if not os.path.isdir(tgt):
+ os.mkdir(tgt)
+ os.chdir(tgt)
+
+ # Get the original data
+ u = urllib2.urlopen(SRC)
+ d = u.read()
+
+ # Get DISK.zip
+ d = get_subfile_data(d, 'DISK.zip')
+
+ # Get Dir_C.zip
+ d = get_subfile_data(d, 'Dir_C.zip')
+
+ # Get zip file object
+ z = get_zipfile(d)
+
+ # Save each file
+ for e in z.filelist:
+ process_file(z, e)
+
+
+if __name__ == '__main__':
+ main(*sys.argv)