From: Peter Naudus Date: Thu, 15 May 2014 01:55:29 +0000 (-0400) Subject: Added support for ZIP compressed files X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=8d0a7bb7837234dfb40f3e01d9f4a8d918d2cef2;p=stevenblack-hosts.git Added support for ZIP compressed files --- 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')