From 19867c5119053d0f3d27eb293a07413b3daea564 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Nov 2013 11:42:59 +0100 Subject: [PATCH] [PEP8] doc string --- async_move_line_importer/model/account.py | 29 ++++++++++----- .../model/move_line_importer.py | 35 +++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/async_move_line_importer/model/account.py b/async_move_line_importer/model/account.py index 3cdf13f79..5d63d06c4 100644 --- a/async_move_line_importer/model/account.py +++ b/async_move_line_importer/model/account.py @@ -33,18 +33,22 @@ def _format_inserts_values(vals): class account_move(orm.Model): - """redefine account move create to bypass orm - if async_bypass_create is set to True in context""" + """redefine account move create to bypass orm. + + Async_bypass_create must be set to True in context. + + """ _inherit = "account.move" def _prepare_line(self, cr, uid, move_id, line, vals, context=None): - """Take incomming move vals and complete move line dict with - missing data + """Take incomming move vals and complete move line dict with missing data + :param move_id: parent move id :param line: dict of vals of move line :param vals: dict of vals of move :returns: dict of val of move line completed + """ if isinstance(line, tuple): line = line[2] @@ -65,7 +69,10 @@ class account_move(orm.Model): def _bypass_create(self, cr, uid, vals, context=None): """Create entries using cursor directly - :returns: created id""" + + :returns: created id + + """ mvl_obj = self.pool['account.move.line'] vals['company_id'] = context.get('company_id', False) vals['state'] = 'draft' @@ -96,8 +103,11 @@ class account_move(orm.Model): class account_move_line(orm.Model): - """redefine account move line create to bypass orm - if async_bypass_create is set to True in context""" + """Redefine account move line create to bypass orm. + + Async_bypass_create must be set to True in context + + """ _inherit = "account.move.line" @@ -111,7 +121,10 @@ class account_move_line(orm.Model): def _bypass_create(self, cr, uid, vals, context=None): """Create entries using cursor directly - :returns: created id""" + + :returns: created id + + """ sql = u"Insert INTO account_move_line (%s) VALUES (%s) RETURNING id" sql = sql % _format_inserts_values(vals) try: diff --git a/async_move_line_importer/model/move_line_importer.py b/async_move_line_importer/model/move_line_importer.py index f22bdc930..84e095968 100644 --- a/async_move_line_importer/model/move_line_importer.py +++ b/async_move_line_importer/model/move_line_importer.py @@ -38,10 +38,13 @@ _logger = logging.getLogger(__name__) class move_line_importer(orm.Model): """Asynchrone move / move line importer. + It will parse the saved CSV file using orm.BaseModel.load in a thread. If you set bypass_orm to True then the load function will use a totally overriden create function that is a lot faster - but that totally bypass the ORM""" + but that totally bypass the ORM + + """ _name = "move.line.importer" _inherit = ['mail.thread'] @@ -110,9 +113,12 @@ class move_line_importer(orm.Model): def _parse_csv(self, cr, uid, imp_id): """Parse stored CSV file in order to be usable by BaseModel.load method. + Manage base 64 decoding. + :param imp_id: current importer id :returns: (head [list of first row], data [list of list]) + """ # We use tempfile in order to avoid memory error with large files with tempfile.TemporaryFile() as src: @@ -127,11 +133,12 @@ class move_line_importer(orm.Model): return self._prepare_csv_data(decoded, delimiter) def _prepare_csv_data(self, csv_file, delimiter=","): - """Parse a decoded CSV file and return head list - and data list + """Parse a decoded CSV file and return head list and data list + :param csv_file: decoded CSV file :param delimiter: CSV file delimiter char :returns: (head [list of first row], data [list of list]) + """ data = csv.reader(csv_file, delimiter=str(delimiter)) head = data.next() @@ -142,8 +149,10 @@ class move_line_importer(orm.Model): def format_messages(self, messages): """Format error messages generated by the BaseModel.load method + :param messages: return of BaseModel.load messages key :returns: formatted string + """ res = [] for msg in messages: @@ -156,13 +165,16 @@ class move_line_importer(orm.Model): def _manage_load_results(self, cr, uid, imp_id, result, _do_commit=True, context=None): """Manage the BaseModel.load function output and store exception. + Will generate success/failure report and store it into report field. Manage commit and rollback even if load method uses PostgreSQL Savepoints. + :param imp_id: current importer id :param result: BaseModel.laod return {ids: list(int)|False, messages: [Message]} :param _do_commit: toggle commit management only used for testing purpose only :returns: current importer id + """ # Import sucessful state = msg = None @@ -178,13 +190,16 @@ class move_line_importer(orm.Model): def _write_report(self, cr, uid, imp_id, state, msg, _do_commit=True, max_tries=5, context=None): - """Commit report in a separated transaction in order to avoid - concurrent update error due to mail.message. + """Commit report in a separated transaction. + + It will avoid concurrent update error due to mail.message. If transaction trouble happen we try 5 times to rewrite report + :param imp_id: current importer id :param state: import state :param msg: report summary :returns: current importer id + """ if _do_commit: db_name = cr.dbname @@ -219,12 +234,15 @@ class move_line_importer(orm.Model): def _load_data(self, cr, uid, imp_id, head, data, _do_commit=True, context=None): """Function that does the load of parsed CSV file. + If will log exception and susccess into the report fields. + :param imp_id: current importer id :param head: CSV file head (list of header) :param data: CSV file content (list of data list) :param _do_commit: toggle commit management only used for testing purpose only :returns: current importer id + """ state = msg = None try: @@ -254,9 +272,11 @@ class move_line_importer(orm.Model): def _allows_thread(self, imp_id): """Check if there is a async import of this file running + :param imp_id: current importer id :returns: void :raise: orm.except in case on failure + """ for th in threading.enumerate(): if th.getName() == 'async_move_line_import_%s' % imp_id: @@ -274,11 +294,14 @@ class move_line_importer(orm.Model): def import_file(self, cr, uid, imp_id, context=None): """ Will do an asynchronous load of a CSV file. + Will generate an success/failure report and generate some maile threads. It uses BaseModel.load to lookup CSV. If you set bypass_orm to True then the load function will use a totally overriden create function that is a lot faster - but that totally bypass the ORM""" + but that totally bypass the ORM + + """ if isinstance(imp_id, list): imp_id = imp_id[0]