blob: 009e16919ee1f751887ef38623f4eb10f7836c43 [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
Denham Craftona2966442011-06-14 19:18:23 -05005FILENAME=["gapps-gb-20110613-signed.zip","gapps-hdpi-20101114-signed.zip","gapps-mdpi-20110501-signed.zip","gapps-mdpi-tiny-20101020-signed.zip","gapps-mdpi-tegra-20101020-signed.zip","gapps-passion-EPE54B-signed.zip","gapps-ds-ERE36B-signed.zip","DRC83_base_defanged.zip"]
DrMacinyashac48416a2011-03-16 01:47:53 -05006VERSIONS=["gb","hdpi","mdpi","mdpi-tiny","tegra","cm5hdpi","cm5mdpi","cm4"]
Denham Crafton164602a2011-05-17 23:42:23 -05007MIRRORS=["http://goo-inside.me/gapps/","http://android.d3xt3r01.tk/cyanogen/gapps/"]
Koushik Dutta3a5397d2010-06-27 20:10:23 -07008
9def device():
Wes Garner5f296182010-09-07 21:10:50 -050010 print "usage: get-google-files -m [method] -v [version]"
Koushik Dutta3a5397d2010-06-27 20:10:23 -070011 print "Note: Device method is currently not implemented, please use download"
12 sys.exit(1)
13
Wes Garner5f296182010-09-07 21:10:50 -050014def download(version):
Koushik Dutta3a5397d2010-06-27 20:10:23 -070015 try:
Nathan Forbes76378332010-10-26 23:03:18 -040016 os.makedirs(os.path.join(os.path.dirname(__file__), "proprietary"))
Koushik Dutta3a5397d2010-06-27 20:10:23 -070017 except:
18 pass
Koushik Dutta3a5397d2010-06-27 20:10:23 -070019 if len(MIRRORS) > 1:
20 i = random.randrange(0, len(MIRRORS)-1)
21 else:
22 i = 0
Wes Garner5f296182010-09-07 21:10:50 -050023
24 try:
25 j = VERSIONS.index(version.lower())
26 except ValueError:
27 print "GApps version not found, defaulting to HDPI"
28 j = 0
29
30 url = MIRRORS[i] + FILENAME[j]
31
32 print "Fetching %s GApps from %s" % (version.upper(),url)
Koushik Dutta3a5397d2010-06-27 20:10:23 -070033
34 data = urllib2.urlopen(url).read()
35 zip = zipfile.ZipFile(StringIO.StringIO(data),'r')
36
37 for filename in zip.namelist():
ctsoa73c6872010-06-30 05:52:16 +000038 if filename.split("/")[0] == "system" and filename[-1] != "/":
Koushik Dutta3a5397d2010-06-27 20:10:23 -070039 print "Extracting %s" % filename
ctso042f09f2010-06-30 05:42:12 +000040 try:
ctsoa73c6872010-06-30 05:52:16 +000041 bytes = zip.read(filename)
Nathan Forbesec89ed42010-12-13 18:33:04 -050042 fd = open(os.path.join(os.path.dirname(__file__), "proprietary", os.path.basename(filename)),"wb")
ctsoa73c6872010-06-30 05:52:16 +000043 fd.write(bytes)
44 fd.close()
45 except Exception, e:
46 print e
ctso042f09f2010-06-30 05:42:12 +000047 pass
Koushik Dutta3a5397d2010-06-27 20:10:23 -070048
49def main():
50 parser = OptionParser(usage="usage: %prog [options]")
Wes Garner5f296182010-09-07 21:10:50 -050051 parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: download")
DrMacinyashac48416a2011-03-16 01:47:53 -050052 parser.add_option("-v", "--version", dest='version', default="gb", help="GApps Version: gb, hdpi, mdpi, mdpi-tiny, tegra, cm5hdpi, cm5mdpi, cm4 [default: gb]")
Koushik Dutta3a5397d2010-06-27 20:10:23 -070053 (options, args) = parser.parse_args()
54
55 if options.method == "device":
56 return device()
57
58 if options.method == "download":
Wes Garner5f296182010-09-07 21:10:50 -050059 return download(options.version)
Koushik Dutta3a5397d2010-06-27 20:10:23 -070060
61if __name__ == '__main__':
62 main()