2003-10-14 02:36:29 +05:30
|
|
|
# Copyright (C) 2003 Jesper Zedlitz
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
"Export/Partition"
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import posixpath
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import Utils
|
|
|
|
import RelLib
|
|
|
|
import GrampsCfg
|
|
|
|
|
|
|
|
from QuestionDialog import ErrorDialog
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
from gnome.ui import *
|
|
|
|
import WriteXML
|
|
|
|
|
|
|
|
personSeen = []
|
|
|
|
familySeen = []
|
|
|
|
database_for_unlinked_persons = RelLib.GrampsDB()
|
|
|
|
prefix = "/tmp/test"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def work_on_person( db, person ):
|
|
|
|
global personSeen
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if (len(person.get_family_id_list()) + len(person.get_parent_family_id_list())) > 0:
|
2003-10-14 02:36:29 +05:30
|
|
|
database = db
|
|
|
|
else:
|
|
|
|
database = database_for_unlinked_persons
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if( database.get_person_id_map().has_key( person.get_id() ) ):
|
2003-10-14 02:36:29 +05:30
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
database.add_person_no_map( person, person.get_id() )
|
2003-10-14 02:36:29 +05:30
|
|
|
personSeen.append(person)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for source_ref in person.get_primary_name().get_source_references():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_sourceref( database, source_ref)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for name in person.get_alternate_names():
|
|
|
|
for source_ref in name.get_source_references():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_sourceref( database, source_ref)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
work_on_event( database, person.get_birth() )
|
|
|
|
work_on_event( database, person.get_death() )
|
|
|
|
for event in person.get_event_list():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_event(database, event)
|
|
|
|
|
|
|
|
# recursion
|
2004-02-14 11:10:30 +05:30
|
|
|
for fam in person.get_family_id_list():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_family( database, fam )
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for fam in person.get_parent_family_id_list():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_family( database, fam[0] )
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def work_on_family( database, family ):
|
|
|
|
global familySeen
|
2004-02-14 11:10:30 +05:30
|
|
|
if database.get_family_id_map().has_key( family.get_id() ):
|
2003-10-14 02:36:29 +05:30
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
database.get_family_id_map()[family.get_id()] = family
|
2003-10-14 02:36:29 +05:30
|
|
|
familySeen.append(family)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
work_on_event( database, family.get_marriage() )
|
|
|
|
for event in family.get_event_list():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_event(database, event)
|
|
|
|
|
|
|
|
|
|
|
|
# recursion
|
2004-02-14 11:10:30 +05:30
|
|
|
father = family.get_father_id()
|
2003-10-14 02:36:29 +05:30
|
|
|
if( father != None ):
|
|
|
|
work_on_person( database, father )
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
mother = family.get_mother_id()
|
2003-10-14 02:36:29 +05:30
|
|
|
if( mother != None ):
|
|
|
|
work_on_person( database, mother )
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for person in family.get_child_id_list():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_person( database, person )
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def work_on_sourceref( database, source_ref ):
|
|
|
|
if source_ref == None:
|
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
source = source_ref.get_base_id()
|
2003-10-14 02:36:29 +05:30
|
|
|
if source == None:
|
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if database.get_source_map().has_key(source.get_id()):
|
2003-10-14 02:36:29 +05:30
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
database.add_source_no_map( source, source.get_id() );
|
2003-10-14 02:36:29 +05:30
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def work_on_event( database, event ):
|
|
|
|
if event == None:
|
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for source_ref in event.get_source_references():
|
2003-10-14 02:36:29 +05:30
|
|
|
work_on_sourceref( database, source_ref)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
work_on_place( database, event.get_place_id() )
|
2003-10-14 02:36:29 +05:30
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def work_on_place( database, place ):
|
|
|
|
if place == None:
|
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if place in database.get_place_ids():
|
2003-10-14 02:36:29 +05:30
|
|
|
return
|
2004-02-14 11:10:30 +05:30
|
|
|
database.add_place_no_map(place, place.get_id())
|
2003-10-14 02:36:29 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def report(db, person):
|
|
|
|
global personSeen
|
|
|
|
global prefix
|
|
|
|
global database_for_unlinked_persons
|
|
|
|
|
|
|
|
text = "=== Partitions ===\n"
|
|
|
|
count = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
for p in db.get_person_id_map().values():
|
2003-10-14 02:36:29 +05:30
|
|
|
if not p in personSeen:
|
|
|
|
database = RelLib.GrampsDB()
|
|
|
|
work_on_person( database, p )
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person_len = len(database.get_person_keys())
|
2003-10-14 02:36:29 +05:30
|
|
|
if person_len > 0:
|
|
|
|
g = WriteXML.XmlWriter(database,None,0,0)
|
|
|
|
g.write(prefix+str(count)+".xml")
|
|
|
|
text += "partition "+prefix+str(count)+".xml written ( "+str(person_len)+" persons)\n"
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
g = WriteXML.XmlWriter(database_for_unlinked_persons,None,0,0)
|
|
|
|
g.write(prefix+".xml")
|
2004-02-14 11:10:30 +05:30
|
|
|
text += "partition "+prefix+".xml written ( "+str(len(database_for_unlinked_persons.get_person_keys()))+" persons)\n"
|
2003-10-14 02:36:29 +05:30
|
|
|
|
|
|
|
base = os.path.dirname(__file__)
|
|
|
|
glade_file = "%s/summary.glade" % base
|
|
|
|
|
|
|
|
topDialog = gtk.glade.XML(glade_file,"summary","gramps")
|
|
|
|
topDialog.signal_autoconnect({
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
|
|
})
|
|
|
|
|
|
|
|
top = topDialog.get_widget("summary")
|
|
|
|
textwindow = topDialog.get_widget("textwindow")
|
|
|
|
textwindow.get_buffer().set_text(text)
|
|
|
|
top.show()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from Plugins import register_report
|
|
|
|
|
|
|
|
register_report(
|
|
|
|
report,
|
|
|
|
_("Partitions"),
|
|
|
|
status=(_("Alpha")),
|
|
|
|
category=_("Export"),
|
|
|
|
description=_("This program partitions individuals in a database into disjoint partitions.\n"+
|
|
|
|
"A partition is composed of people related by one or more multiple relations.\n"+
|
|
|
|
"There should be no known relationship between people in different partitions.")
|
|
|
|
)
|
|
|
|
|