From 20484bb01345985e10501b701808b237905f27ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 5 Mar 2015 11:32:18 +0100 Subject: [PATCH] Fix formatting in logger calls --- trytond/backend/mysql/table.py | 28 ++++++++++----------- trytond/backend/postgresql/database.py | 5 ++-- trytond/backend/postgresql/table.py | 23 +++++++++-------- trytond/backend/sqlite/table.py | 34 +++++++++++++------------- trytond/convert.py | 8 +++--- trytond/ir/cron.py | 4 +-- trytond/ir/ui/view.py | 10 ++++---- trytond/modules/__init__.py | 12 ++++----- trytond/pool.py | 2 +- trytond/protocols/dispatcher.py | 22 ++++++++--------- trytond/protocols/webdav.py | 4 +-- trytond/server.py | 16 ++++++------ 12 files changed, 84 insertions(+), 84 deletions(-) diff --git a/trytond/backend/mysql/table.py b/trytond/backend/mysql/table.py index ea9ea3b59e..59d68a1342 100644 --- a/trytond/backend/mysql/table.py +++ b/trytond/backend/mysql/table.py @@ -188,8 +188,8 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from %s to %s.', - (column_name, self.table_name, - self._columns[column_name]['typname'], base_type)) + column_name, self.table_name, + self._columns[column_name]['typname'], base_type) if (base_type == 'varchar' and self._columns[column_name]['typname'] == 'varchar'): # Migrate size @@ -202,10 +202,10 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from varchar(%s) to varchar(%s).', - (column_name, self.table_name, - self._columns[column_name]['size'] > 0 - and self._columns[column_name]['size'] or 255, - field_size)) + column_name, self.table_name, + self._columns[column_name]['size'] > 0 + and self._columns[column_name]['size'] or 255, + field_size) return column_type = column_type[1] @@ -304,9 +304,9 @@ class TableHandler(TableHandlerInterface): 'If it doesn\'t work, update records ' 'and execute manually:\n' 'ALTER TABLE `%s` MODIFY COLUMN `%s` %s', - (column_name, self.table_name, self.table_name, - column_name, self._column_definition(column_name, - nullable=False))) + column_name, self.table_name, self.table_name, + column_name, self._column_definition(column_name, + nullable=False)) elif action == 'remove': if self._columns[column_name]['nullable']: return @@ -337,9 +337,9 @@ class TableHandler(TableHandlerInterface): 'unable to add \'%s\' constraint on table %s !\n' 'If you want to have it, you should update the records ' 'and execute manually:\n' - 'ALTER table `%s` ADD CONSTRAINT `%s` %s' - % (constraint, self.table_name, self.table_name, ident, - constraint,), exc_info=True) + 'ALTER table `%s` ADD CONSTRAINT `%s` %s', + constraint, self.table_name, self.table_name, ident, + constraint, exc_info=True) self._update_definitions() def drop_constraint(self, ident, exception=False, table=None): @@ -355,7 +355,7 @@ class TableHandler(TableHandlerInterface): raise logger.warning( 'unable to drop \'%s\' constraint on table %s!', - (ident, self.table_name)) + ident, self.table_name) self._update_definitions() def drop_column(self, column_name, exception=False): @@ -371,7 +371,7 @@ class TableHandler(TableHandlerInterface): raise logger.warning( 'unable to drop \'%s\' column on table %s!', - (column_name, self.table_name)) + column_name, self.table_name) self._update_definitions() @staticmethod diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index 4426ec0236..b5fb1dd6d2 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -26,6 +26,8 @@ from sql import Flavor __all__ = ['Database', 'DatabaseIntegrityError', 'DatabaseOperationalError', 'Cursor'] +logger = logging.getLogger(__name__) + RE_VERSION = re.compile(r'\S+ (\d+)\.(\d+)') os.environ['PGTZ'] = os.environ.get('TZ', '') @@ -52,8 +54,7 @@ class Database(DatabaseInterface): def connect(self): if self._connpool is not None: return self - logger = logging.getLogger('database') - logger.info('connect to "%s"' % self.database_name) + logger.info('connect to "%s"', self.database_name) uri = parse_uri(config.get('database', 'uri')) assert uri.scheme == 'postgresql' host = uri.hostname and "host=%s" % uri.hostname or '' diff --git a/trytond/backend/postgresql/table.py b/trytond/backend/postgresql/table.py index 35bcc61716..3256fd90b2 100644 --- a/trytond/backend/postgresql/table.py +++ b/trytond/backend/postgresql/table.py @@ -230,8 +230,8 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from %s to %s.', - (column_name, self.table_name, - self._columns[column_name]['typname'], base_type)) + column_name, self.table_name, + self._columns[column_name]['typname'], base_type) if (base_type == 'varchar' and self._columns[column_name]['typname'] == 'varchar'): @@ -248,10 +248,10 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from varchar(%s) to varchar(%s).', - (column_name, self.table_name, - self._columns[column_name]['size'] > 0 and - self._columns[column_name]['size'] or "", - field_size)) + column_name, self.table_name, + self._columns[column_name]['size'] > 0 and + self._columns[column_name]['size'] or "", + field_size) return column_type = column_type[1] @@ -360,8 +360,7 @@ class TableHandler(TableHandlerInterface): 'If it doesn\'t work, update records ' 'and execute manually:\n' 'ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL', - (column_name, self.table_name, self.table_name, - column_name)) + column_name, self.table_name, self.table_name, column_name) elif action == 'remove': if not self._columns[column_name]['notnull']: return @@ -392,8 +391,8 @@ class TableHandler(TableHandlerInterface): 'If you want to have it, you should update the records ' 'and execute manually:\n' 'ALTER table "%s" ADD CONSTRAINT "%s" %s', - (constraint, self.table_name, self.table_name, ident, - constraint)) + constraint, self.table_name, self.table_name, ident, + constraint) self._update_definitions() def drop_constraint(self, ident, exception=False, table=None): @@ -409,7 +408,7 @@ class TableHandler(TableHandlerInterface): raise logger.warning( 'unable to drop \'%s\' constraint on table %s!', - (ident, self.table_name)) + ident, self.table_name) self._update_definitions() def drop_column(self, column_name, exception=False): @@ -425,7 +424,7 @@ class TableHandler(TableHandlerInterface): raise logger.warning( 'unable to drop \'%s\' column on table %s!', - (column_name, self.table_name), exc_info=True) + column_name, self.table_name, exc_info=True) self._update_definitions() @staticmethod diff --git a/trytond/backend/sqlite/table.py b/trytond/backend/sqlite/table.py index 9fd13da281..0e7317be1d 100644 --- a/trytond/backend/sqlite/table.py +++ b/trytond/backend/sqlite/table.py @@ -164,19 +164,19 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to alter size of column %s ' 'of table %s!', - (column_name, self.table_name)) + column_name, self.table_name) def alter_type(self, column_name, column_type): logger.warning( 'Unable to alter type of column %s ' 'of table %s!', - (column_name, self.table_name)) + column_name, self.table_name) def db_default(self, column_name, value): logger.warning( 'Unable to set default on column %s ' 'of table %s!', - (column_name, self.table_name)) + column_name, self.table_name) def add_raw_column(self, column_name, column_type, column_format, default_fun=None, field_size=None, migrate=True, string=''): @@ -196,8 +196,8 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from %s to %s.', - (column_name, self.table_name, - self._columns[column_name]['typname'], base_type)) + column_name, self.table_name, + self._columns[column_name]['typname'], base_type) if (base_type == 'VARCHAR' and self._columns[column_name]['typname'] == 'VARCHAR'): @@ -214,10 +214,10 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to migrate column %s on table %s ' 'from varchar(%s) to varchar(%s).', - (column_name, self.table_name, - self._columns[column_name]['size'] > 0 - and self._columns[column_name]['size'] or "", - field_size)) + column_name, self.table_name, + self._columns[column_name]['size'] > 0 + and self._columns[column_name]['size'] or "", + field_size) return column_type = column_type[1] @@ -242,12 +242,12 @@ class TableHandler(TableHandlerInterface): def add_fk(self, column_name, reference, on_delete=None): logger.warning( 'Unable to add foreign key on table %s!', - (self.table_name,)) + self.table_name) def drop_fk(self, column_name, table=None): logger.warning( 'Unable to drop foreign key on table %s!', - (self.table_name,)) + self.table_name) def index_action(self, column_name, action='add', table=None): if isinstance(column_name, basestring): @@ -282,29 +282,29 @@ class TableHandler(TableHandlerInterface): logger.warning( 'Unable to set not null on column %s ' 'of table %s!', - (column_name, self.table_name)) + column_name, self.table_name) elif action == 'remove': logger.warning( 'Unable to remove not null on column %s ' 'of table %s!', - (column_name, self.table_name)) + column_name, self.table_name) else: raise Exception('Not null action not supported!') def add_constraint(self, ident, constraint, exception=False): logger.warning( 'Unable to add constraint on table %s!', - (self.table_name,)) + self.table_name) def drop_constraint(self, ident, exception=False, table=None): logger.warning( 'Unable to drop constraint on table %s!', - (self.table_name,)) + self.table_name) def drop_column(self, column_name, exception=False): logger.warning( - 'Unable to drop \'%s\' column on table %s!', - (column_name, self.table_name)) + 'Unable to drop "%s" column on table %s!', + column_name, self.table_name) @staticmethod def drop_table(cursor, model, table, cascade=False): diff --git a/trytond/convert.py b/trytond/convert.py index beee036114..95d603bac5 100644 --- a/trytond/convert.py +++ b/trytond/convert.py @@ -670,7 +670,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler): logger.warning( "Field %s of %s@%s not updated (id: %s), because " "it has changed since the last update", - (key, record.id, model, fs_id)) + key, record.id, model, fs_id) continue # so, the field in the fs and in the db are different, @@ -794,7 +794,7 @@ def post_import(pool, module, to_delete): for mrec in mdata: model, db_id = mrec.model, mrec.db_id - logger.info('Deleting %s@%s', (db_id, model)) + logger.info('Deleting %s@%s', db_id, model) try: # Deletion of the record try: @@ -807,7 +807,7 @@ def post_import(pool, module, to_delete): else: logger.warning( 'Could not delete id %d of model %s because model no ' - 'longer exists.', (db_id, model)) + 'longer exists.', db_id, model) cursor.commit() except Exception: cursor.rollback() @@ -817,7 +817,7 @@ def post_import(pool, module, to_delete): 'that points to this resource\n' 'You should manually fix this ' 'and restart --update=module\n', - (db_id, model), exc_info=True) + db_id, model, exc_info=True) if 'active' in Model._fields: Model.write([Model(db_id)], { 'active': False, diff --git a/trytond/ir/cron.py b/trytond/ir/cron.py index 4ee955c857..336def8e63 100644 --- a/trytond/ir/cron.py +++ b/trytond/ir/cron.py @@ -151,7 +151,7 @@ class Cron(ModelSQL, ModelView): server.quit() except Exception: logger.error('Unable to deliver email:\n %s', - (msg.as_string(),), exc_info=True) + msg.as_string(), exc_info=True) @classmethod def _callback(cls, cron): @@ -203,4 +203,4 @@ class Cron(ModelSQL, ModelView): transaction.cursor.commit() except Exception: transaction.cursor.rollback() - logger.error('Running cron %s', (cron.id,), exc_info=True) + logger.error('Running cron %s', cron.id, exc_info=True) diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 84f959a5d0..04de1732e8 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -141,8 +141,8 @@ class View(ModelSQL, ModelView): if not validator.validate(tree): error_log = reduce(lambda x, y: str(x) + '\n' + str(y), validator.error_log.filter_from_errors()) - logger.error('Invalid xml view:\n%s' - % (str(error_log) + '\n' + xml)) + logger.error('Invalid xml view:\n%s', + str(error_log) + '\n' + xml) cls.raise_user_error('invalid_xml', (view.rec_name,)) root_element = tree.getroottree().getroot() @@ -159,9 +159,9 @@ class View(ModelSQL, ModelView): validates.get(attr, lambda a: True)(value) except Exception, e: logger.error('Invalid pyson view element "%s:%s":' - '\n%s\n%s' - % (element.get('id') or element.get('name'), - attr, str(e), xml)) + '\n%s\n%s', + element.get('id') or element.get('name'), attr, + str(e), xml) return False for child in element: if not encode(child): diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index 676025a5d8..f58c5266c7 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -229,7 +229,7 @@ def load_module_graph(graph, pool, update=None, lang=None): module2state[child.name] = package_state for type in classes.keys(): for cls in classes[type]: - logger.info('%s:register %s' % (module, cls.__name__)) + logger.info('%s:register %s', module, cls.__name__) cls.__register__(module) for model in classes['model']: if hasattr(model, '_history'): @@ -241,7 +241,7 @@ def load_module_graph(graph, pool, update=None, lang=None): for filename in package.info.get('xml', []): filename = filename.replace('/', os.sep) - logger.info('%s:loading %s' % (module, filename)) + logger.info('%s:loading %s', module, filename) # Feed the parser with xml content: with tools.file_open(OPJ(module, filename)) as fp: tryton_parser.parse_xmlstream(fp) @@ -254,8 +254,8 @@ def load_module_graph(graph, pool, update=None, lang=None): lang2 = os.path.splitext(os.path.basename(filename))[0] if lang2 not in lang: continue - logger.info('%s:loading %s' % (module, - filename[len(package.info['directory']) + 1:])) + logger.info('%s:loading %s', module, + filename[len(package.info['directory']) + 1:]) Translation = pool.get('ir.translation') Translation.translation_import(lang2, module, filename) @@ -279,7 +279,7 @@ def load_module_graph(graph, pool, update=None, lang=None): for model_name in models_to_update_history: model = pool.get(model_name) if model._history: - logger.info('history:update %s' % model.__name__) + logger.info('history:update %s', model.__name__) model._update_history_table() # Vacuum : @@ -322,7 +322,7 @@ def register_classes(): for package in create_graph(get_module_list())[0]: module = package.name - logger.info('%s:registering classes' % module) + logger.info('%s:registering classes', module) if module in ('ir', 'res', 'webdav', 'tests'): MODULES.append(module) diff --git a/trytond/pool.py b/trytond/pool.py index 5aa1780d63..7bdd4c4cec 100644 --- a/trytond/pool.py +++ b/trytond/pool.py @@ -146,7 +146,7 @@ class Pool(object): # Don't reset pool if already init and not to update if not update and self._pool.get(self.database_name): return - logger.info('init pool for "%s"', (self.database_name,)) + logger.info('init pool for "%s"', self.database_name) self._pool.setdefault(self.database_name, {}) # Clean the _pool before loading modules for type in self.classes.keys(): diff --git a/trytond/protocols/dispatcher.py b/trytond/protocols/dispatcher.py index 06b996d633..c78f469bab 100644 --- a/trytond/protocols/dispatcher.py +++ b/trytond/protocols/dispatcher.py @@ -43,14 +43,14 @@ def dispatch(host, port, protocol, database_name, user, session, object_type, Cache.clean(database_name) Cache.resets(database_name) msg = res and 'successful login' or 'bad login or password' - logger.info('%s \'%s\' from %s:%d using %s on database \'%s\'' - % (msg, user, host, port, protocol, database_name)) + logger.info('%s \'%s\' from %s:%d using %s on database \'%s\'', + msg, user, host, port, protocol, database_name) return res or False elif method == 'logout': name = security.logout(database_name, user, session) - logger.info(('logout \'%s\' from %s:%d ' - 'using %s on database \'%s\'') - % (name, host, port, protocol, database_name)) + logger.info('logout \'%s\' from %s:%d ' + 'using %s on database \'%s\'', + name, host, port, protocol, database_name) return True elif method == 'version': return VERSION @@ -247,10 +247,10 @@ def create(database_name, password, lang, admin_password): transaction.cursor.commit() res = True except Exception: - logger.error('CREATE DB: %s failed' % database_name, exc_info=True) + logger.error('CREATE DB: %s failed', database_name, exc_info=True) raise else: - logger.info('CREATE DB: %s' % (database_name,)) + logger.info('CREATE DB: %s', database_name) return res @@ -268,10 +268,10 @@ def drop(database_name, password): Database.drop(cursor, database_name) cursor.commit() except Exception: - logger.error('DROP DB: %s failed', (database_name,), exc_info=True) + logger.error('DROP DB: %s failed', database_name, exc_info=True) raise else: - logger.info('DROP DB: %s', (database_name,)) + logger.info('DROP DB: %s', database_name) Pool.stop(database_name) return True @@ -284,7 +284,7 @@ def dump(database_name, password): time.sleep(1) data = Database.dump(database_name) - logger.info('DUMP DB: %s' % (database_name)) + logger.info('DUMP DB: %s', database_name) return buffer(data) @@ -299,7 +299,7 @@ def restore(database_name, password, data, update=False): except Exception: pass Database.restore(database_name, data) - logger.info('RESTORE DB: %s' % (database_name)) + logger.info('RESTORE DB: %s', database_name) if update: with Transaction().start(database_name, 0) as transaction: cursor = transaction.cursor diff --git a/trytond/protocols/webdav.py b/trytond/protocols/webdav.py index 7a6734ca8d..089ec558b8 100644 --- a/trytond/protocols/webdav.py +++ b/trytond/protocols/webdav.py @@ -133,9 +133,9 @@ class TrytonDAVInterface(iface.dav_interface): if isinstance(exception, (NotLogged, ConcurrencyException, UserError, UserWarning, DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden)): - logger.debug('Exception %s', (exception,), exc_info=True) + logger.debug('Exception %s', exception, exc_info=True) else: - logger.error('Exception %s', (exception,), exc_info=True) + logger.error('Exception %s', exception, exc_info=True) @staticmethod def get_dburi(uri): diff --git a/trytond/server.py b/trytond/server.py index c89600b84a..b792460251 100644 --- a/trytond/server.py +++ b/trytond/server.py @@ -45,8 +45,8 @@ class TrytonServer(object): self.logger = logging.getLogger(__name__) if options.configfile: - self.logger.info('using %s as configuration file' - % options.configfile) + self.logger.info('using %s as configuration file', + options.configfile) else: self.logger.info('using default configuration') self.logger.info('initialising distributed objects services') @@ -188,24 +188,24 @@ class TrytonServer(object): for hostname, port in parse_listen( config.get('jsonrpc', 'listen')): self.jsonrpcd.append(JSONRPCDaemon(hostname, port, ssl)) - self.logger.info("starting JSON-RPC%s protocol on %s:%d" % - (ssl and ' SSL' or '', hostname or '*', port)) + self.logger.info("starting JSON-RPC%s protocol on %s:%d", + ssl and ' SSL' or '', hostname or '*', port) if config.get('xmlrpc', 'listen'): from trytond.protocols.xmlrpc import XMLRPCDaemon for hostname, port in parse_listen( config.get('xmlrpc', 'listen')): self.xmlrpcd.append(XMLRPCDaemon(hostname, port, ssl)) - self.logger.info("starting XML-RPC%s protocol on %s:%d" % - (ssl and ' SSL' or '', hostname or '*', port)) + self.logger.info("starting XML-RPC%s protocol on %s:%d", + ssl and ' SSL' or '', hostname or '*', port) if config.get('webdav', 'listen'): from trytond.protocols.webdav import WebDAVServerThread for hostname, port in parse_listen( config.get('webdav', 'listen')): self.webdavd.append(WebDAVServerThread(hostname, port, ssl)) - self.logger.info("starting WebDAV%s protocol on %s:%d" % - (ssl and ' SSL' or '', hostname or '*', port)) + self.logger.info("starting WebDAV%s protocol on %s:%d", + ssl and ' SSL' or '', hostname or '*', port) for servers in (self.xmlrpcd, self.jsonrpcd, self.webdavd): for server in servers: