diff --git a/gramps/cli/grampscli.py b/gramps/cli/grampscli.py index d19e95762..e883a8a12 100644 --- a/gramps/cli/grampscli.py +++ b/gramps/cli/grampscli.py @@ -297,7 +297,10 @@ class CLIManager(object): # apply preferred researcher if loaded file has none res = self.dbstate.db.get_researcher() owner = get_researcher() - if res.get_name() == "" and owner.get_name() != "": + # If the DB Owner Info is empty and + # [default] Researcher is not empty and + # database is empty, then copy default researcher to DB owner + if res.is_empty() and not owner.is_empty() and self.dbstate.db.is_empty(): self.dbstate.db.set_researcher(owner) name_displayer.set_name_format(self.dbstate.db.name_formats) diff --git a/gramps/gen/db/read.py b/gramps/gen/db/read.py index c7c243a45..d14695bb8 100644 --- a/gramps/gen/db/read.py +++ b/gramps/gen/db/read.py @@ -1014,6 +1014,18 @@ class DbBsddbRead(DbReadBase, Callback): """ return self.get_number_of_records(self.tag_map) + def is_empty(self): + """ + Return true if there are no [primary] records in the database + """ + for obj_map in [self.person_map, self.family_map, self.event_map, + self.place_map, self.source_map, self.citation_map, + self.media_map, self.repository_map, self.note_map, + self.tag_map]: + if self.get_number_of_records(obj_map) > 0: + return False + return True + def all_handles(self, table): """ return all the keys of a database table diff --git a/gramps/gen/lib/researcher.py b/gramps/gen/lib/researcher.py index f8f4d40e9..f735557c9 100644 --- a/gramps/gen/lib/researcher.py +++ b/gramps/gen/lib/researcher.py @@ -166,3 +166,10 @@ class Researcher(LocationBase): ['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']: + if getattr(self, attr) != "": + return False + return True diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index 890da47a8..b9d3bd4c7 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -518,6 +518,10 @@ class GrampsParser(UpdateCallback): self.replace_import_handle = (self.db.get_number_of_people() > 0 and not LOG.isEnabledFor(logging.DEBUG)) + # Similarly, if the data is imported into an empty family tree, we also + # import the Researcher; if the tree was not empty, the existing + # Researcher is retained + self.import_researcher = self.db.is_empty() self.ord = None self.objref = None self.object = None @@ -956,7 +960,10 @@ class GrampsParser(UpdateCallback): # Register new formats name_displayer.set_name_format(self.db.name_formats) - self.db.set_researcher(self.owner) + # If the database was originally empty we update the researcher from + # the XML (or initialised to no researcher) + if self.import_researcher: + self.db.set_researcher(self.owner) if self.home is not None: person = self.db.get_person_from_handle(self.home) self.db.set_default_person_handle(person.handle) diff --git a/gramps/plugins/lib/libgedcom.py b/gramps/plugins/lib/libgedcom.py index 0044fd023..f754fd767 100644 --- a/gramps/plugins/lib/libgedcom.py +++ b/gramps/plugins/lib/libgedcom.py @@ -1868,6 +1868,7 @@ class GedcomParser(UpdateCallback): self.number_of_errors = 0 self.maxpeople = stage_one.get_person_count() self.dbase = dbase + self.import_researcher = self.dbase.is_empty() self.emapper = IdFinder(dbase.get_gramps_ids(EVENT_KEY), dbase.event_prefix) self.famc_map = stage_one.get_famc_map() @@ -3317,7 +3318,7 @@ class GedcomParser(UpdateCallback): self.__parse_level(state, self.subm_parse_tbl, self.__undefined) # If this is the submitter that we were told about in the HEADer, then # we will need to update the researcher - if line.token_text == self.subm: + if line.token_text == self.subm and self.import_researcher: self.dbase.set_researcher(state.res) submitter_name = _("SUBM (Submitter): @%s@") % line.token_text