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 | |
| 5 | FILENAME="gapps-passion-FRF83-signed.zip" |
| 6 | MIRRORS=["http://www.kanged.net/up/files/1/",] |
| 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 |
| 18 | os.chdir("proprietary") |
| 19 | if len(MIRRORS) > 1: |
| 20 | i = random.randrange(0, len(MIRRORS)-1) |
| 21 | else: |
| 22 | i = 0 |
| 23 | url = MIRRORS[i] + FILENAME |
| 24 | print "Fetching from %s" % url |
| 25 | |
| 26 | data = urllib2.urlopen(url).read() |
| 27 | zip = zipfile.ZipFile(StringIO.StringIO(data),'r') |
| 28 | |
| 29 | for filename in zip.namelist(): |
| 30 | if filename.split("/")[0] == "system": |
| 31 | print "Extracting %s" % filename |
| 32 | zip.extract(filename) |
| 33 | |
| 34 | def main(): |
| 35 | parser = OptionParser(usage="usage: %prog [options]") |
| 36 | parser.add_option("-m", "--method", dest='method', default="device", help="Extraction Method: device, download [default: device]") |
| 37 | (options, args) = parser.parse_args() |
| 38 | |
| 39 | if options.method == "device": |
| 40 | return device() |
| 41 | |
| 42 | if options.method == "download": |
| 43 | return download() |
| 44 | |
| 45 | if __name__ == '__main__': |
| 46 | main() |