Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import sys, random, urllib2, zipfile, StringIO, os |
| 3 | from optparse import OptionParser |
| 4 | |
Denham Crafton | 164602a | 2011-05-17 23:42:23 -0500 | [diff] [blame] | 5 | FILENAME=["gapps-gb-20110307-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"] |
DrMacinyasha | c48416a | 2011-03-16 01:47:53 -0500 | [diff] [blame] | 6 | VERSIONS=["gb","hdpi","mdpi","mdpi-tiny","tegra","cm5hdpi","cm5mdpi","cm4"] |
Denham Crafton | 164602a | 2011-05-17 23:42:23 -0500 | [diff] [blame] | 7 | MIRRORS=["http://goo-inside.me/gapps/","http://android.d3xt3r01.tk/cyanogen/gapps/"] |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 8 | |
| 9 | def device(): |
Wes Garner | 5f29618 | 2010-09-07 21:10:50 -0500 | [diff] [blame] | 10 | print "usage: get-google-files -m [method] -v [version]" |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 11 | print "Note: Device method is currently not implemented, please use download" |
| 12 | sys.exit(1) |
| 13 | |
Wes Garner | 5f29618 | 2010-09-07 21:10:50 -0500 | [diff] [blame] | 14 | def download(version): |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 15 | try: |
Nathan Forbes | 7637833 | 2010-10-26 23:03:18 -0400 | [diff] [blame] | 16 | os.makedirs(os.path.join(os.path.dirname(__file__), "proprietary")) |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 17 | except: |
| 18 | pass |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 19 | if len(MIRRORS) > 1: |
| 20 | i = random.randrange(0, len(MIRRORS)-1) |
| 21 | else: |
| 22 | i = 0 |
Wes Garner | 5f29618 | 2010-09-07 21:10:50 -0500 | [diff] [blame] | 23 | |
| 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 Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 33 | |
| 34 | data = urllib2.urlopen(url).read() |
| 35 | zip = zipfile.ZipFile(StringIO.StringIO(data),'r') |
| 36 | |
| 37 | for filename in zip.namelist(): |
ctso | a73c687 | 2010-06-30 05:52:16 +0000 | [diff] [blame] | 38 | if filename.split("/")[0] == "system" and filename[-1] != "/": |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 39 | print "Extracting %s" % filename |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 40 | try: |
ctso | a73c687 | 2010-06-30 05:52:16 +0000 | [diff] [blame] | 41 | bytes = zip.read(filename) |
Nathan Forbes | ec89ed4 | 2010-12-13 18:33:04 -0500 | [diff] [blame] | 42 | fd = open(os.path.join(os.path.dirname(__file__), "proprietary", os.path.basename(filename)),"wb") |
ctso | a73c687 | 2010-06-30 05:52:16 +0000 | [diff] [blame] | 43 | fd.write(bytes) |
| 44 | fd.close() |
| 45 | except Exception, e: |
| 46 | print e |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 47 | pass |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 48 | |
| 49 | def main(): |
| 50 | parser = OptionParser(usage="usage: %prog [options]") |
Wes Garner | 5f29618 | 2010-09-07 21:10:50 -0500 | [diff] [blame] | 51 | parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: download") |
DrMacinyasha | c48416a | 2011-03-16 01:47:53 -0500 | [diff] [blame] | 52 | parser.add_option("-v", "--version", dest='version', default="gb", help="GApps Version: gb, hdpi, mdpi, mdpi-tiny, tegra, cm5hdpi, cm5mdpi, cm4 [default: gb]") |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 53 | (options, args) = parser.parse_args() |
| 54 | |
| 55 | if options.method == "device": |
| 56 | return device() |
| 57 | |
| 58 | if options.method == "download": |
Wes Garner | 5f29618 | 2010-09-07 21:10:50 -0500 | [diff] [blame] | 59 | return download(options.version) |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 60 | |
| 61 | if __name__ == '__main__': |
| 62 | main() |