X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=lcm%2Fosm_common%2Fdbmemory.py;h=cdb048285b5eccac892f849e691e798d2662e4e7;hb=ae501920e1c0e03c8571bece610dd5518e6e86b9;hp=75d1f883347472aa2c0ed05299ddfada16902e52;hpb=c887cc2fdd02c898ecd1f08d6927043027fd07eb;p=osm%2FRO.git diff --git a/lcm/osm_common/dbmemory.py b/lcm/osm_common/dbmemory.py index 75d1f883..cdb04828 100644 --- a/lcm/osm_common/dbmemory.py +++ b/lcm/osm_common/dbmemory.py @@ -1,14 +1,22 @@ -from dbbase import DbException, dbbase +import logging +from dbbase import DbException, DbBase from http import HTTPStatus from uuid import uuid4 from copy import deepcopy +__author__ = "Alfonso Tierno " -class dbmemory(dbbase): - def __init__(self): +class DbMemory(DbBase): + + def __init__(self, logger_name='db'): + self.logger = logging.getLogger(logger_name) self.db = {} + def db_connect(self, config): + if "logger_name" in config: + self.logger = logging.getLogger(config["logger_name"]) + @staticmethod def _format_filter(filter): return filter # TODO @@ -45,7 +53,7 @@ class dbmemory(dbbase): HTTPStatus.CONFLICT.value) l = row if not l and fail_on_empty: - raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND.value) + raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND) return deepcopy(l) except Exception as e: # TODO refine raise DbException(str(e)) @@ -70,7 +78,7 @@ class dbmemory(dbbase): break else: if fail_on_empty: - raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND.value) + raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND) return None del self.db[table][i] return {"deleted": 1} @@ -83,7 +91,7 @@ class dbmemory(dbbase): break else: if fail_on_empty: - raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND.value) + raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND) return None self.db[table][i] = deepcopy(indata) return {"upadted": 1}