blob: 3084987dfdac8a9372f545db74bf2cdf5a9f8a76 [file] [log] [blame]
Koushik Dutta3a5397d2010-06-27 20:10:23 -07001#!/usr/bin/env python
2import sys, random, urllib2, zipfile, StringIO, os
3from optparse import OptionParser
4
Chris Soyarsad3374e2010-07-04 17:23:02 +00005FILENAME="gapps-passion-FRF91-signed.zip"
ctso042f09f2010-06-30 05:42:12 +00006MIRRORS=["http://www.kanged.net/mirror/gapps/",]
Koushik Dutta3a5397d2010-06-27 20:10:23 -07007
8def device():
9 print "usage: extract-google-files -m [method]"
10 print "Note: Device method is currently not implemented, please use download"
11 sys.exit(1)
12
13def download():
14 try:
15 os.makedirs("proprietary")
16 except:
17 pass
Koushik Dutta3a5397d2010-06-27 20:10:23 -070018 if len(MIRRORS) > 1:
19 i = random.randrange(0, len(MIRRORS)-1)
20 else:
21 i = 0
22 url = MIRRORS[i] + FILENAME
23 print "Fetching from %s" % url
24
25 data = urllib2.urlopen(url).read()
26 zip = zipfile.ZipFile(StringIO.StringIO(data),'r')
27
28 for filename in zip.namelist():
ctsoa73c6872010-06-30 05:52:16 +000029 if filename.split("/")[0] == "system" and filename[-1] != "/":
Koushik Dutta3a5397d2010-06-27 20:10:23 -070030 print "Extracting %s" % filename
ctso042f09f2010-06-30 05:42:12 +000031 try:
ctsoa73c6872010-06-30 05:52:16 +000032 bytes = zip.read(filename)
33 fd = open("proprietary/"+os.path.basename(filename),"wb")
34 fd.write(bytes)
35 fd.close()
36 except Exception, e:
37 print e
ctso042f09f2010-06-30 05:42:12 +000038 pass
Koushik Dutta3a5397d2010-06-27 20:10:23 -070039
40def main():
41 parser = OptionParser(usage="usage: %prog [options]")
ctso042f09f2010-06-30 05:42:12 +000042 parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: device, download [default: device]")
Koushik Dutta3a5397d2010-06-27 20:10:23 -070043 (options, args) = parser.parse_args()
44
45 if options.method == "device":
46 return device()
47
48 if options.method == "download":
49 return download()
50
51if __name__ == '__main__':
52 main()