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 -- feeding-timers.lua
-- original author: tejón -- original author: tejón
-- rewritten by expwnent -- rewritten by expwnent
-- see repeat.lua for how to run this every so often automatically -- see repeat.lua for how to run this every so often automatically

@ -46,7 +46,7 @@ target file:
character encoding: character encoding:
The text will likely be using system-default encoding, and as such 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 fix this, you need to modify the character set that you are reading
the document with. 'Notepad++' is a freely available program which the document with. 'Notepad++' is a freely available program which
can do this using the following steps: can do this using the following steps:

@ -14,8 +14,8 @@ path_blacklist = [
] ]
def valid_file(filename): def valid_file(filename):
return len(filter(lambda ext: filename.endswith('.' + ext), valid_extensions)) and \ return len(list(filter(lambda ext: filename.endswith('.' + ext), valid_extensions))) and \
not len(filter(lambda path: path.replace('\\', '/') in filename.replace('\\', '/'), path_blacklist)) not len(list(filter(lambda path: path.replace('\\', '/') in filename.replace('\\', '/'), path_blacklist)))
success = True success = True
def error(msg): def error(msg):
@ -94,7 +94,7 @@ def main():
sys.exit(2) sys.exit(2)
fix = (len(sys.argv) > 2 and sys.argv[2] == '--fix') fix = (len(sys.argv) > 2 and sys.argv[2] == '--fix')
global path_blacklist 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 cur, dirnames, filenames in os.walk(root_path):
for filename in filenames: for filename in filenames:
@ -104,7 +104,13 @@ def main():
continue continue
lines = [] lines = []
with open(full_path, 'rb') as f: 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: for linter in linters:
try: try:
linter.check(lines) linter.check(lines)