Added support for ZIP compressed files
authorPeter Naudus <redacted>
Thu, 15 May 2014 01:55:29 +0000 (21:55 -0400)
committerPeter Naudus <redacted>
Thu, 15 May 2014 01:55:29 +0000 (21:55 -0400)
updateHostsFile.py

index 231ea090d14df7c7c4a734bd1d014227e75e61b5..b4d172e37f1515c07d585c3fdf0db579ccb7b9ff 100644 (file)
@@ -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')
git clone https://git.99rst.org/PROJECT