From 8d0a7bb7837234dfb40f3e01d9f4a8d918d2cef2 Mon Sep 17 00:00:00 2001 From: Peter Naudus Date: Wed, 14 May 2014 21:55:29 -0400 Subject: [PATCH] Added support for ZIP compressed files --- updateHostsFile.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/updateHostsFile.py b/updateHostsFile.py index 231ea090d..b4d172e37 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -14,6 +14,8 @@ import subprocess import sys import tempfile import urllib2 +import zipfile +import StringIO # Project Settings BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -115,7 +117,16 @@ def updateAllSources(): continue; print 'Updating source ' + source + ' from ' + updateURL updatedFile = urllib2.urlopen(updateURL) + updatedFile = updatedFile.read() + + if '.zip' in updateURL: + updatedZippedFile = zipfile.ZipFile(StringIO.StringIO(updatedFile)) + for name in updatedZippedFile.namelist(): + if name in ('hosts', 'hosts.txt'): + updatedFile = updatedZippedFile.open(name).read() + break + updatedFile = string.replace( updatedFile, '\r', '' ) #get rid of carriage-return symbols dataFile = open(DATA_PATH + '/' + source + '/' + DATA_FILENAMES, 'w')