2010-06-28 03:10:23 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys, random, urllib2, zipfile, StringIO, os
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
2010-06-30 05:42:12 +00:00
|
|
|
FILENAME="gapps-passion-FRF85B-signed.zip"
|
|
|
|
MIRRORS=["http://www.kanged.net/mirror/gapps/",]
|
2010-06-28 03:10:23 +00:00
|
|
|
|
|
|
|
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():
|
2010-06-30 05:52:16 +00:00
|
|
|
if filename.split("/")[0] == "system" and filename[-1] != "/":
|
2010-06-28 03:10:23 +00:00
|
|
|
print "Extracting %s" % filename
|
2010-06-30 05:42:12 +00:00
|
|
|
try:
|
2010-06-30 05:52:16 +00:00
|
|
|
bytes = zip.read(filename)
|
|
|
|
fd = open("proprietary/"+os.path.basename(filename),"wb")
|
|
|
|
fd.write(bytes)
|
|
|
|
fd.close()
|
|
|
|
except Exception, e:
|
|
|
|
print e
|
2010-06-30 05:42:12 +00:00
|
|
|
pass
|
2010-06-28 03:10:23 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = OptionParser(usage="usage: %prog [options]")
|
2010-06-30 05:42:12 +00:00
|
|
|
parser.add_option("-m", "--method", dest='method', default="download", help="Extraction Method: device, download [default: device]")
|
2010-06-28 03:10:23 +00:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.method == "device":
|
|
|
|
return device()
|
|
|
|
|
|
|
|
if options.method == "download":
|
|
|
|
return download()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|