Make lint.py work under Python 3 and fix a few UTF-8 errors

develop
lethosor 2015-04-06 11:25:30 -04:00
parent 4b124bc022
commit fab7887f20
3 changed files with 12 additions and 6 deletions

@ -1,5 +1,5 @@
-- feeding-timers.lua
-- original author: tejón
-- original author: tejón
-- rewritten by expwnent
-- see repeat.lua for how to run this every so often automatically

@ -46,7 +46,7 @@ target file:
character encoding:
The text will likely be using system-default encoding, and as such
will likely NOT display special characters (eg:é,õ,ç) correctly. To
will likely NOT display special characters (eg:é,õ,ç) correctly. To
fix this, you need to modify the character set that you are reading
the document with. 'Notepad++' is a freely available program which
can do this using the following steps:

@ -14,8 +14,8 @@ path_blacklist = [
]
def valid_file(filename):
return len(filter(lambda ext: filename.endswith('.' + ext), valid_extensions)) and \
not len(filter(lambda path: path.replace('\\', '/') in filename.replace('\\', '/'), path_blacklist))
return len(list(filter(lambda ext: filename.endswith('.' + ext), valid_extensions))) and \
not len(list(filter(lambda path: path.replace('\\', '/') in filename.replace('\\', '/'), path_blacklist)))
success = True
def error(msg):
@ -94,7 +94,7 @@ def main():
sys.exit(2)
fix = (len(sys.argv) > 2 and sys.argv[2] == '--fix')
global path_blacklist
path_blacklist = map(lambda s: os.path.join(root_path, s.replace('^', '')) if s.startswith('^') else s, path_blacklist)
path_blacklist = list(map(lambda s: os.path.join(root_path, s.replace('^', '')) if s.startswith('^') else s, path_blacklist))
for cur, dirnames, filenames in os.walk(root_path):
for filename in filenames:
@ -104,7 +104,13 @@ def main():
continue
lines = []
with open(full_path, 'rb') as f:
lines = f.read().split('\n')
lines = f.read().split(b'\n')
for i, line in enumerate(lines):
try:
lines[i] = line.decode('utf-8')
except UnicodeDecodeError:
error('%s:%i: Invalid UTF-8 (other errors will be ignored)' % (rel_path, i + 1))
lines[i] = ''
for linter in linters:
try:
linter.check(lines)