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 | |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 5 | FILENAME="gapps-passion-FRF85B-signed.zip" |
| 6 | MIRRORS=["http://www.kanged.net/mirror/gapps/",] |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 7 | |
| 8 | def 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 | |
| 13 | def download(): |
| 14 | try: |
| 15 | os.makedirs("proprietary") |
| 16 | except: |
| 17 | pass |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 18 | 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(): |
ctso | a73c687 | 2010-06-30 05:52:16 +0000 | [diff] [blame^] | 29 | if filename.split("/")[0] == "system" and filename[-1] != "/": |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 30 | print "Extracting %s" % filename |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 31 | try: |
ctso | a73c687 | 2010-06-30 05:52:16 +0000 | [diff] [blame^] | 32 | 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 |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 38 | pass |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 39 | |
| 40 | def main(): |
| 41 | parser = OptionParser(usage="usage: %prog [options]") |
ctso | 042f09f | 2010-06-30 05:42:12 +0000 | [diff] [blame] | 42 | parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: device, download [default: device]") |
Koushik Dutta | 3a5397d | 2010-06-27 20:10:23 -0700 | [diff] [blame] | 43 | (options, args) = parser.parse_args() |
| 44 | |
| 45 | if options.method == "device": |
| 46 | return device() |
| 47 | |
| 48 | if options.method == "download": |
| 49 | return download() |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | main() |