More pylint improvements
This commit is contained in:
@ -30,7 +30,6 @@ CitationBase class for Gramps.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import logging
|
import logging
|
||||||
LOG = logging.getLogger(".citation")
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -39,6 +38,8 @@ LOG = logging.getLogger(".citation")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from .handle import Handle
|
from .handle import Handle
|
||||||
|
|
||||||
|
LOG = logging.getLogger(".citation")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# CitationBase class
|
# CitationBase class
|
||||||
|
@ -63,7 +63,7 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
|
|||||||
AttributeBase.__init__(self, source)
|
AttributeBase.__init__(self, source)
|
||||||
RefBase.__init__(self, source)
|
RefBase.__init__(self, source)
|
||||||
if source:
|
if source:
|
||||||
self.__role = EventRoleType(source.__role)
|
self.__role = EventRoleType(source.role)
|
||||||
else:
|
else:
|
||||||
self.__role = EventRoleType()
|
self.__role = EventRoleType()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class GenderStats(object):
|
|||||||
This allows the tracking of the liklihood of a person's given name
|
This allows the tracking of the liklihood of a person's given name
|
||||||
indicating the gender of the person.
|
indicating the gender of the person.
|
||||||
"""
|
"""
|
||||||
def __init__ (self, stats={}):
|
def __init__(self, stats=None):
|
||||||
if stats is None:
|
if stats is None:
|
||||||
self.stats = {}
|
self.stats = {}
|
||||||
else:
|
else:
|
||||||
@ -56,42 +56,35 @@ class GenderStats(object):
|
|||||||
self.stats = {}
|
self.stats = {}
|
||||||
return self.stats
|
return self.stats
|
||||||
|
|
||||||
def _get_key (self, person):
|
def name_stats(self, name):
|
||||||
name = person.get_primary_name().get_first_name()
|
|
||||||
return self._get_key_from_name (name)
|
|
||||||
|
|
||||||
def _get_key_from_name (self, name):
|
|
||||||
return name.split (' ')[0].replace ('?', '')
|
|
||||||
|
|
||||||
def name_stats (self, name):
|
|
||||||
if name in self.stats:
|
if name in self.stats:
|
||||||
return self.stats[name]
|
return self.stats[name]
|
||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
|
|
||||||
def count_name (self, name, gender):
|
def count_name(self, name, gender):
|
||||||
"""
|
"""
|
||||||
Count a given name under gender in the gender stats.
|
Count a given name under gender in the gender stats.
|
||||||
"""
|
"""
|
||||||
keyname = self._get_key_from_name(name)
|
keyname = _get_key_from_name(name)
|
||||||
if not keyname:
|
if not keyname:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._set_stats(keyname, gender)
|
self._set_stats(keyname, gender)
|
||||||
|
|
||||||
def count_person (self, person, undo = 0):
|
def count_person(self, person, undo=0):
|
||||||
if not person:
|
if not person:
|
||||||
return
|
return
|
||||||
# Let the Person do their own counting later
|
# Let the Person do their own counting later
|
||||||
|
|
||||||
keyname = self._get_key (person)
|
keyname = _get_key(person)
|
||||||
if not keyname:
|
if not keyname:
|
||||||
return
|
return
|
||||||
|
|
||||||
gender = person.get_gender()
|
gender = person.get_gender()
|
||||||
self._set_stats(keyname, gender, undo)
|
self._set_stats(keyname, gender, undo)
|
||||||
|
|
||||||
def _set_stats (self, keyname, gender, undo=0):
|
def _set_stats(self, keyname, gender, undo=0):
|
||||||
(male, female, unknown) = self.name_stats (keyname)
|
(male, female, unknown) = self.name_stats(keyname)
|
||||||
if not undo:
|
if not undo:
|
||||||
increment = 1
|
increment = 1
|
||||||
else:
|
else:
|
||||||
@ -112,11 +105,11 @@ class GenderStats(object):
|
|||||||
|
|
||||||
self.stats[keyname] = (male, female, unknown)
|
self.stats[keyname] = (male, female, unknown)
|
||||||
|
|
||||||
def uncount_person (self, person):
|
def uncount_person(self, person):
|
||||||
return self.count_person (person, undo = 1)
|
return self.count_person(person, undo=1)
|
||||||
|
|
||||||
def guess_gender (self, name):
|
def guess_gender(self, name):
|
||||||
name = self._get_key_from_name (name)
|
name = _get_key_from_name(name)
|
||||||
if not name or name not in self.stats:
|
if not name or name not in self.stats:
|
||||||
return Person.UNKNOWN
|
return Person.UNKNOWN
|
||||||
|
|
||||||
@ -134,3 +127,10 @@ class GenderStats(object):
|
|||||||
return Person.FEMALE
|
return Person.FEMALE
|
||||||
|
|
||||||
return Person.UNKNOWN
|
return Person.UNKNOWN
|
||||||
|
|
||||||
|
def _get_key(person):
|
||||||
|
name = person.get_primary_name().get_first_name()
|
||||||
|
return _get_key_from_name(name)
|
||||||
|
|
||||||
|
def _get_key_from_name(name):
|
||||||
|
return name.split(' ')[0].replace('?', '')
|
||||||
|
@ -146,7 +146,7 @@ class MediaBase(object):
|
|||||||
else:
|
else:
|
||||||
self.media_list.append(addendum)
|
self.media_list.append(addendum)
|
||||||
|
|
||||||
def has_media_reference(self, obj_handle) :
|
def has_media_reference(self, obj_handle):
|
||||||
"""
|
"""
|
||||||
Return True if the object or any of it's child objects has reference
|
Return True if the object or any of it's child objects has reference
|
||||||
to this media object handle.
|
to this media object handle.
|
||||||
@ -180,7 +180,7 @@ class MediaBase(object):
|
|||||||
:param new_handle: The media handle to replace the old one with.
|
:param new_handle: The media handle to replace the old one with.
|
||||||
:type new_handle: str
|
:type new_handle: str
|
||||||
"""
|
"""
|
||||||
refs_list = [ media_ref.ref for media_ref in self.media_list ]
|
refs_list = [media_ref.ref for media_ref in self.media_list]
|
||||||
new_ref = None
|
new_ref = None
|
||||||
if new_handle in refs_list:
|
if new_handle in refs_list:
|
||||||
new_ref = self.media_list[refs_list.index(new_handle)]
|
new_ref = self.media_list[refs_list.index(new_handle)]
|
||||||
|
@ -96,7 +96,7 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
|
|||||||
"note_list": NoteBase.to_struct(self),
|
"note_list": NoteBase.to_struct(self),
|
||||||
"attribute_list": AttributeBase.to_struct(self),
|
"attribute_list": AttributeBase.to_struct(self),
|
||||||
"ref": Handle("Media", self.ref),
|
"ref": Handle("Media", self.ref),
|
||||||
"rect": self.rect if self.rect != (0,0,0,0) else None}
|
"rect": self.rect if self.rect != (0, 0, 0, 0) else None}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_struct(cls, struct):
|
def from_struct(cls, struct):
|
||||||
@ -107,9 +107,12 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
|
|||||||
"""
|
"""
|
||||||
default = MediaRef()
|
default = MediaRef()
|
||||||
return (PrivacyBase.from_struct(struct.get("private", default.private)),
|
return (PrivacyBase.from_struct(struct.get("private", default.private)),
|
||||||
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
|
CitationBase.from_struct(struct.get("citation_list",
|
||||||
NoteBase.from_struct(struct.get("note_list", default.note_list)),
|
default.citation_list)),
|
||||||
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
|
NoteBase.from_struct(struct.get("note_list",
|
||||||
|
default.note_list)),
|
||||||
|
AttributeBase.from_struct(struct.get("attribute_list",
|
||||||
|
default.attribute_list)),
|
||||||
RefBase.from_struct(struct.get("ref", default.ref)),
|
RefBase.from_struct(struct.get("ref", default.ref)),
|
||||||
struct.get("rect", default.rect))
|
struct.get("rect", default.rect))
|
||||||
|
|
||||||
@ -117,7 +120,8 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
|
|||||||
"""
|
"""
|
||||||
Convert a serialized tuple of data to an object.
|
Convert a serialized tuple of data to an object.
|
||||||
"""
|
"""
|
||||||
(privacy, citation_list, note_list,attribute_list,ref,self.rect) = data
|
(privacy, citation_list, note_list, attribute_list, ref,
|
||||||
|
self.rect) = data
|
||||||
PrivacyBase.unserialize(self, privacy)
|
PrivacyBase.unserialize(self, privacy)
|
||||||
CitationBase.unserialize(self, citation_list)
|
CitationBase.unserialize(self, citation_list)
|
||||||
NoteBase.unserialize(self, note_list)
|
NoteBase.unserialize(self, note_list)
|
||||||
|
@ -61,7 +61,7 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
|||||||
LNFN = 1 # last name first name
|
LNFN = 1 # last name first name
|
||||||
FNLN = 2 # first name last name
|
FNLN = 2 # first name last name
|
||||||
FN = 4 # first name
|
FN = 4 # first name
|
||||||
LNFNP= 5 # primary name primconnector rest, given pa/ma suffix, primprefix
|
LNFNP = 5 # primary name primconnector rest, given pa/ma suffix, primprefix
|
||||||
|
|
||||||
NAMEFORMATS = (DEF, LNFN, FNLN, FN, LNFNP)
|
NAMEFORMATS = (DEF, LNFN, FNLN, FN, LNFNP)
|
||||||
#deprecated :
|
#deprecated :
|
||||||
@ -175,11 +175,14 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
|||||||
"""
|
"""
|
||||||
default = Name()
|
default = Name()
|
||||||
return (PrivacyBase.from_struct(struct.get("private", default.private)),
|
return (PrivacyBase.from_struct(struct.get("private", default.private)),
|
||||||
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
|
CitationBase.from_struct(struct.get("citation_list",
|
||||||
NoteBase.from_struct(struct.get("note_list", default.note_list)),
|
default.citation_list)),
|
||||||
|
NoteBase.from_struct(struct.get("note_list",
|
||||||
|
default.note_list)),
|
||||||
DateBase.from_struct(struct.get("date", {})),
|
DateBase.from_struct(struct.get("date", {})),
|
||||||
struct.get("first_name", default.first_name),
|
struct.get("first_name", default.first_name),
|
||||||
SurnameBase.from_struct(struct.get("surname_list", default.surname_list)),
|
SurnameBase.from_struct(struct.get("surname_list",
|
||||||
|
default.surname_list)),
|
||||||
struct.get("suffix", default.suffix),
|
struct.get("suffix", default.suffix),
|
||||||
struct.get("title", default.title),
|
struct.get("title", default.title),
|
||||||
NameType.from_struct(struct.get("type", {})),
|
NameType.from_struct(struct.get("type", {})),
|
||||||
@ -237,10 +240,12 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
|||||||
Indicate if the name is empty.
|
Indicate if the name is empty.
|
||||||
"""
|
"""
|
||||||
namefieldsempty = (self.first_name == "" and
|
namefieldsempty = (self.first_name == "" and
|
||||||
self.suffix == "" and self.title == "" and self.nick == ""
|
self.suffix == "" and
|
||||||
and self.famnick == "")
|
self.title == "" and
|
||||||
surnamefieldsempty = not (False in
|
self.nick == "" and
|
||||||
[surn.is_empty() for surn in self.surname_list])
|
self.famnick == "")
|
||||||
|
surnamefieldsempty = False not in [surn.is_empty()
|
||||||
|
for surn in self.surname_list]
|
||||||
return namefieldsempty and surnamefieldsempty
|
return namefieldsempty and surnamefieldsempty
|
||||||
|
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
@ -536,7 +541,7 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
|||||||
"""
|
"""
|
||||||
first = self.first_name
|
first = self.first_name
|
||||||
surname = self.get_surname()
|
surname = self.get_surname()
|
||||||
if (self.suffix == ""):
|
if self.suffix == "":
|
||||||
return "%s %s" % (first, surname)
|
return "%s %s" % (first, surname)
|
||||||
else:
|
else:
|
||||||
# translators: needed for Arabic, ignore otherwise
|
# translators: needed for Arabic, ignore otherwise
|
||||||
@ -569,7 +574,6 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
|||||||
firstname = self.first_name.strip()
|
firstname = self.first_name.strip()
|
||||||
surname = self.get_surname().replace('/', '?')
|
surname = self.get_surname().replace('/', '?')
|
||||||
suffix = self.suffix
|
suffix = self.suffix
|
||||||
title = self.title
|
|
||||||
if suffix == "":
|
if suffix == "":
|
||||||
return '%s /%s/' % (firstname, surname)
|
return '%s /%s/' % (firstname, surname)
|
||||||
else:
|
else:
|
||||||
|
@ -31,7 +31,6 @@ Place name class for Gramps
|
|||||||
from .secondaryobj import SecondaryObject
|
from .secondaryobj import SecondaryObject
|
||||||
from .datebase import DateBase
|
from .datebase import DateBase
|
||||||
from .const import IDENTICAL, EQUAL, DIFFERENT
|
from .const import IDENTICAL, EQUAL, DIFFERENT
|
||||||
from .handle import Handle
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -110,7 +110,7 @@ class Researcher(LocationBase):
|
|||||||
struct.get("postal", default.postal),
|
struct.get("postal", default.postal),
|
||||||
struct.get("phone", default.phone),
|
struct.get("phone", default.phone),
|
||||||
struct.get("name", default.name),
|
struct.get("name", default.name),
|
||||||
struct.get("address", default.address),
|
struct.get("address", default.addr),
|
||||||
struct.get("email", default.email))
|
struct.get("email", default.email))
|
||||||
|
|
||||||
def unserialize(self, data):
|
def unserialize(self, data):
|
||||||
|
@ -27,13 +27,8 @@ Source Attribute class for GRAMPS.
|
|||||||
# Gramps modules
|
# Gramps modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from .secondaryobj import SecondaryObject
|
|
||||||
from .privacybase import PrivacyBase
|
|
||||||
from .citationbase import CitationBase
|
|
||||||
from .notebase import NoteBase
|
|
||||||
from .attribute import AttributeRoot
|
from .attribute import AttributeRoot
|
||||||
from .srcattrtype import SrcAttributeType
|
from .srcattrtype import SrcAttributeType
|
||||||
from .const import IDENTICAL, EQUAL, DIFFERENT
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -22,9 +22,6 @@
|
|||||||
SurnameBase class for Gramps.
|
SurnameBase class for Gramps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..const import GRAMPS_LOCALE as glocale
|
|
||||||
_ = glocale.translation.gettext
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Gramps modules
|
# Gramps modules
|
||||||
@ -32,6 +29,8 @@ _ = glocale.translation.gettext
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from .surname import Surname
|
from .surname import Surname
|
||||||
from .const import IDENTICAL, EQUAL
|
from .const import IDENTICAL, EQUAL
|
||||||
|
from ..const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.gettext
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -182,7 +182,7 @@ class Url(SecondaryObject, PrivacyBase):
|
|||||||
def are_equal(self, other):
|
def are_equal(self, other):
|
||||||
"""Deprecated - use :meth:`~.SecondaryObject.is_equal` instead."""
|
"""Deprecated - use :meth:`~.SecondaryObject.is_equal` instead."""
|
||||||
|
|
||||||
warn( "Use is_equal instead of are_equal", DeprecationWarning, 2)
|
warn("Use is_equal instead of are_equal", DeprecationWarning, 2)
|
||||||
return self.is_equal(other)
|
return self.is_equal(other)
|
||||||
|
|
||||||
def parse_path(self):
|
def parse_path(self):
|
||||||
|
Reference in New Issue
Block a user