diff --git a/gramps/gen/lib/address.py b/gramps/gen/lib/address.py index f896e47ba..c684667cc 100644 --- a/gramps/gen/lib/address.py +++ b/gramps/gen/lib/address.py @@ -93,7 +93,7 @@ class Address(SecondaryObject, PrivacyBase, CitationBase, NoteBase, DateBase, "note_list": NoteBase.to_struct(self), "date": DateBase.to_struct(self), "location": LocationBase.to_struct(self) - } + } @classmethod def from_struct(cls, struct): @@ -108,7 +108,7 @@ class Address(SecondaryObject, PrivacyBase, CitationBase, NoteBase, DateBase, NoteBase.from_struct(struct.get("note_list", default.note_list)), DateBase.from_struct(struct.get("date", {})), LocationBase.from_struct(struct.get("location", {})) - ) + ) def unserialize(self, data): """ diff --git a/gramps/gen/lib/attrbase.py b/gramps/gen/lib/attrbase.py index 5581acb7b..6d63f9b0e 100644 --- a/gramps/gen/lib/attrbase.py +++ b/gramps/gen/lib/attrbase.py @@ -55,7 +55,7 @@ class AttributeRootBase(object): """ if source: self.attribute_list = [self._CLASS(attribute) - for attribute in source.attribute_list] + for attribute in source.attribute_list] else: self.attribute_list = [] diff --git a/gramps/gen/lib/citationbase.py b/gramps/gen/lib/citationbase.py index 6b19d8150..3393da3e4 100644 --- a/gramps/gen/lib/citationbase.py +++ b/gramps/gen/lib/citationbase.py @@ -30,7 +30,6 @@ CitationBase class for Gramps. # #------------------------------------------------------------------------- import logging -LOG = logging.getLogger(".citation") #------------------------------------------------------------------------- # @@ -39,6 +38,8 @@ LOG = logging.getLogger(".citation") #------------------------------------------------------------------------- from .handle import Handle +LOG = logging.getLogger(".citation") + #------------------------------------------------------------------------- # # CitationBase class @@ -138,7 +139,7 @@ class CitationBase(object): :type handle: list """ LOG.debug('enter remove_citation handle: %s self: %s citation_list: %s' - % (citation_handle_list, self, self.citation_list)) + % (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' % diff --git a/gramps/gen/lib/eventref.py b/gramps/gen/lib/eventref.py index 9330e9db5..66edcca16 100644 --- a/gramps/gen/lib/eventref.py +++ b/gramps/gen/lib/eventref.py @@ -46,7 +46,7 @@ from .handle import Handle # #------------------------------------------------------------------------- class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase, - IndirectCitationBase, SecondaryObject): + IndirectCitationBase, SecondaryObject): """ Event reference class. @@ -63,7 +63,7 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase, AttributeBase.__init__(self, source) RefBase.__init__(self, source) if source: - self.__role = EventRoleType(source.__role) + self.__role = EventRoleType(source.role) else: self.__role = EventRoleType() diff --git a/gramps/gen/lib/genderstats.py b/gramps/gen/lib/genderstats.py index 1474c4fc6..088cfafc7 100644 --- a/gramps/gen/lib/genderstats.py +++ b/gramps/gen/lib/genderstats.py @@ -42,7 +42,7 @@ class GenderStats(object): This allows the tracking of the liklihood of a person's given name indicating the gender of the person. """ - def __init__ (self, stats={}): + def __init__(self, stats=None): if stats is None: self.stats = {} else: @@ -56,42 +56,35 @@ class GenderStats(object): self.stats = {} return self.stats - def _get_key (self, person): - 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): + def name_stats(self, name): if name in self.stats: return self.stats[name] 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. """ - keyname = self._get_key_from_name(name) + keyname = _get_key_from_name(name) if not keyname: return self._set_stats(keyname, gender) - def count_person (self, person, undo = 0): + def count_person(self, person, undo=0): if not person: return # Let the Person do their own counting later - keyname = self._get_key (person) + keyname = _get_key(person) if not keyname: return gender = person.get_gender() self._set_stats(keyname, gender, undo) - def _set_stats (self, keyname, gender, undo=0): - (male, female, unknown) = self.name_stats (keyname) + def _set_stats(self, keyname, gender, undo=0): + (male, female, unknown) = self.name_stats(keyname) if not undo: increment = 1 else: @@ -112,11 +105,11 @@ class GenderStats(object): self.stats[keyname] = (male, female, unknown) - def uncount_person (self, person): - return self.count_person (person, undo = 1) + def uncount_person(self, person): + return self.count_person(person, undo=1) - def guess_gender (self, name): - name = self._get_key_from_name (name) + def guess_gender(self, name): + name = _get_key_from_name(name) if not name or name not in self.stats: return Person.UNKNOWN @@ -134,3 +127,10 @@ class GenderStats(object): return Person.FEMALE 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('?', '') diff --git a/gramps/gen/lib/ldsordbase.py b/gramps/gen/lib/ldsordbase.py index 3b1d1cc52..cf86d43b3 100644 --- a/gramps/gen/lib/ldsordbase.py +++ b/gramps/gen/lib/ldsordbase.py @@ -54,7 +54,7 @@ class LdsOrdBase(object): if source: self.lds_ord_list = [LdsOrd(lds_ord) - for lds_ord in source.lds_ord_list] + for lds_ord in source.lds_ord_list] else: self.lds_ord_list = [] diff --git a/gramps/gen/lib/mediabase.py b/gramps/gen/lib/mediabase.py index a04e5f910..2184bf722 100644 --- a/gramps/gen/lib/mediabase.py +++ b/gramps/gen/lib/mediabase.py @@ -146,7 +146,7 @@ class MediaBase(object): else: 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 to this media object handle. @@ -167,7 +167,7 @@ class MediaBase(object): :type obj_handle_list: list """ new_media_list = [media_ref for media_ref in self.media_list - if media_ref.ref not in obj_handle_list] + if media_ref.ref not in obj_handle_list] self.media_list = new_media_list def replace_media_references(self, old_handle, new_handle): @@ -180,7 +180,7 @@ class MediaBase(object): :param new_handle: The media handle to replace the old one with. :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 if new_handle in refs_list: new_ref = self.media_list[refs_list.index(new_handle)] diff --git a/gramps/gen/lib/mediaref.py b/gramps/gen/lib/mediaref.py index b0aba4e82..fc44f92e5 100644 --- a/gramps/gen/lib/mediaref.py +++ b/gramps/gen/lib/mediaref.py @@ -96,7 +96,7 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase, "note_list": NoteBase.to_struct(self), "attribute_list": AttributeBase.to_struct(self), "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 def from_struct(cls, struct): @@ -107,9 +107,12 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase, """ default = MediaRef() return (PrivacyBase.from_struct(struct.get("private", default.private)), - CitationBase.from_struct(struct.get("citation_list", default.citation_list)), - NoteBase.from_struct(struct.get("note_list", default.note_list)), - AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)), + CitationBase.from_struct(struct.get("citation_list", + default.citation_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)), 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. """ - (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) CitationBase.unserialize(self, citation_list) NoteBase.unserialize(self, note_list) diff --git a/gramps/gen/lib/name.py b/gramps/gen/lib/name.py index 3d44d7e85..571a99cdf 100644 --- a/gramps/gen/lib/name.py +++ b/gramps/gen/lib/name.py @@ -57,11 +57,11 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, object stores one of them """ - DEF = 0 # Default format (determined by gramps-wide prefs) - LNFN = 1 # last name first name - FNLN = 2 # first name last name - FN = 4 # first name - LNFNP= 5 # primary name primconnector rest, given pa/ma suffix, primprefix + DEF = 0 # Default format (determined by gramps-wide prefs) + LNFN = 1 # last name first name + FNLN = 2 # first name last name + FN = 4 # first name + LNFNP = 5 # primary name primconnector rest, given pa/ma suffix, primprefix NAMEFORMATS = (DEF, LNFN, FNLN, FN, LNFNP) #deprecated : @@ -175,11 +175,14 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, """ default = Name() return (PrivacyBase.from_struct(struct.get("private", default.private)), - CitationBase.from_struct(struct.get("citation_list", default.citation_list)), - NoteBase.from_struct(struct.get("note_list", default.note_list)), + 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("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("title", default.title), NameType.from_struct(struct.get("type", {})), @@ -237,10 +240,12 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, Indicate if the name is empty. """ namefieldsempty = (self.first_name == "" and - self.suffix == "" and self.title == "" and self.nick == "" - and self.famnick == "") - surnamefieldsempty = not (False in - [surn.is_empty() for surn in self.surname_list]) + self.suffix == "" and + self.title == "" and + self.nick == "" and + self.famnick == "") + surnamefieldsempty = False not in [surn.is_empty() + for surn in self.surname_list] return namefieldsempty and surnamefieldsempty def unserialize(self, data): @@ -536,7 +541,7 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, """ first = self.first_name surname = self.get_surname() - if (self.suffix == ""): + if self.suffix == "": return "%s %s" % (first, surname) else: # translators: needed for Arabic, ignore otherwise @@ -569,7 +574,6 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, firstname = self.first_name.strip() surname = self.get_surname().replace('/', '?') suffix = self.suffix - title = self.title if suffix == "": return '%s /%s/' % (firstname, surname) else: diff --git a/gramps/gen/lib/placename.py b/gramps/gen/lib/placename.py index c67ccc144..2701c4b71 100644 --- a/gramps/gen/lib/placename.py +++ b/gramps/gen/lib/placename.py @@ -31,7 +31,6 @@ Place name class for Gramps from .secondaryobj import SecondaryObject from .datebase import DateBase from .const import IDENTICAL, EQUAL, DIFFERENT -from .handle import Handle #------------------------------------------------------------------------- # @@ -191,8 +190,8 @@ class PlaceName(SecondaryObject, DateBase): :rtype: int """ if (self.value != other.value or - self.date != other.date or - self.lang != other.lang): + self.date != other.date or + self.lang != other.lang): return DIFFERENT else: if self.is_equal(other): diff --git a/gramps/gen/lib/researcher.py b/gramps/gen/lib/researcher.py index cef646151..309138c62 100644 --- a/gramps/gen/lib/researcher.py +++ b/gramps/gen/lib/researcher.py @@ -110,7 +110,7 @@ class Researcher(LocationBase): struct.get("postal", default.postal), struct.get("phone", default.phone), struct.get("name", default.name), - struct.get("address", default.address), + struct.get("address", default.addr), struct.get("email", default.email)) def unserialize(self, data): @@ -159,17 +159,17 @@ class Researcher(LocationBase): self.name = other_researcher.name self.addr = other_researcher.addr - self.email = other_researcher.email + self.email = other_researcher.email def get(self): return [getattr(self, value) for value in - ['name', 'addr', 'locality', 'city', 'state', - 'country', 'postal', 'phone', 'email'] - ] + ['name', 'addr', 'locality', 'city', 'state', + 'country', 'postal', 'phone', 'email'] + ] def is_empty(self): for attr in ['name', 'addr', 'locality', 'city', 'state', - 'country', 'postal', 'phone', 'email']: + 'country', 'postal', 'phone', 'email']: if getattr(self, attr) != "": return False return True diff --git a/gramps/gen/lib/srcattribute.py b/gramps/gen/lib/srcattribute.py index eae1c58a2..ce4d1836c 100644 --- a/gramps/gen/lib/srcattribute.py +++ b/gramps/gen/lib/srcattribute.py @@ -27,13 +27,8 @@ Source Attribute class for GRAMPS. # Gramps modules # #------------------------------------------------------------------------- -from .secondaryobj import SecondaryObject -from .privacybase import PrivacyBase -from .citationbase import CitationBase -from .notebase import NoteBase from .attribute import AttributeRoot from .srcattrtype import SrcAttributeType -from .const import IDENTICAL, EQUAL, DIFFERENT #------------------------------------------------------------------------- # diff --git a/gramps/gen/lib/surnamebase.py b/gramps/gen/lib/surnamebase.py index 7b469df87..82a37ed7b 100644 --- a/gramps/gen/lib/surnamebase.py +++ b/gramps/gen/lib/surnamebase.py @@ -22,9 +22,6 @@ SurnameBase class for Gramps. """ -from ..const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext - #------------------------------------------------------------------------- # # Gramps modules @@ -32,6 +29,8 @@ _ = glocale.translation.gettext #------------------------------------------------------------------------- from .surname import Surname from .const import IDENTICAL, EQUAL +from ..const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext #------------------------------------------------------------------------- # diff --git a/gramps/gen/lib/url.py b/gramps/gen/lib/url.py index 0ccff8725..e773f32f5 100644 --- a/gramps/gen/lib/url.py +++ b/gramps/gen/lib/url.py @@ -182,7 +182,7 @@ class Url(SecondaryObject, PrivacyBase): def are_equal(self, other): """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) def parse_path(self):