Skip to content
Snippets Groups Projects
Commit 7caf4d2c authored by Jakub Maloštík's avatar Jakub Maloštík
Browse files

Use python abc module instead of override_required

parent 0881a6bb
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
from __future__ import print_function from __future__ import print_function
import abc
import sys import sys
import os import os
import io import io
...@@ -133,17 +134,6 @@ class Error(Exception): ...@@ -133,17 +134,6 @@ class Error(Exception):
return d return d
def override_required(method):
def abstract_method(self, *args, **kwargs):
method(self, *args, **kwargs)
raise NotImplementedError(
"Class %s needs to implement the %s() method" %
(type(self).__name__, method.__name__)
)
abstract_method.__doc__ = method.__doc__
return abstract_method
def get_clean_root_logger(level=logging.INFO): def get_clean_root_logger(level=logging.INFO):
""" Attempts to get logging module into clean slate state """ """ Attempts to get logging module into clean slate state """
...@@ -509,7 +499,7 @@ class DataBase(ObjectBase): ...@@ -509,7 +499,7 @@ class DataBase(ObjectBase):
self.db = None self.db = None
self.con = None self.con = None
@override_required @abc.abstractmethod
def connect(self): def connect(self):
pass pass
...@@ -628,7 +618,7 @@ class DataBase(ObjectBase): ...@@ -628,7 +618,7 @@ class DataBase(ObjectBase):
def _get_not(self, b): def _get_not(self, b):
return "" if b else "NOT" return "" if b else "NOT"
@override_required @abc.abstractmethod
def _build_get_client_by_name(self, cert_names, name, secret): def _build_get_client_by_name(self, cert_names, name, secret):
"""Build query and params for client lookup""" """Build query and params for client lookup"""
...@@ -647,7 +637,7 @@ class DataBase(ObjectBase): ...@@ -647,7 +637,7 @@ class DataBase(ObjectBase):
return Client(**rows[0]) if rows else None return Client(**rows[0]) if rows else None
@override_required @abc.abstractmethod
def _build_get_clients(self, id): def _build_get_clients(self, id):
"""Build query and params for client lookup by id""" """Build query and params for client lookup by id"""
...@@ -659,7 +649,7 @@ class DataBase(ObjectBase): ...@@ -659,7 +649,7 @@ class DataBase(ObjectBase):
rows = db.query_all(query, params, ret=ret) rows = db.query_all(query, params, ret=ret)
return [Client(**row) for row in rows] return [Client(**row) for row in rows]
@override_required @abc.abstractmethod
def _build_add_modify_client(self, id, **kwargs): def _build_add_modify_client(self, id, **kwargs):
"""Build query and params for adding/modifying client""" """Build query and params for adding/modifying client"""
...@@ -675,11 +665,11 @@ class DataBase(ObjectBase): ...@@ -675,11 +665,11 @@ class DataBase(ObjectBase):
newid = res_id if id is None else id newid = res_id if id is None else id
return newid return newid
@override_required @abc.abstractmethod
def _build_get_debug_version(self): def _build_get_debug_version(self):
pass pass
@override_required @abc.abstractmethod
def _build_get_debug_tablestat(self): def _build_get_debug_tablestat(self):
pass pass
...@@ -707,13 +697,13 @@ class DataBase(ObjectBase): ...@@ -707,13 +697,13 @@ class DataBase(ObjectBase):
maps.append(mapped) maps.append(mapped)
return set(maps) # unique return set(maps) # unique
@override_required @abc.abstractmethod
def _build_fetch_events( def _build_fetch_events(
self, client, id, count, self, client, id, count,
cat, nocat, tag, notag, group, nogroup): cat, nocat, tag, notag, group, nogroup):
"""Build query and params for fetching events based on id, count and category, tag and group filters""" """Build query and params for fetching events based on id, count and category, tag and group filters"""
@override_required @abc.abstractmethod
def _load_event_json(self, data): def _load_event_json(self, data):
"""Return decoded json from data loaded from database, if unable to decode, return None""" """Return decoded json from data loaded from database, if unable to decode, return None"""
...@@ -770,15 +760,15 @@ class DataBase(ObjectBase): ...@@ -770,15 +760,15 @@ class DataBase(ObjectBase):
"events": events "events": events
} }
@override_required @abc.abstractmethod
def _build_store_events_event(self, client, event, raw_event): def _build_store_events_event(self, client, event, raw_event):
"""Build query and params for event insertion""" """Build query and params for event insertion"""
@override_required @abc.abstractmethod
def _build_store_events_categories(self, event_id, cat_ids): def _build_store_events_categories(self, event_id, cat_ids):
"""Build query and params for insertion of event-categories mapping""" """Build query and params for insertion of event-categories mapping"""
@override_required @abc.abstractmethod
def _build_store_events_tags(self, event_id, tag_ids): def _build_store_events_tags(self, event_id, tag_ids):
"""Build query and params for insertion of event-tags mapping""" """Build query and params for insertion of event-tags mapping"""
...@@ -809,7 +799,7 @@ class DataBase(ObjectBase): ...@@ -809,7 +799,7 @@ class DataBase(ObjectBase):
exception.log(self.log) exception.log(self.log)
return [{"error": 500, "message": "DB error %s" % type(e).__name__}] return [{"error": 500, "message": "DB error %s" % type(e).__name__}]
@override_required @abc.abstractmethod
def _build_insert_last_received_id(self, client, id): def _build_insert_last_received_id(self, client, id):
"""Build query and params for insertion of the last event id received by client""" """Build query and params for insertion of the last event id received by client"""
...@@ -820,7 +810,7 @@ class DataBase(ObjectBase): ...@@ -820,7 +810,7 @@ class DataBase(ObjectBase):
with attempt as db: with attempt as db:
db.execute(query, params) db.execute(query, params)
@override_required @abc.abstractmethod
def _build_get_last_event_id(self): def _build_get_last_event_id(self):
"""Build query and params for querying the id of the last inserted event""" """Build query and params for querying the id of the last inserted event"""
...@@ -831,7 +821,7 @@ class DataBase(ObjectBase): ...@@ -831,7 +821,7 @@ class DataBase(ObjectBase):
id_ = db.query_one(query, params, ret=ret)["id"] id_ = db.query_one(query, params, ret=ret)["id"]
return id_ or 1 return id_ or 1
@override_required @abc.abstractmethod
def _build_get_last_received_id(self, client): def _build_get_last_received_id(self, client):
"""Build query and params for querying the last event id received by client""" """Build query and params for querying the last event id received by client"""
...@@ -852,11 +842,11 @@ class DataBase(ObjectBase): ...@@ -852,11 +842,11 @@ class DataBase(ObjectBase):
return id return id
@override_required @abc.abstractmethod
def _build_load_maps_tags(self): def _build_load_maps_tags(self):
"""Build query and params for updating the tag map""" """Build query and params for updating the tag map"""
@override_required @abc.abstractmethod
def _build_load_maps_cats(self): def _build_load_maps_cats(self):
"""Build query and params for updating the catetgory map""" """Build query and params for updating the catetgory map"""
...@@ -867,7 +857,7 @@ class DataBase(ObjectBase): ...@@ -867,7 +857,7 @@ class DataBase(ObjectBase):
db.execute(tquery, tparams) db.execute(tquery, tparams)
db.execute(cquery, cparams) db.execute(cquery, cparams)
@override_required @abc.abstractmethod
def _build_purge_lastlog(self, days): def _build_purge_lastlog(self, days):
"""Build query and params for purging stored client last event mapping older than days""" """Build query and params for purging stored client last event mapping older than days"""
...@@ -876,11 +866,11 @@ class DataBase(ObjectBase): ...@@ -876,11 +866,11 @@ class DataBase(ObjectBase):
with self as db: with self as db:
return db.query_rowcount(query, params, ret=ret) return db.query_rowcount(query, params, ret=ret)
@override_required @abc.abstractmethod
def _build_purge_events_get_id(self, days): def _build_purge_events_get_id(self, days):
"""Build query and params to get largest event id of events older than days""" """Build query and params to get largest event id of events older than days"""
@override_required @abc.abstractmethod
def _build_purge_events_events(self, id_): def _build_purge_events_events(self, id_):
"""Build query and params to remove events older then days and their mappings""" """Build query and params to remove events older then days and their mappings"""
...@@ -895,6 +885,9 @@ class DataBase(ObjectBase): ...@@ -895,6 +885,9 @@ class DataBase(ObjectBase):
return affected return affected
DataBase = abc.ABCMeta("DataBase", (DataBase,), {})
class MySQL(DataBase): class MySQL(DataBase):
def __init__( def __init__(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment