summaryrefslogtreecommitdiffstats
path: root/get-google-files
blob: 3084987dfdac8a9372f545db74bf2cdf5a9f8a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import sys, random, urllib2, zipfile, StringIO, os
from optparse import OptionParser

FILENAME="gapps-passion-FRF91-signed.zip"
MIRRORS=["http://www.kanged.net/mirror/gapps/",]

def device():
    print "usage: extract-google-files -m [method]"
    print "Note:  Device method is currently not implemented, please use download"
    sys.exit(1)

def download():
    try:
        os.makedirs("proprietary")
    except:
        pass
    if len(MIRRORS) > 1:
        i = random.randrange(0, len(MIRRORS)-1)
    else:
        i = 0
    url = MIRRORS[i] + FILENAME
    print "Fetching from %s" % url

    data = urllib2.urlopen(url).read()
    zip = zipfile.ZipFile(StringIO.StringIO(data),'r')
    
    for filename in zip.namelist():
        if filename.split("/")[0] == "system" and filename[-1] != "/":
            print "Extracting %s" % filename
            try:
                bytes = zip.read(filename)
                fd = open("proprietary/"+os.path.basename(filename),"wb")
                fd.write(bytes)
                fd.close()
            except Exception, e:
                print e
                pass

def main():
    parser = OptionParser(usage="usage: %prog [options]")
    parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: device, download [default: device]")
    (options, args) = parser.parse_args()

    if options.method == "device":
        return device()

    if options.method == "download":
        return download()

if __name__ == '__main__':
    main()