1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-04-18 23:19:57 +02:00

Moved both classes un lodel/plugin/datasource_plugin.py + check inheritance

Implements the check of the bases classes of a datasource class in a datasource plugin ( solves #144 )
This commit is contained in:
Yann 2016-09-07 17:26:08 +02:00
commit c7553748f0

View file

@ -5,6 +5,75 @@ from lodel.settings.validator import SettingValidator
_glob_typename = 'datasource'
##@brief Datasource class in plugins HAVE TO inherit from this abstract class
class AbstractDatasource(object):
##@brief Trigger LodelFatalError when abtract method called
@staticmethod
def _abs_err():
raise LodelFatalError("This method is abstract and HAVE TO be \
reimplemented by plugin datasource child class")
##@brief The constructor
def __init__(self, *conn_args, **conn_kwargs):
self._abs_err()
##@brief Provide a new uniq numeric ID
#@param emcomp LeObject subclass (not instance) : To know on wich things we
#have to be uniq
#@return an integer
def new_numeric_id(self, emcomp):
self._abs_err()
##@brief returns a selection of documents from the datasource
#@param target_cls Emclass
#@param field_list list
#@param filters list : List of filters
#@param rel_filters list : List of relational filters
#@param order list : List of column to order. ex: order = [('title', 'ASC'),]
#@param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
#@param limit int : Number of records to be returned
#@param offset int: used with limit to choose the start record
#@param instanciate bool : If true, the records are returned as instances, else they are returned as dict
#@return list
def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
instanciate=True):
self._abs_err()
##@brief Deletes records according to given filters
#@param target Emclass : class of the record to delete
#@param filters list : List of filters
#@param relational_filters list : List of relational filters
#@return int : number of deleted records
def delete(self, target, filters, relational_filters):
self._abs_err()
## @brief updates records according to given filters
#@param target Emclass : class of the object to insert
#@param filters list : List of filters
#@param relational_filters list : List of relational filters
#@param upd_datas dict : datas to update (new values)
#@return int : Number of updated records
def update(self, target, filters, relational_filters, upd_datas):
self._abs_err()
## @brief Inserts a record in a given collection
# @param target Emclass : class of the object to insert
# @param new_datas dict : datas to insert
# @return the inserted uid
def insert(self, target, new_datas):
self._abs_err()
## @brief Inserts a list of records in a given collection
# @param target Emclass : class of the objects inserted
# @param datas_list list : list of dict
# @return list : list of the inserted records' ids
def insert_multi(self, target, datas_list):
self._abs_err()
##@brief Designed to handles datasources plugins
#
#A datasource provide data access to LeAPI typically a connector on a DB
@ -41,6 +110,10 @@ class DatasourcePlugin(Plugin):
def datasource_cls(self):
if self.__datasource_cls is None:
self.__datasource_cls = self.loader_module().Datasource
if not issubclass(self.__datasource_cls, AbstractDatasource):
raise DatasourcePluginError("The datasource class of the \
'%s' plugin is not a child class of \
lodel.plugin.datasource_plugin.AbstractDatasource" % (self.name))
return self.__datasource_cls
##@brief Accessor to migration handler class
@ -163,70 +236,6 @@ but %s is a %s" % (ds_name, pinstance.__class__.__name__))
def get_migration_handler(cls, ds_plugin_name):
return cls.get(ds_plugin_name).migration_handler_cls()
class AbstractDatasource(object):
##@brief Trigger LodelFatalError when abtract method called
@staticmethod
def _abs_err():
raise LodelFatalError("This method is abstract and HAVE TO be \
reimplemented by plugin datasource child class")
##@brief The constructor
def __init__(self, *conn_args, **conn_kwargs):
self._abs_err()
##@brief Provide a new uniq numeric ID
#@param emcomp LeObject subclass (not instance) : To know on wich things we
#have to be uniq
#@return an integer
def new_numeric_id(self, emcomp):
self._abs_err()
##@brief returns a selection of documents from the datasource
#@param target_cls Emclass
#@param field_list list
#@param filters list : List of filters
#@param rel_filters list : List of relational filters
#@param order list : List of column to order. ex: order = [('title', 'ASC'),]
#@param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
#@param limit int : Number of records to be returned
#@param offset int: used with limit to choose the start record
#@param instanciate bool : If true, the records are returned as instances, else they are returned as dict
#@return list
def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
instanciate=True):
self._abs_err()
##@brief Deletes records according to given filters
#@param target Emclass : class of the record to delete
#@param filters list : List of filters
#@param relational_filters list : List of relational filters
#@return int : number of deleted records
def delete(self, target, filters, relational_filters):
self._abs_err()
## @brief updates records according to given filters
#@param target Emclass : class of the object to insert
#@param filters list : List of filters
#@param relational_filters list : List of relational filters
#@param upd_datas dict : datas to update (new values)
#@return int : Number of updated records
def update(self, target, filters, relational_filters, upd_datas):
self._abs_err()
## @brief Inserts a record in a given collection
# @param target Emclass : class of the object to insert
# @param new_datas dict : datas to insert
# @return the inserted uid
def insert(self, target, new_datas):
self._abs_err()
## @brief Inserts a list of records in a given collection
# @param target Emclass : class of the objects inserted
# @param datas_list list : list of dict
# @return list : list of the inserted records' ids
def insert_multi(self, target, datas_list):
self._abs_err()
##@page lodel2_datasources Lodel2 datasources
#