[FIX] pep8, pylint, eyeballing

This commit is contained in:
Guewen Baconnier @ Camptocamp
2012-12-20 14:37:01 +01:00
parent a5979a9f45
commit 412d86809d
36 changed files with 673 additions and 540 deletions

View File

@@ -28,17 +28,18 @@ try:
except:
raise Exception(_('Please install python lib xlrd'))
class FileParser(BankStatementImportParser):
"""
Generic abstract class for defining parser for .csv or .xls file format.
"""
def __init__(self, parse_name, keys_to_validate=[], ftype='csv', convertion_dict=None, header=None, *args, **kwargs):
"""
:param char: parse_name : The name of the parser
:param list: keys_to_validate : contain the key that need to be present in the file
:param char ftype: extension of the file (could be csv or xls)
:param: convertion_dict : keys and type to convert of every column in the file like
:param: convertion_dict : keys and type to convert of every column in the file like
{
'ref': unicode,
'label': unicode,
@@ -48,7 +49,7 @@ class FileParser(BankStatementImportParser):
}
:param list: header : specify header fields if the csv file has no header
"""
super(FileParser, self).__init__(parse_name, *args, **kwargs)
if ftype in ('csv', 'xls'):
self.ftype = ftype
@@ -57,9 +58,9 @@ class FileParser(BankStatementImportParser):
self.keys_to_validate = keys_to_validate
self.convertion_dict = convertion_dict
self.fieldnames = header
self._datemode = 0 # used only for xls documents,
# 0 means Windows mode (1900 based dates).
# Set in _parse_xls, from the contents of the file
self._datemode = 0 # used only for xls documents,
# 0 means Windows mode (1900 based dates).
# Set in _parse_xls, from the contents of the file
def _custom_format(self, *args, **kwargs):
"""
@@ -78,7 +79,7 @@ class FileParser(BankStatementImportParser):
Launch the parsing through .csv or .xls depending on the
given ftype
"""
res = None
if self.ftype == 'csv':
res = self._parse_csv()
@@ -108,7 +109,6 @@ class FileParser(BankStatementImportParser):
self.result_row_list = self._cast_rows(*args, **kwargs)
return True
def _parse_csv(self):
"""
:return: list of dict from csv file (line/rows)
@@ -116,7 +116,7 @@ class FileParser(BankStatementImportParser):
csv_file = tempfile.NamedTemporaryFile()
csv_file.write(self.filebuffer)
csv_file.flush()
with open(csv_file.name, 'rU') as fobj:
with open(csv_file.name, 'rU') as fobj:
reader = UnicodeDictReader(fobj, fieldnames=self.fieldnames)
return list(reader)
@@ -138,7 +138,7 @@ class FileParser(BankStatementImportParser):
try:
wb_file.close()
except Exception, e:
pass #file is allready closed
pass # file is already closed
return res
def _from_csv(self, result_set, conversion_rules):
@@ -175,6 +175,6 @@ class FileParser(BankStatementImportParser):
Convert the self.result_row_list using the self.convertion_dict providen.
We call here _from_xls or _from_csv depending on the self.ftype variable.
"""
func = getattr(self, '_from_%s'%(self.ftype))
func = getattr(self, '_from_%s' % self.ftype)
res = func(self.result_row_list, self.convertion_dict)
return res