* src/ArgHandler.py: Command line support for geneweb import

and export; Fix command line exports for gedcom, XML, and package.
* src/Exporter.py (help): Point to correct manual section.
* src/const.py.in: Add a constant for geneweb mime type name.
* src/plugins/WriteFtree.py: Support wizard and fix command line mode.
* src/plugins/writeftree.glade: Support export wizard.
* src/plugins/WritePkg.py: Support wizard and fix command line mode.
* src/plugins/ImportGeneWeb.py: Comment out debugging messages.
* src/plugins/WriteGeneWeb.py: Support for command-line export.


svn: r4054
This commit is contained in:
Alex Roitman
2005-02-19 19:05:48 +00:00
parent c9f66dad82
commit 329e8b6f3d
9 changed files with 297 additions and 349 deletions

View File

@@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2003-2004 Donald N. Allingham
# Copyright (C) 2003-2005 Donald N. Allingham
#
# 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
@@ -29,6 +29,7 @@
#-------------------------------------------------------------------------
import os
from cStringIO import StringIO
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@@ -47,25 +48,70 @@ import gnome
import Utils
import GenericFilter
import Errors
from QuestionDialog import ErrorDialog
from gettext import gettext as _
_title_string = _("Export to Web Family Tree")
#-------------------------------------------------------------------------
#
# writeData
#
#-------------------------------------------------------------------------
def writeData(database,person):
def writeData(database,filename,person,option_box):
ret = 0
try:
FtreeWriter(database,person)
writer = FtreeWriter(database,person,0,filename,option_box)
ret = writer.export_data()
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
return ret
class FtreeWriterOptionBox:
"""
Create a VBox with the option widgets and define methods to retrieve
the options.
"""
def __init__(self,person):
self.person = person
def get_option_box(self):
self.restrict = True
base = os.path.dirname(__file__)
glade_file = "%s/%s" % (base,"writeftree.glade")
self.top = gtk.glade.XML(glade_file,"top","gramps")
filter_obj = self.top.get_widget("filter")
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
des = GenericFilter.GenericFilter()
des.set_name(_("Descendants of %s") % self.person.get_primary_name().get_name())
des.add_rule(GenericFilter.IsDescendantOf([self.person.get_handle(),1]))
ans = GenericFilter.GenericFilter()
ans.set_name(_("Ancestors of %s") % self.person.get_primary_name().get_name())
ans.add_rule(GenericFilter.IsAncestorOf([self.person.get_handle(),1]))
com = GenericFilter.GenericFilter()
com.set_name(_("People with common ancestor with %s") %
self.person.get_primary_name().get_name())
com.add_rule(GenericFilter.HasCommonAncestorWith([self.person.get_handle()]))
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
filter_obj.set_menu(self.filter_menu)
the_box = self.top.get_widget("vbox1")
the_parent = self.top.get_widget('dialog-vbox1')
the_parent.remove(the_box)
self.top.get_widget("top").destroy()
return the_box
def parse_options(self):
self.restrict = self.top.get_widget("restrict").get_active()
self.cfilter = self.filter_menu.get_active().get_data("filter")
#-------------------------------------------------------------------------
#
# FtreeWriter
@@ -73,93 +119,39 @@ def writeData(database,person):
#-------------------------------------------------------------------------
class FtreeWriter:
def __init__(self,database,person,cl=0,name=""):
def __init__(self,database,person,cl=0,filename="",option_box=None):
self.db = database
self.person = person
self.option_box = option_box
self.cl = cl
self.filename = filename
self.plist = {}
if cl:
if name:
self.export(name,None,0)
if not option_box:
self.cl_setup()
else:
base = os.path.dirname(__file__)
glade_file = "%s/%s" % (base,"writeftree.glade")
dic = {
"destroy_passed_object" : self.close,
"on_ok_clicked" : self.on_ok_clicked,
"on_help_clicked" : self.on_help_clicked,
}
self.option_box.parse_options()
self.top = gtk.glade.XML(glade_file,"top","gramps")
self.restrict = self.option_box.restrict
if self.option_box.cfilter == None:
for p in self.db.get_person_handles(sort_handles=False):
self.plist[p] = 1
else:
try:
for p in self.option_box.cfilter.apply(self.db, self.db.get_person_handles(sort_handles=False)):
self.plist[p] = 1
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
return
Utils.set_titles(self.top.get_widget('top'),
self.top.get_widget('title'),
_title_string)
self.top.signal_autoconnect(dic)
def cl_setup(self):
self.restrict = True
for p in self.db.get_person_handles(sort_handles=False):
self.plist[p] = 1
self.topwin = self.top.get_widget("top")
self.restrict = self.top.get_widget("restrict")
self.filter = self.top.get_widget("filter")
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
des = GenericFilter.GenericFilter()
des.set_name(_("Descendants of %s") % person.get_primary_name().get_name())
des.add_rule(GenericFilter.IsDescendantOf([person.get_handle(),1]))
ans = GenericFilter.GenericFilter()
ans.set_name(_("Ancestors of %s") % person.get_primary_name().get_name())
ans.add_rule(GenericFilter.IsAncestorOf([person.get_handle(),1]))
com = GenericFilter.GenericFilter()
com.set_name(_("People with common ancestor with %s") %
person.get_primary_name().get_name())
com.add_rule(GenericFilter.HasCommonAncestorWith([person.get_handle()]))
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
self.filter.set_menu(self.filter_menu)
self.topwin.show()
def close(self,obj):
self.topwin.destroy()
def on_ok_clicked(self,obj):
name = self.top.get_widget("filename").get_text()
restrict = self.top.get_widget('restrict').get_active()
pfilter = self.filter_menu.get_active().get_data("filter")
Utils.destroy_passed_object(self.topwin)
try:
self.export(name, pfilter, restrict)
except (IOError,OSError),msg:
ErrorDialog(_("Could not create %s") % name, msg)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
gnome.help_display('gramps-manual','export-data')
def export(self, filename, cfilter, restrict ):
if cfilter == None:
for p in self.db.get_person_handles(sort_handles=False):
self.plist[p] = 1
else:
try:
for p in cfilter.apply(self.db, self.db.get_person_handle_map().values()):
self.plist[p.get_handle()] = 1
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
return
def export_data(self):
name_map = {}
id_map = {}
id_name = {}
@@ -187,7 +179,7 @@ class FtreeWriter:
id_map[key] = n
id_name[key] = get_name(pn,count)
f = open(filename,"w")
f = open(self.filename,"w")
for key in self.plist:
p = self.db.get_person_from_handle(key)
@@ -197,31 +189,42 @@ class FtreeWriter:
email = ""
web = ""
family = p.get_main_parents_family_handle()
if family:
if family.get_father_handle() and id_map.has_key(family.get_father_handle().get_handle()):
father = id_map[family.get_father_handle().get_handle()]
if family.get_mother_handle() and id_map.has_key(family.get_mother_handle().get_handle()):
mother = id_map[family.get_mother_handle().get_handle()]
family_handle = p.get_main_parents_family_handle()
if family_handle:
family = self.db.get_family_from_handle(family_handle)
if family.get_father_handle() and id_map.has_key(family.get_father_handle()):
father = id_map[family.get_father_handle()]
if family.get_mother_handle() and id_map.has_key(family.get_mother_handle()):
mother = id_map[family.get_mother_handle()]
#
# Calculate Date
#
birth = p.get_birth().get_date_object()
death = p.get_death().get_date_object()
birth_handle = p.get_birth_handle()
death_handle = p.get_death_handle()
if birth_handle:
birth_event = self.db.get_event_from_handle(birth_handle)
birth = birth_event.get_date_object()
else:
birth = None
if death_handle:
death_event = self.db.get_event_from_handle(death_handle)
death = death_event.get_date_object()
else:
death = None
if restrict:
if self.restrict:
alive = Utils.probably_alive(p,self.db)
else:
alive = 0
if birth.isValid() and not alive:
if death.isValid() and not alive :
if birth and not alive:
if death and not alive :
dates = "%s-%s" % (fdate(birth),fdate(death))
else:
dates = fdate(birth)
else:
if death.isValid() and not alive:
if death and not alive:
dates = fdate(death)
else:
dates = ""
@@ -229,16 +232,17 @@ class FtreeWriter:
f.write('%s;%s;%s;%s;%s;%s\n' % (name,father,mother,email,web,dates))
f.close()
return 1
def fdate(val):
if val.getYearValid():
if val.getMonthValid():
if val.getDayValid():
return "%d/%d/%d" % (val.getDay(),val.getMonth(),val.getYear())
if val.get_year_valid():
if val.get_month_valid():
if val.get_day_valid():
return "%d/%d/%d" % (val.get_day(),val.get_month(),val.get_year())
else:
return "%d/%d" % (val.getMonth(),val.getYear())
return "%d/%d" % (val.get_month(),val.get_year())
else:
return "%d" % val.getYear()
return "%d" % val.get_year()
else:
return ""
@@ -250,22 +254,26 @@ def get_name(name,count):
else:
val = str(count)
if (name.Suffix == ""):
if name.Prefix:
return "%s %s %s%s" % (name.FirstName, name.Prefix, name.Surname, val)
if (name.suffix == ""):
if name.prefix:
return "%s %s %s%s" % (name.first_name, name.prefix, name.surname, val)
else:
return "%s %s%s" % (name.FirstName, name.Surname, val)
return "%s %s%s" % (name.first_name, name.surname, val)
else:
if name.Prefix:
return "%s %s %s%s, %s" % (name.FirstName, name.Prefix, name.Surname, val, name.Suffix)
if name.prefix:
return "%s %s %s%s, %s" % (name.first_name, name.prefix, name.surname, val, name.Suffix)
else:
return "%s %s%s, %s" % (name.FirstName, name.Surname, val, name.Suffix)
return "%s %s%s, %s" % (name.first_name, name.surname, val, name.suffix)
#-------------------------------------------------------------------------
#
# Register the plugin
#
#-------------------------------------------------------------------------
from PluginMgr import register_export
_title = _('_Web Family Tree')
_description = _('Web Family Tree format.')
_config = (_('Web Family Tree export options'),FtreeWriterOptionBox)
_filename = 'wft'
register_export(writeData,_title_string)
from PluginMgr import register_export
register_export(writeData,_title,_description,_config,_filename)