Use flake8 if available instead of pyflakes

With flake8, we can check for more issues and ignore those who are not
real issues.

This allowed me to find genuine errors in:
- modules/boursorama/pages/account_history.py
- modules/ing/pages/login.py
- weboob/tools/application/qt/qt.py
I left one in weboob/tools/browser/browser.py for the time being.

Some PEP8 fixes on other files.
This commit is contained in:
Laurent Bachelier 2012-11-24 19:46:34 +01:00
commit 541d080c9d
18 changed files with 54 additions and 45 deletions

View file

@ -21,7 +21,7 @@
try:
import sqlite3 as sqlite
except ImportError, e:
from pysqlite2 import dbapi2 as sqlite
from pysqlite2 import dbapi2 as sqlite # NOQA
from weboob.core import Weboob
from weboob.core.modules import ModuleLoadError
@ -30,6 +30,7 @@ import logging
level = logging.DEBUG
logging.basicConfig(stream=sys.stdout, level=level)
def main(filename):
weboob = Weboob()
try:

View file

@ -23,7 +23,6 @@ from datetime import date
import re
from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Transaction
from weboob.tools.capabilities.bank.transactions import FrenchTransaction

View file

@ -25,7 +25,7 @@ from logging import warning, debug
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from cgi import parse_qs # NOQA
from weboob.tools.misc import html2text, get_bytes_size
from weboob.capabilities.torrent import Torrent
@ -69,7 +69,7 @@ class TorrentsPage(BasePage):
current_group += ' - '
current_group += a.text
elif tr.attrib.get('class', '').startswith('group_torrent') or \
tr.attrib.get('class', '').startswith('torrent'):
tr.attrib.get('class', '').startswith('torrent'):
tds = tr.findall('td')
title = current_group
@ -100,9 +100,9 @@ class TorrentsPage(BasePage):
continue
id = '%s.%s' % (params['id'][0], m.group(1))
try:
size, unit = tds[i+3].text.split()
size, unit = tds[i + 3].text.split()
except ValueError:
size, unit = tds[i+2].text.split()
size, unit = tds[i + 2].text.split()
size = get_bytes_size(float(size.replace(',', '')), unit)
seeders = int(tds[-2].text)
leechers = int(tds[-1].text)
@ -159,8 +159,8 @@ class TorrentsPage(BasePage):
torrent.seeders = int(tds[3].text)
torrent.leechers = int(tds[4].text)
break
elif not is_table and tr.attrib.get('class', '').startswith('torrent_widget') and \
tr.attrib.get('class', '').endswith('pad'):
elif not is_table and tr.attrib.get('class', '').startswith('torrent_widget') \
and tr.attrib.get('class', '').endswith('pad'):
url = tr.cssselect('a[title=Download]')[0].attrib['href']
m = self.TORRENTID_REGEXP.match(url)
if not m:

View file

@ -23,7 +23,7 @@ import re
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from cgi import parse_qs # NOQA
from weboob.capabilities import NotAvailable
from weboob.tools.browser import BasePage, BrokenPageError
@ -87,6 +87,7 @@ class BaseVideoPage(BasePage):
def get_description(self):
raise NotImplementedError()
class VideoPage(BaseVideoPage):
URL_REGEXP = re.compile('http://www.ina.fr/(.+)\.html')

View file

@ -104,8 +104,9 @@ class LoginPage(BasePage):
self.browser.submit(nologin=True)
def error(self):
error = self.document.find('//span[@class="error"]')
return error is not None
err = self.document.find('//span[@class="error"]')
return err is not None
class LoginPage2(BasePage):
def on_loaded(self):

View file

@ -21,7 +21,7 @@
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from cgi import parse_qs # NOQA
from urlparse import urlsplit

View file

@ -29,7 +29,7 @@ import re
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from cgi import parse_qs # NOQA
__all__ = ['RadioFranceBrowser', 'RadioFranceVideo']
@ -93,7 +93,6 @@ class ReplayPage(BasePage):
return (radio_domain, player_id)
class DataPage(BasePage):
def get_current(self):
document = self.document

View file

@ -1,7 +1,12 @@
#!/bin/bash
#!/bin/bash -u
cd $(dirname $0)
cd ..
# grep will return 0 only if it founds something, but our script
# wants to return 0 when it founds nothing!
pyflakes weboob modules contrib scripts/* | grep -v redefinition && exit 1 || exit 0
if which flake8 >/dev/null 2>&1; then
set -e
flake8 --ignore=E,W *.py weboob modules contrib scripts/*
else
# grep will return 0 only if it founds something, but our script
# wants to return 0 when it founds nothing!
pyflakes *.py weboob modules contrib scripts/* | grep -v redefinition && exit 1 || exit 0
fi

View file

@ -24,6 +24,7 @@ from logging import warning
import gtk
class FakeConic(object):
STATUS_CONNECTED = None
STATUS_DISCONNECTED = None
@ -37,11 +38,11 @@ except ImportError:
else:
toolkit = hildon
try :
try:
import conic
except ImportError:
warning("conic is not found")
conic = FakeConic()
conic = FakeConic() # NOQA
from logging import debug
@ -70,7 +71,7 @@ class MasstransitHildon():
self.refresh_in_progress = False
self.connected = False
self.weboob = weboob
try :
try:
self.connection = conic.Connection()
self.connection.connect("connection-event", self.connect_event)
self.connection.set_property("automatic-connection-events", True)
@ -80,7 +81,7 @@ class MasstransitHildon():
horizontal_box = gtk.HBox()
self.main_window = toolkit.Window()
try :
try:
self.refresh_button = toolkit.Button(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
hildon.BUTTON_ARRANGEMENT_HORIZONTAL,
@ -223,7 +224,7 @@ class MasstransitHildon():
"the refresh button is clicked"
debug("on_refresh_button_clicked")
self.refresh_in_progress = True
try :
try:
self.connection.request_connection(conic.CONNECT_FLAG_NONE)
except AttributeError:
if isinstance(conic, FakeConic):
@ -232,7 +233,7 @@ class MasstransitHildon():
raise
def check_station_input(self, widget, user_data):
if self.combo_source.get_current_text() is None :
if self.combo_source.get_current_text() is None:
self.picker_button_dest.set_sensitive(False)
self.refresh_button.set_sensitive(False)
self.retour_button.set_sensitive(False)
@ -251,7 +252,7 @@ class MasstransitHildon():
banner.set_timeout(10000)
hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 1)
self.treestore.clear()
try :
try:
source_text = self.combo_source.get_current_text()
dest_text = self.combo_dest.get_current_text()
except AttributeError:

View file

@ -30,7 +30,7 @@ try:
import tty, termios
except ImportError:
PROMPT = '--Press return to continue--'
def readch():
def readch(): # NOQA
return sys.stdin.readline()
else:
PROMPT = '--Press a key to continue--'
@ -163,7 +163,6 @@ class IFormatter(object):
self.output(formatted)
return formatted
def format_obj(self, obj, alias=None):
"""
Format an object to be human-readable.

View file

@ -26,8 +26,7 @@ from PyQt4.QtCore import QTimer, SIGNAL, QObject, QString, QSize, QVariant, QMut
from PyQt4.QtGui import QMainWindow, QApplication, QStyledItemDelegate, \
QStyleOptionViewItemV4, QTextDocument, QStyle, \
QAbstractTextDocumentLayout, QPalette, QMessageBox, \
QSpinBox, QLineEdit, QComboBox, QCheckBox, QInputDialog, \
QLineEdit
QSpinBox, QLineEdit, QComboBox, QCheckBox, QInputDialog
from weboob.core.ouiboube import Weboob
from weboob.core.scheduler import IScheduler

View file

@ -21,7 +21,7 @@
try:
import sqlite3 as sqlite
except ImportError, e:
from pysqlite2 import dbapi2 as sqlite
from pysqlite2 import dbapi2 as sqlite # NOQA
from mechanize import CookieJar, Cookie
@ -47,7 +47,8 @@ class FirefoxCookieJar(CookieJar):
def load(self):
db = self.__connect()
if not db: return
if not db:
return
cookies = db.execute("""SELECT host, path, name, value, expiry, lastAccessed, isSecure
FROM moz_cookies
@ -83,12 +84,15 @@ class FirefoxCookieJar(CookieJar):
def save(self):
db = self.__connect()
if not db: return
if not db:
return
db.execute("DELETE FROM moz_cookies WHERE host LIKE '%%%s%%'" % self.domain)
for cookie in self:
if cookie.secure: secure = 1
else: secure = 0
if cookie.secure:
secure = 1
else:
secure = 0
if cookie.expires is not None:
expires = cookie.expires
else:

View file

@ -29,8 +29,8 @@ try:
from yaml import CLoader as Loader
from yaml import CDumper as Dumper
except ImportError:
from yaml import Loader
from yaml import Dumper
from yaml import Loader # NOQA
from yaml import Dumper # NOQA
from .iconfig import IConfig, ConfigError

View file

@ -27,4 +27,4 @@ try:
import simplejson as json
except ImportError:
# Python 2.6+ has a module similar to simplejson
import json
import json # NOQA

View file

@ -22,16 +22,15 @@ try:
from collections import OrderedDict
except ImportError:
try:
from simplejson import OrderedDict
from simplejson import OrderedDict # NOQA
except ImportError:
try:
from ordereddict import OrderedDict
from ordereddict import OrderedDict # NOQA
except ImportError:
## {{{ http://code.activestate.com/recipes/576693/ (r6)
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
class OrderedDict(dict, DictMixin): # NOQA
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
@ -123,7 +122,7 @@ except ImportError:
def __eq__(self, other):
if isinstance(other, OrderedDict):
return len(self)==len(other) and self.items() == other.items()
return len(self) == len(other) and self.items() == other.items()
return dict.__eq__(self, other)
def __ne__(self, other):

View file

@ -30,7 +30,7 @@ from elementtidy import TidyHTMLTreeBuilder
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
from xml.etree import ElementTree
from xml.etree import ElementTree # NOQA
from .iparser import IParser

View file

@ -22,7 +22,7 @@ from html5lib import treebuilders, HTMLParser
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
from xml.etree import ElementTree
from xml.etree import ElementTree # NOQA
from .iparser import IParser

View file

@ -23,7 +23,7 @@ import htmlentitydefs
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
from xml.etree import ElementTree
from xml.etree import ElementTree # NOQA
from .iparser import IParser
@ -68,6 +68,7 @@ class HTMLTreeBuilder(_HTMLParser):
except:
pass
class HTMLParser(IParser):
def parse(self, data, encoding=None):
parser = HTMLTreeBuilder(encoding)