Further pylint improvements
This commit is contained in:
parent
831330b6d0
commit
c3eab4e6e3
@ -47,14 +47,13 @@ class BaseObject(object):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
return self
|
||||
raise NotImplementedError
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
@ -75,7 +74,7 @@ class BaseObject(object):
|
||||
|
||||
:returns: Returns a struct containing the data of the object.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def from_struct(self, struct):
|
||||
"""
|
||||
@ -91,7 +90,7 @@ class BaseObject(object):
|
||||
|
||||
:returns: Returns an object of this type.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def matches_string(self, pattern, case_sensitive=False):
|
||||
"""
|
||||
@ -109,9 +108,6 @@ class BaseObject(object):
|
||||
# Run through its own items
|
||||
patern_upper = pattern.upper()
|
||||
for item in self.get_text_data_list():
|
||||
# Some items are strings, which will fail in item.upper(), and some items are unicode.
|
||||
# Convert all items to unicode and the item.upper().find(patern_upper) will work OK.
|
||||
item = str(item)
|
||||
if not item:
|
||||
continue
|
||||
if case_sensitive:
|
||||
@ -228,5 +224,8 @@ class BaseObject(object):
|
||||
|
||||
@classmethod
|
||||
def create(cls, data):
|
||||
"""
|
||||
Create a new instance from serialized data.
|
||||
"""
|
||||
if data:
|
||||
return cls().unserialize(data)
|
||||
|
@ -138,15 +138,14 @@ class CitationBase(object):
|
||||
:param citation_handle_list: The list of citation handles to be removed
|
||||
:type handle: list
|
||||
"""
|
||||
LOG.debug('enter remove_citation handle: %s self: %s citation_list: %s'
|
||||
% (citation_handle_list, self, self.citation_list))
|
||||
LOG.debug('enter remove_citation handle: %s self: %s citation_list: %s',
|
||||
citation_handle_list, self, self.citation_list)
|
||||
for handle in citation_handle_list:
|
||||
if handle in self.citation_list:
|
||||
LOG.debug('remove handle %s from citation_list %s' %
|
||||
(handle, self.citation_list))
|
||||
LOG.debug('remove handle %s from citation_list %s',
|
||||
handle, self.citation_list)
|
||||
self.citation_list.remove(handle)
|
||||
LOG.debug('get_citation_child_list %s' %
|
||||
self.get_citation_child_list())
|
||||
LOG.debug('get_citation_child_list %s', self.get_citation_child_list())
|
||||
for item in self.get_citation_child_list():
|
||||
item.remove_citation_references(citation_handle_list)
|
||||
|
||||
@ -182,13 +181,13 @@ class CitationBase(object):
|
||||
:returns: The list of :class:`~.citation.Citation` handles
|
||||
:rtype: list
|
||||
"""
|
||||
list = self.citation_list
|
||||
all_citations = self.citation_list
|
||||
|
||||
for item in self.get_citation_child_list():
|
||||
list += item.get_citation_list()
|
||||
all_citations += item.get_citation_list()
|
||||
for subitem in item.get_citation_child_list():
|
||||
list += subitem.get_citation_list()
|
||||
return list
|
||||
all_citations += subitem.get_citation_list()
|
||||
return all_citations
|
||||
|
||||
def has_citation_reference(self, citation_handle):
|
||||
"""
|
||||
@ -205,7 +204,7 @@ class CitationBase(object):
|
||||
if citation_ref == citation_handle:
|
||||
return True
|
||||
|
||||
LOG.debug("citation child list %s" % self.get_citation_child_list())
|
||||
LOG.debug("citation child list %s", self.get_citation_child_list())
|
||||
for item in self.get_citation_child_list():
|
||||
if item.has_citation_reference(citation_handle):
|
||||
return True
|
||||
@ -337,3 +336,16 @@ class IndirectCitationBase(object):
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_citation_child_list(self):
|
||||
"""
|
||||
Return the list of child secondary objects that may refer citations.
|
||||
|
||||
All methods which inherit from CitationBase and have other child objects
|
||||
with citations, should return here a list of child objects which are
|
||||
CitationBase
|
||||
|
||||
:returns: Returns the list of child secondary child objects that may
|
||||
refer citations.
|
||||
:rtype: list
|
||||
"""
|
||||
return []
|
||||
|
@ -30,8 +30,6 @@ LDS Ordinance class for Gramps.
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from warnings import warn
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -46,6 +44,8 @@ from .datebase import DateBase
|
||||
from .placebase import PlaceBase
|
||||
from .privacybase import PrivacyBase
|
||||
from .const import IDENTICAL, EQUAL, DIFFERENT
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -63,26 +63,26 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
|
||||
source of genealogical information in the United States.
|
||||
"""
|
||||
|
||||
BAPTISM = 0
|
||||
ENDOWMENT = 1
|
||||
BAPTISM = 0
|
||||
ENDOWMENT = 1
|
||||
SEAL_TO_PARENTS = 2
|
||||
SEAL_TO_SPOUSE = 3
|
||||
CONFIRMATION = 4
|
||||
SEAL_TO_SPOUSE = 3
|
||||
CONFIRMATION = 4
|
||||
|
||||
DEFAULT_TYPE = BAPTISM
|
||||
|
||||
|
||||
STATUS_NONE = 0
|
||||
STATUS_BIC = 1
|
||||
STATUS_CANCELED = 2
|
||||
STATUS_CHILD = 3
|
||||
STATUS_CLEARED = 4
|
||||
STATUS_NONE = 0
|
||||
STATUS_BIC = 1
|
||||
STATUS_CANCELED = 2
|
||||
STATUS_CHILD = 3
|
||||
STATUS_CLEARED = 4
|
||||
STATUS_COMPLETED = 5
|
||||
STATUS_DNS = 6
|
||||
STATUS_INFANT = 7
|
||||
STATUS_PRE_1970 = 8
|
||||
STATUS_DNS = 6
|
||||
STATUS_INFANT = 7
|
||||
STATUS_PRE_1970 = 8
|
||||
STATUS_QUALIFIED = 9
|
||||
STATUS_DNS_CAN = 10
|
||||
STATUS_DNS_CAN = 10
|
||||
STATUS_STILLBORN = 11
|
||||
STATUS_SUBMITTED = 12
|
||||
STATUS_UNCLEARED = 13
|
||||
@ -91,28 +91,28 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
|
||||
|
||||
|
||||
_TYPE_MAP = [
|
||||
(BAPTISM, _('Baptism'), 'baptism'),
|
||||
(ENDOWMENT, _('Endowment'), 'endowment'),
|
||||
(CONFIRMATION, _('Confirmation'), 'confirmation'),
|
||||
(BAPTISM, _('Baptism'), 'baptism'),
|
||||
(ENDOWMENT, _('Endowment'), 'endowment'),
|
||||
(CONFIRMATION, _('Confirmation'), 'confirmation'),
|
||||
(SEAL_TO_PARENTS, _('Sealed to Parents'), 'sealed_to_parents'),
|
||||
(SEAL_TO_SPOUSE, _('Sealed to Spouse'), 'sealed_to_spouse' ),
|
||||
(SEAL_TO_SPOUSE, _('Sealed to Spouse'), 'sealed_to_spouse'),
|
||||
]
|
||||
|
||||
_STATUS_MAP = [
|
||||
(STATUS_NONE, _("<No Status>"), ""),
|
||||
(STATUS_BIC, _("BIC"), "BIC"),
|
||||
(STATUS_CANCELED, _("Canceled"), "Canceled"),
|
||||
(STATUS_CHILD, _("Child"), "Child"),
|
||||
(STATUS_CLEARED, _("Cleared"), "Cleared"),
|
||||
(STATUS_COMPLETED, _("Completed"), "Completed"),
|
||||
(STATUS_DNS, _("DNS"), "DNS"),
|
||||
(STATUS_INFANT, _("Infant"), "Infant"),
|
||||
(STATUS_PRE_1970, _("Pre-1970"), "Pre-1970"),
|
||||
(STATUS_QUALIFIED, _("Qualified"), "Qualified"),
|
||||
(STATUS_DNS_CAN, _("DNS/CAN"), "DNS/CAN"),
|
||||
(STATUS_STILLBORN, _("Stillborn"), "Stillborn"),
|
||||
(STATUS_SUBMITTED, _("Submitted"), "Submitted"),
|
||||
(STATUS_UNCLEARED, _("Uncleared"), "Uncleared"),
|
||||
(STATUS_NONE, _("<No Status>"), ""),
|
||||
(STATUS_BIC, _("BIC"), "BIC"),
|
||||
(STATUS_CANCELED, _("Canceled"), "Canceled"),
|
||||
(STATUS_CHILD, _("Child"), "Child"),
|
||||
(STATUS_CLEARED, _("Cleared"), "Cleared"),
|
||||
(STATUS_COMPLETED, _("Completed"), "Completed"),
|
||||
(STATUS_DNS, _("DNS"), "DNS"),
|
||||
(STATUS_INFANT, _("Infant"), "Infant"),
|
||||
(STATUS_PRE_1970, _("Pre-1970"), "Pre-1970"),
|
||||
(STATUS_QUALIFIED, _("Qualified"), "Qualified"),
|
||||
(STATUS_DNS_CAN, _("DNS/CAN"), "DNS/CAN"),
|
||||
(STATUS_STILLBORN, _("Stillborn"), "Stillborn"),
|
||||
(STATUS_SUBMITTED, _("Submitted"), "Submitted"),
|
||||
(STATUS_UNCLEARED, _("Uncleared"), "Uncleared"),
|
||||
]
|
||||
|
||||
def __init__(self, source=None):
|
||||
@ -183,8 +183,10 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
|
||||
:returns: Returns a serialized object
|
||||
"""
|
||||
default = LdsOrd()
|
||||
return (CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
|
||||
NoteBase.from_struct(struct.get("note_list", default.note_list)),
|
||||
return (CitationBase.from_struct(struct.get("citation_list",
|
||||
default.citation_list)),
|
||||
NoteBase.from_struct(struct.get("note_list",
|
||||
default.note_list)),
|
||||
DateBase.from_struct(struct.get("date", {})),
|
||||
struct.get("type", {}),
|
||||
struct.get("place", default.place),
|
||||
@ -353,7 +355,7 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
|
||||
|
||||
def are_equal(self, other):
|
||||
"""Return 1 if the specified ordinance is the same as the instance."""
|
||||
warn( "Use is_equal instead are_equal", DeprecationWarning, 2)
|
||||
warn("Use is_equal instead are_equal", DeprecationWarning, 2)
|
||||
return self.is_equal(other)
|
||||
|
||||
def type2xml(self):
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2011 Tim G L Lyons
|
||||
# Copyright (C) 2011 Tim G L Lyons
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -71,6 +71,69 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
else:
|
||||
self.gramps_id = None
|
||||
|
||||
def serialize(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in this object to a structure (eg,
|
||||
struct) that represents all the data elements.
|
||||
|
||||
This method is used to recursively convert the object into a
|
||||
self-documenting form that can easily be used for various
|
||||
purposes, including diffs and queries.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns a struct containing the data of the object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def from_struct(self, struct):
|
||||
"""
|
||||
Given a struct data representation, return an object of this type.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns an object of this type.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def get_labels(cls, _):
|
||||
"""
|
||||
Return labels.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
"""
|
||||
Return schema.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def get_label(cls, field, _):
|
||||
"""
|
||||
@ -83,7 +146,8 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
if chain[-1] in labels:
|
||||
return labels[chain[-1]]
|
||||
else:
|
||||
raise Exception("%s has no such label on %s: '%s'" % (cls, path, field))
|
||||
raise Exception("%s has no such label on %s: '%s'" %
|
||||
(cls, path, field))
|
||||
|
||||
@classmethod
|
||||
def get_field_type(cls, field):
|
||||
@ -146,7 +210,8 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
elif ignore_errors:
|
||||
return
|
||||
else:
|
||||
raise Exception("%s is not a valid field of %s; use %s" % (part, path, dir(path)))
|
||||
raise Exception("%s is not a valid field of %s; use %s" %
|
||||
(part, path, dir(path)))
|
||||
return path
|
||||
|
||||
def set_field(self, field, value, ignore_errors=False):
|
||||
@ -221,6 +286,15 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def has_citation_reference(self, handle):
|
||||
"""
|
||||
Indicate if the object has a citation references.
|
||||
|
||||
In the base class, no such references exist. Derived classes should
|
||||
override this if they provide citation references.
|
||||
"""
|
||||
return False
|
||||
|
||||
def has_media_reference(self, handle):
|
||||
"""
|
||||
Indicate if the object has a media references.
|
||||
@ -232,10 +306,10 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
|
||||
def remove_citation_references(self, handle_list):
|
||||
"""
|
||||
Remove the specified source references from the object.
|
||||
Remove the specified citation references from the object.
|
||||
|
||||
In the base class no such references exist. Derived classes should
|
||||
override this if they provide source references.
|
||||
override this if they provide citation references.
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -249,9 +323,17 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
pass
|
||||
|
||||
def replace_citation_references(self, old_handle, new_handle):
|
||||
"""
|
||||
Replace all references to the old citation handle with those to the new
|
||||
citation handle.
|
||||
"""
|
||||
pass
|
||||
|
||||
def replace_media_references(self, old_handle, new_handle):
|
||||
"""
|
||||
Replace all references to the old media handle with those to the new
|
||||
media handle.
|
||||
"""
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -283,6 +365,55 @@ class PrimaryObject(BasicPrimaryObject):
|
||||
"""
|
||||
BasicPrimaryObject.__init__(self, source)
|
||||
|
||||
def serialize(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in this object to a structure (eg,
|
||||
struct) that represents all the data elements.
|
||||
|
||||
This method is used to recursively convert the object into a
|
||||
self-documenting form that can easily be used for various
|
||||
purposes, including diffs and queries.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns a struct containing the data of the object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def from_struct(self, struct):
|
||||
"""
|
||||
Given a struct data representation, return an object of this type.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns an object of this type.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def has_handle_reference(self, classname, handle):
|
||||
"""
|
||||
Return True if the object has reference to a given handle of given
|
||||
|
@ -71,10 +71,22 @@ class RefBase(object):
|
||||
objects.
|
||||
:rtype: list
|
||||
"""
|
||||
assert False, "Must be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def set_reference_handle(self, val):
|
||||
self.ref = val
|
||||
def set_reference_handle(self, handle):
|
||||
"""
|
||||
Set the reference handle.
|
||||
|
||||
:param handle: The reference handle.
|
||||
:type handle: str
|
||||
"""
|
||||
self.ref = handle
|
||||
|
||||
def get_reference_handle(self):
|
||||
"""
|
||||
Return the reference handle.
|
||||
|
||||
:returns: The reference handle.
|
||||
:rtype: str
|
||||
"""
|
||||
return self.ref
|
||||
|
@ -40,6 +40,55 @@ class SecondaryObject(BaseObject):
|
||||
database.
|
||||
"""
|
||||
|
||||
def serialize(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in this object to a structure (eg,
|
||||
struct) that represents all the data elements.
|
||||
|
||||
This method is used to recursively convert the object into a
|
||||
self-documenting form that can easily be used for various
|
||||
purposes, including diffs and queries.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns a struct containing the data of the object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def from_struct(self, struct):
|
||||
"""
|
||||
Given a struct data representation, return an object of this type.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns an object of this type.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def is_equal(self, source):
|
||||
return self.serialize() == source.serialize()
|
||||
|
||||
@ -51,6 +100,13 @@ class SecondaryObject(BaseObject):
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_labels(cls, _):
|
||||
"""
|
||||
Return labels.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_label(self, field, _):
|
||||
"""
|
||||
Get the associated label given a field name of this object.
|
||||
@ -67,4 +123,3 @@ class SecondaryObject(BaseObject):
|
||||
return labels[chain[-1]]
|
||||
else:
|
||||
raise Exception("%s has no such label: '%s'" % (self, field))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user