blob: eb8ab5380ed72a9c87d6e5306deb5667424573bf [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
DrMacinyasha1698c042010-12-02 17:54:11 -08005FILENAME=["gapps-hdpi-20101114-signed.zip","gapps-mdpi-20101020-signed.zip","gapps-mdpi-tiny-20101020-signed.zip"]
Wes Garner5f296182010-09-07 21:10:50 -05006VERSIONS=["hdpi","mdpi","mdpi-tiny"]
DrMacinyasha1698c042010-12-02 17:54:11 -08007MIRRORS=["http://cyanogenmod-mirror.local.host.name/gapps/","http://goo-inside.me/google-apps/","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")
52 parser.add_option("-v", "--version", dest='version', default="hdpi", help="GApps Version: hdpi, mdpi, mdpi-tiny [default: hdpi]")
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()