Fixed pylint warnings

This commit is contained in:
Fabio Manganiello 2019-07-13 22:36:45 +02:00
parent 0826dd53a6
commit 674c164fc1
2 changed files with 21 additions and 13 deletions

View file

@ -22,6 +22,11 @@ class NfcBackend(Backend):
Requires: Requires:
* **nfcpy** >= 1.0 (``pip install nfcpy``) * **nfcpy** >= 1.0 (``pip install nfcpy``)
Run the following to check if your device is compatible with nfcpy and the right permissions are set::
python -m nfc
""" """
def __init__(self, device='usb', *args, **kwargs): def __init__(self, device='usb', *args, **kwargs):

View file

@ -6,6 +6,7 @@ from sqlalchemy import create_engine, Table, MetaData
from platypush.plugins import Plugin, action from platypush.plugins import Plugin, action
class DbPlugin(Plugin): class DbPlugin(Plugin):
""" """
Database plugin. It allows you to programmatically select, insert, update Database plugin. It allows you to programmatically select, insert, update
@ -29,20 +30,20 @@ class DbPlugin(Plugin):
super().__init__() super().__init__()
self.engine = self._get_engine(engine, *args, **kwargs) self.engine = self._get_engine(engine, *args, **kwargs)
def _get_engine(self, engine=None, *args, **kwargs): def _get_engine(self, engine=None, *args, **kwargs):
if engine: if engine:
return create_engine(engine, *args, **kwargs) return create_engine(engine, *args, **kwargs)
else: else:
return self.engine return self.engine
def _build_condition(self, table, column, value): @staticmethod
def _build_condition(table, column, value):
if isinstance(value, str): if isinstance(value, str):
value = "'{}'".format(value) value = "'{}'".format(value)
elif not isinstance(value, int) and not isinstance(value, 'float'): elif not isinstance(value, int) and not isinstance(value, float):
value = "'{}'".format(str(value)) value = "'{}'".format(str(value))
return eval('table.c.{}=={}'.format(column, value)) return eval('{}.{}=={}'.format(table, column, value))
@action @action
def execute(self, statement, engine=None, *args, **kwargs): def execute(self, statement, engine=None, *args, **kwargs):
@ -69,7 +70,6 @@ class DbPlugin(Plugin):
with engine.connect() as connection: with engine.connect() as connection:
result = connection.execute(statement) result = connection.execute(statement)
@action @action
def select(self, query=None, table=None, filter=None, engine=None, *args, **kwargs): def select(self, query=None, table=None, filter=None, engine=None, *args, **kwargs):
""" """
@ -77,14 +77,18 @@ class DbPlugin(Plugin):
:param query: SQL to be executed :param query: SQL to be executed
:type query: str :type query: str
:param filter: Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex SQL logic. :param filter: Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL
in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex
SQL logic.
:type filter: dict :type filter: dict
:param table: If you specified a filter instead of a raw query, you'll have to specify the target table :param table: If you specified a filter instead of a raw query, you'll have to specify the target table
:type table: str :type table: str
:param engine: Engine to be used (default: default class engine) :param engine: Engine to be used (default: default class engine)
:type engine: str :type engine: str
:param args: Extra arguments that will be passed to ``sqlalchemy.create_engine`` (see http://docs.sqlalchemy.org/en/latest/core/engines.html) :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine``
:param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine`` (see http://docs.sqlalchemy.org/en/latest/core/engines.html) (see http://docs.sqlalchemy.org/en/latest/core/engines.html)
:param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine``
(see http://docs.sqlalchemy.org/en/latest/core/engines.html)
:returns: List of hashes representing the result rows. :returns: List of hashes representing the result rows.
Examples: Examples:
@ -149,9 +153,8 @@ class DbPlugin(Plugin):
return rows return rows
@action @action
def insert(self, table, records, engine=None, key_columns=[], def insert(self, table, records, engine=None, key_columns=None,
on_duplicate_update=False, *args, **kwargs): on_duplicate_update=False, *args, **kwargs):
""" """
Inserts records (as a list of hashes) into a table. Inserts records (as a list of hashes) into a table.
@ -195,6 +198,9 @@ class DbPlugin(Plugin):
} }
""" """
if key_columns is None:
key_columns = []
db = self._get_engine(engine, *args, **kwargs) db = self._get_engine(engine, *args, **kwargs)
for record in records: for record in records:
@ -212,7 +218,6 @@ class DbPlugin(Plugin):
else: else:
raise e raise e
@action @action
def update(self, table, records, key_columns, engine=None, *args, **kwargs): def update(self, table, records, key_columns, engine=None, *args, **kwargs):
""" """
@ -272,7 +277,6 @@ class DbPlugin(Plugin):
update = update.values(**values) update = update.values(**values)
engine.execute(update) engine.execute(update)
@action @action
def delete(self, table, records, engine=None, *args, **kwargs): def delete(self, table, records, engine=None, *args, **kwargs):
""" """
@ -320,4 +324,3 @@ class DbPlugin(Plugin):
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: