Convert gen.lib to use abstract base classes
This commit is contained in:
parent
bb009aa276
commit
fe9af29bf5
@ -24,9 +24,10 @@ Base Object class for Gramps
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# standard python modules
|
# Standard Python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
import re
|
import re
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -34,7 +35,7 @@ import re
|
|||||||
# Base Object
|
# Base Object
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class BaseObject:
|
class BaseObject(metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
The BaseObject is the base class for all data objects in Gramps,
|
The BaseObject is the base class for all data objects in Gramps,
|
||||||
whether primary or not.
|
whether primary or not.
|
||||||
@ -43,18 +44,19 @@ class BaseObject:
|
|||||||
searching through all available information.
|
searching through all available information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Convert the object to a serialized tuple of data.
|
Convert the object to a serialized tuple of data.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def to_struct(self):
|
def to_struct(self):
|
||||||
"""
|
"""
|
||||||
Convert the data held in this object to a structure (eg,
|
Convert the data held in this object to a structure (eg,
|
||||||
@ -74,8 +76,8 @@ class BaseObject:
|
|||||||
|
|
||||||
:returns: Returns a struct containing the data of the object.
|
:returns: Returns a struct containing the data of the object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def from_struct(self, struct):
|
def from_struct(self, struct):
|
||||||
"""
|
"""
|
||||||
Given a struct data representation, return an object of this type.
|
Given a struct data representation, return an object of this type.
|
||||||
@ -90,7 +92,6 @@ class BaseObject:
|
|||||||
|
|
||||||
:returns: Returns an object of this type.
|
:returns: Returns an object of this type.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def matches_string(self, pattern, case_sensitive=False):
|
def matches_string(self, pattern, case_sensitive=False):
|
||||||
"""
|
"""
|
||||||
|
@ -23,6 +23,13 @@
|
|||||||
Basic Primary Object class for Gramps.
|
Basic Primary Object class for Gramps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Standard Python modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from abc import abstractmethod
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Gramps modules
|
# Gramps modules
|
||||||
@ -71,18 +78,19 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
|||||||
else:
|
else:
|
||||||
self.gramps_id = None
|
self.gramps_id = None
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Convert the object to a serialized tuple of data.
|
Convert the object to a serialized tuple of data.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def to_struct(self):
|
def to_struct(self):
|
||||||
"""
|
"""
|
||||||
Convert the data held in this object to a structure (eg,
|
Convert the data held in this object to a structure (eg,
|
||||||
@ -102,8 +110,8 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
|||||||
|
|
||||||
:returns: Returns a struct containing the data of the object.
|
:returns: Returns a struct containing the data of the object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def from_struct(self, struct):
|
def from_struct(self, struct):
|
||||||
"""
|
"""
|
||||||
Given a struct data representation, return an object of this type.
|
Given a struct data representation, return an object of this type.
|
||||||
@ -118,7 +126,6 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
|||||||
|
|
||||||
:returns: Returns an object of this type.
|
:returns: Returns an object of this type.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def set_gramps_id(self, gramps_id):
|
def set_gramps_id(self, gramps_id):
|
||||||
"""
|
"""
|
||||||
@ -259,18 +266,19 @@ class PrimaryObject(BasicPrimaryObject):
|
|||||||
"""
|
"""
|
||||||
BasicPrimaryObject.__init__(self, source)
|
BasicPrimaryObject.__init__(self, source)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Convert the object to a serialized tuple of data.
|
Convert the object to a serialized tuple of data.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def to_struct(self):
|
def to_struct(self):
|
||||||
"""
|
"""
|
||||||
Convert the data held in this object to a structure (eg,
|
Convert the data held in this object to a structure (eg,
|
||||||
@ -290,8 +298,8 @@ class PrimaryObject(BasicPrimaryObject):
|
|||||||
|
|
||||||
:returns: Returns a struct containing the data of the object.
|
:returns: Returns a struct containing the data of the object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def from_struct(self, struct):
|
def from_struct(self, struct):
|
||||||
"""
|
"""
|
||||||
Given a struct data representation, return an object of this type.
|
Given a struct data representation, return an object of this type.
|
||||||
@ -306,7 +314,6 @@ class PrimaryObject(BasicPrimaryObject):
|
|||||||
|
|
||||||
:returns: Returns an object of this type.
|
:returns: Returns an object of this type.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def has_handle_reference(self, classname, handle):
|
def has_handle_reference(self, classname, handle):
|
||||||
"""
|
"""
|
||||||
|
@ -22,12 +22,19 @@
|
|||||||
Base Reference class for Gramps.
|
Base Reference class for Gramps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Standard Python modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# RefBase class
|
# RefBase class
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class RefBase:
|
class RefBase(metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
Base reference class to manage references to other objects.
|
Base reference class to manage references to other objects.
|
||||||
|
|
||||||
@ -62,6 +69,7 @@ class RefBase:
|
|||||||
self.ref = data
|
self.ref = data
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_referenced_handles(self):
|
def get_referenced_handles(self):
|
||||||
"""
|
"""
|
||||||
Returns the list of (classname, handle) tuples for all directly
|
Returns the list of (classname, handle) tuples for all directly
|
||||||
@ -71,7 +79,6 @@ class RefBase:
|
|||||||
objects.
|
objects.
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def set_reference_handle(self, handle):
|
def set_reference_handle(self, handle):
|
||||||
"""
|
"""
|
||||||
|
@ -22,6 +22,13 @@
|
|||||||
Secondary Object class for Gramps.
|
Secondary Object class for Gramps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Standard Python modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from abc import abstractmethod
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Gramps modules
|
# Gramps modules
|
||||||
@ -40,18 +47,19 @@ class SecondaryObject(BaseObject):
|
|||||||
database.
|
database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Convert the object to a serialized tuple of data.
|
Convert the object to a serialized tuple of data.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def to_struct(self):
|
def to_struct(self):
|
||||||
"""
|
"""
|
||||||
Convert the data held in this object to a structure (eg,
|
Convert the data held in this object to a structure (eg,
|
||||||
@ -71,8 +79,8 @@ class SecondaryObject(BaseObject):
|
|||||||
|
|
||||||
:returns: Returns a struct containing the data of the object.
|
:returns: Returns a struct containing the data of the object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def from_struct(self, struct):
|
def from_struct(self, struct):
|
||||||
"""
|
"""
|
||||||
Given a struct data representation, return an object of this type.
|
Given a struct data representation, return an object of this type.
|
||||||
@ -87,7 +95,6 @@ class SecondaryObject(BaseObject):
|
|||||||
|
|
||||||
:returns: Returns an object of this type.
|
:returns: Returns an object of this type.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def is_equal(self, source):
|
def is_equal(self, source):
|
||||||
return self.serialize() == source.serialize()
|
return self.serialize() == source.serialize()
|
||||||
|
@ -25,9 +25,10 @@ Table Object class for Gramps.
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# standard python modules
|
# Standard Python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from abc import abstractmethod
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -78,18 +79,19 @@ class TableObject(BaseObject):
|
|||||||
self.handle = None
|
self.handle = None
|
||||||
self.change = 0
|
self.change = 0
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Convert the object to a serialized tuple of data.
|
Convert the object to a serialized tuple of data.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def to_struct(self):
|
def to_struct(self):
|
||||||
"""
|
"""
|
||||||
Convert the data held in this object to a structure (eg,
|
Convert the data held in this object to a structure (eg,
|
||||||
@ -109,8 +111,8 @@ class TableObject(BaseObject):
|
|||||||
|
|
||||||
:returns: Returns a struct containing the data of the object.
|
:returns: Returns a struct containing the data of the object.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def from_struct(self, struct):
|
def from_struct(self, struct):
|
||||||
"""
|
"""
|
||||||
Given a struct data representation, return an object of this type.
|
Given a struct data representation, return an object of this type.
|
||||||
@ -125,7 +127,6 @@ class TableObject(BaseObject):
|
|||||||
|
|
||||||
:returns: Returns an object of this type.
|
:returns: Returns an object of this type.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def get_change_time(self):
|
def get_change_time(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user