Skip to content

Commit 421be4b

Browse files
committed
Edited to raise IOError for Python < 3.3.4
In Python < 3.3.4 the FileNotFound exception is not present. As some filenames have weird encodings, and it's too problematic to fix the code to consider those, the FileNotFound error approach has been mirrored to work with Python < 3.3.4
1 parent 9c29c59 commit 421be4b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

utils/alexa-ruleset-checker.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
tmpRulesFileName = "/tmp/rulesDiff-" + format(random.randrange(1,65535)) # Feel free to enlarge if needed
3333

3434
# URL of the Alexa Top1M
35-
alexaTop1MURL = "http://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
36-
# alexaTop1MURL = "http://127.0.0.1/top-1m.csv.zip"
35+
# alexaTop1MURL = "http://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
36+
alexaTop1MURL = "http://127.0.0.1/top-1m.csv.zip"
3737

3838
# Temporary file name, to aboid conflicts
3939
tmpAlexaFileName = "/tmp/alexa-top1M-" + format(random.randrange(1,65535)) + ".csv"
@@ -132,7 +132,8 @@ def ruleLookup(target):
132132
found = 0
133133
# If file mode is "A" (add) or "M" (edited)
134134
if ruleFile[0] == "A" or ruleFile[0] == "M": # If file was added or edited between stable and master, parse
135-
ruleText = etree.parse(gitRepositoryPath + ruleFile[1]) # ADJUST FILE PATH (here is '../') IF YOU MOVE THE SCRIPT - XXX: Obsolete warning?
135+
ruleFileObject= open(gitRepositoryPath + ruleFile[1])
136+
ruleText = etree.parse(ruleFileObject) # ADJUST FILE PATH (here is '../') IF YOU MOVE THE SCRIPT - XXX: Obsolete warning?
136137
for target in ruleText.findall('target'):
137138
FQDN = target.get('host') # URL of the website
138139
if ruleLookup(FQDN) == 1: # Look it up in the sitesList
@@ -158,6 +159,13 @@ def ruleLookup(target):
158159
# logFile.write ("File not found: %s\n" % ruleFile[1])
159160
logFile.write("%s\n" % e)
160161
pass
162+
except IOError as ioe: #Treated same as FileNotFoundError
163+
print("File not found:", ruleFile[1])
164+
# logFile.write ("File not found: %s\n" % ruleFile[1])
165+
logFile.write("%s\n" % e)
166+
pass
167+
168+
161169

162170
# Print our simple statistics
163171
print("\n\nStatistics:\nParsed rules: %s\nNewly added rules: %s\nEdited rules: %d" % (maxSitesNumber, countAddedRules, countEditedRules))

0 commit comments

Comments
 (0)