diff --git a/tools/pyflakes.sh b/tools/pyflakes.sh index 97121bb7..c0a40971 100755 --- a/tools/pyflakes.sh +++ b/tools/pyflakes.sh @@ -8,9 +8,10 @@ grep -Fn '.setlocale' ${PYFILES} && echo 'Error: do not use setlocale' && exit 5 grep -Fn '__future__ import with_statement' ${PYFILES} && echo 'Error: with_statement useless as we do not support Python 2.5' && exit 6 grep -nE '^[[:space:]]+except [[:alnum:] ]+,[[:alnum:] ]+' ${PYFILES} && echo 'Error: use new "as" way of naming exceptions' && exit 7 grep -nE "^ *print " ${PYFILES} && echo 'Error: Use the print function' && exit 8 -grep -Fn ".has_key" ${PYFILES} && echo 'Error: Deprecated, use in' && exit 9 +grep -Fn ".has_key" ${PYFILES} && echo 'Error: Deprecated, use operator "in"' && exit 9 +grep -Fn "os.isatty" ${PYFILES} && echo 'Error: Use stream.isatty() instead of os.isatty(stream.fileno())' && exit 10 MODULE_FILES=$(git ls-files|grep '^modules/.*\.py$'|tr '\n' ' ') -grep -nE "^ *print(\(| )" ${MODULE_FILES} && echo 'Error: Use of print in modules is forbidden, use logger instead' && exit 10 +grep -nE "^ *print(\(| )" ${MODULE_FILES} && echo 'Error: Use of print in modules is forbidden, use logger instead' && exit 20 FLAKE8="" if which flake8 >/dev/null 2>&1; then diff --git a/weboob/applications/pastoob/pastoob.py b/weboob/applications/pastoob/pastoob.py index 75dcc8be..6a65670e 100644 --- a/weboob/applications/pastoob/pastoob.py +++ b/weboob/applications/pastoob/pastoob.py @@ -105,7 +105,7 @@ class Pastoob(ReplApplication): output.write(paste.contents) # add a newline unless we are writing # in a file or in a pipe - if os.isatty(output.fileno()): + if output.isatty(): output.write('\n') def do_post(self, line): diff --git a/weboob/applications/webcontentedit/webcontentedit.py b/weboob/applications/webcontentedit/webcontentedit.py index d2a980f7..f10169fd 100644 --- a/weboob/applications/webcontentedit/webcontentedit.py +++ b/weboob/applications/webcontentedit/webcontentedit.py @@ -197,5 +197,5 @@ class WebContentEdit(ReplApplication): # add a newline unless we are writing # in a file or in a pipe - if os.isatty(output.fileno()): + if output.isatty(): output.write('\n') diff --git a/weboob/tools/application/console.py b/weboob/tools/application/console.py index 080a1383..e8691d8f 100644 --- a/weboob/tools/application/console.py +++ b/weboob/tools/application/console.py @@ -64,7 +64,7 @@ class ConsoleApplication(Application): # shell escape strings if sys.platform == 'win32' \ - or not os.isatty(sys.stdout.fileno()) \ + or not sys.stdout.isatty() \ or os.getenv('ANSI_COLORS_DISABLED') is not None: #workaround to disable bold BOLD = '' @@ -120,7 +120,7 @@ class ConsoleApplication(Application): def check_loaded_backends(self, default_config=None): while len(self.enabled_backends) == 0: print('Warning: there is currently no configured backend for %s' % self.APPNAME) - if not os.isatty(self.stdout.fileno()) or not self.ask('Do you want to configure backends?', default=True): + if not self.stdout.isatty() or not self.ask('Do you want to configure backends?', default=True): return False self.prompt_create_backends(default_config) diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index 977e7632..9d033087 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -84,7 +84,7 @@ class IFormatter(object): NC = ConsoleApplication.NC def colored(self, string, color, attrs=None, on_color=None): - if self.outfile != sys.stdout or not (os.isatty(self.outfile.fileno())): + if self.outfile != sys.stdout or not self.outfile.isatty(): return string if isinstance(attrs, basestring): @@ -100,7 +100,7 @@ class IFormatter(object): self.outfile = outfile # XXX if stdin is not a tty, it seems that the command fails. - if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()): + if sys.stdout.isatty() and sys.stdin.isatty(): if sys.platform == 'win32': self.termrows = WConio.gettextinfo()[8] else: