* 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 3ca70aac2d
commit 14052b42db
9 changed files with 297 additions and 349 deletions

View File

@ -1,3 +1,14 @@
2005-02-19 Alex Roitman <shura@alex.neuro.umn.edu>
* 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.
2005-02-18 Don Allingham <dallingham@users.sourceforge.net>
* src/EditPerson.py: more readonly patches
* src/EventEdit.py: more readonly patches

View File

@ -152,7 +152,7 @@ class ArgHandler:
if opt_ix<len(options)-1 \
and options[opt_ix+1][0] in ( '-f', '--format'):
format = options[opt_ix+1][1]
if format not in ('gedcom','gramps-xml','gramps-pkg','grdb'):
if format not in ('gedcom','gramps-xml','gramps-pkg','grdb','geneweb'):
print "Invalid format: %s" % format
print "Ignoring input file: %s" % fname
continue
@ -164,6 +164,8 @@ class ArgHandler:
format = 'gramps-xml'
elif ftype == const.app_gramps:
format = 'grdb'
elif ftype == const.app_geneweb:
format = 'geneweb'
else:
print "Unrecognized format for input file %s" % fname
print "Ignoring input file: %s" % fname
@ -174,7 +176,7 @@ class ArgHandler:
if opt_ix<len(options)-1 \
and options[opt_ix+1][0] in ( '-f', '--format'):
outformat = options[opt_ix+1][1]
if outformat not in ('gedcom','gramps-xml','gramps-pkg','grdb','iso','wft'):
if outformat not in ('gedcom','gramps-xml','gramps-pkg','grdb','iso','wft','geneweb'):
print "Invalid format: %s" % outformat
print "Ignoring output file: %s" % outfname
continue
@ -184,6 +186,8 @@ class ArgHandler:
outformat = 'gramps-pkg'
elif outfname[-3:].upper() == "WFT":
outformat = 'wft'
elif outfname[-2:].upper() == "GW":
outformat = 'geneweb'
elif not os.path.isfile(outfname):
if not os.path.isdir(outfname):
try:
@ -426,6 +430,14 @@ class ArgHandler:
except:
print "Error importing %s" % filename
os._exit(1)
elif format == 'geneweb':
import ImportGeneWeb
filename = os.path.normpath(os.path.abspath(filename))
try:
ImportGeneWeb.importData(self.parent.db,filename,None)
except:
print "Error importing %s" % filename
os._exit(1)
elif format == 'gramps-pkg':
# Create tempdir, if it does not exist, then check for writability
tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
@ -484,8 +496,8 @@ class ArgHandler:
if format == 'gedcom':
import WriteGedcom
try:
g = WriteGedcom.GedcomWriter(self.parent.db,None,1,filename)
del g
gw = WriteGedcom.GedcomWriter(self.parent.db,None,1,filename)
ret = gw.export_data(filename)
except:
print "Error exporting %s" % filename
os._exit(1)
@ -494,63 +506,41 @@ class ArgHandler:
dbname = os.path.join(filename,const.xmlFile)
if filename:
try:
self.parent.save_media(filename)
self.parent.db.save(dbname,None)
import WriteXML
g = WriteXML.XmlWriter(self.parent.db,None,1,1)
ret = g.write(dbname)
except:
print "Error exporting %s" % filename
os._exit(1)
elif format == 'gramps-pkg':
import TarFile
import WriteXML
from cStringIO import StringIO
try:
t = TarFile.TarFile(filename)
mtime = time.time()
import WritePkg
writer = WritePkg.PackageWriter(self.parent.db,filename)
ret = writer.export()
except:
print "Error creating %s" % filename
os._exit(1)
try:
# Write media files first, since the database may be modified
# during the process (i.e. when removing object)
for m_id in self.parent.db.get_media_object_handles():
mobject = self.parent.db.get_object_from_handle(m_id)
oldfile = mobject.get_path()
base = os.path.basename(oldfile)
if os.path.isfile(oldfile):
g = open(oldfile,"rb")
t.add_file(base,mtime,g)
g.close()
else:
print "Warning: media file %s was not found," % base,\
"so it was ignored."
except:
print "Error exporting media files to %s" % filename
os._exit(1)
try:
# Write XML now
g = StringIO()
gfile = WriteXML.XmlWriter(self.parent.db,None,1)
gfile.write_handle(g)
mtime = time.time()
t.add_file("data.gramps",mtime,g)
g.close()
t.close()
except:
print "Error exporting data to %s" % filename
os._exit(1)
elif format == 'iso':
import WriteCD
try:
WriteCD.PackageWriter(self.parent.db,1,filename)
except:
print "Error exporting %s" % filename
os._exit(1)
print "\tISO format is temporarily disabled."
#import WriteCD
#try:
# WriteCD.PackageWriter(self.parent.db,1,filename)
#except:
# print "Error exporting %s" % filename
# os._exit(1)
elif format == 'wft':
import WriteFtree
try:
WriteFtree.FtreeWriter(self.parent.db,None,1,filename)
writer = WriteFtree.FtreeWriter(self.parent.db,None,1,filename)
ret = writer.export_data()
except:
print "Error exporting %s" % filename
os._exit(1)
elif format == 'geneweb':
import WriteGeneWeb
try:
writer = WriteGeneWeb.GeneWebWriter(self.parent.db,None,1,filename)
ret = writer.export_data()
except:
print "Error exporting %s" % filename
os._exit(1)

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004 Donald N. Allingham
# Copyright (C) 2004-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
@ -20,9 +20,7 @@
# $Id$
#
# Written by Alex Roitman, 2004
#
# Written by Alex Roitman
#-------------------------------------------------------------------------
#
@ -121,8 +119,7 @@ class Exporter:
"""
Help handler.
"""
#FIXME: point to the correct section when it exists
gnome.help_display('gramps-manual','index')
gnome.help_display('gramps-manual','export-data')
def build_info_page(self):
"""

View File

@ -42,10 +42,11 @@ from TransTable import TransTable
# Mime Types
#
#-------------------------------------------------------------------------
app_gramps = "application/x-gramps"
app_gramps_xml = "application/x-gramps-xml"
app_gedcom = "application/x-gedcom"
app_gramps_package = "application/x-gramps-package"
app_gramps = "application/x-gramps"
app_gramps_xml = "application/x-gramps-xml"
app_gedcom = "application/x-gedcom"
app_gramps_package = "application/x-gramps-package"
app_geneweb = "application/x-geneweb"
#-------------------------------------------------------------------------
#

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Martin Hawlisch, Donald N. Allingham
# Copyright (C) 2000-2005 Martin Hawlisch, 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,9 +29,8 @@
#-------------------------------------------------------------------------
import os
import re
import string
import const
import time
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -48,13 +47,11 @@ import gtk.glade
#-------------------------------------------------------------------------
import Errors
import RelLib
import Date
import DateHandler
import latin_utf8
import Utils
import const
from QuestionDialog import ErrorDialog
from gettext import gettext as _
from DateHandler import parser as _dp
#-------------------------------------------------------------------------
#
@ -98,7 +95,6 @@ class GeneWebParser:
self.db = dbase
self.f = open(file,"rU")
self.filename = file
self.dp = DateHandler.create_parser()
def get_next_line(self):
line = self.f.readline()
@ -133,7 +129,7 @@ class GeneWebParser:
fields = line.split(" ")
print "LINE: %s" %line
#print "LINE: %s" %line
if fields[0] == "fam":
self.read_family_line(line,fields)
elif fields[0] == "src":
@ -173,7 +169,7 @@ class GeneWebParser:
self.fkeys.append(self.current_family.get_handle())
idx = 1;
print "\nHusband:"
#print "\nHusband:"
(idx,husband) = self.parse_person(fields,idx,RelLib.Person.MALE,None)
if husband:
self.current_husband_handle = husband.get_handle()
@ -181,9 +177,9 @@ class GeneWebParser:
self.db.commit_family(self.current_family,self.trans)
husband.add_family_handle(self.current_family.get_handle())
self.db.commit_person(husband,self.trans)
print "Marriage:"
#print "Marriage:"
idx = self.parse_marriage(fields,idx)
print "Wife:"
#print "Wife:"
(idx,wife) = self.parse_person(fields,idx,RelLib.Person.FEMALE,None)
if wife:
self.current_family.set_mother_handle(wife.get_handle())
@ -194,15 +190,15 @@ class GeneWebParser:
def read_source_line(self,line,fields):
if not self.current_family:
print "Unknown family of child!"
return None
print "Unknown family of child!"
return None
source = self.get_or_create_source(self.decode(fields[1]))
self.current_family.add_source_reference(source)
self.db.commit_family(self.current_family,self.trans)
return None
def read_witness_line(self,line,fields):
print "Witness:"
#print "Witness:"
if fields[1] == "m:":
self.parse_person(fields,2,RelLib.Person.MALE,None)
elif fields[1] == "f:":
@ -219,8 +215,8 @@ class GeneWebParser:
husb = self.db.get_person_from_handle(self.current_husband_handle)
father_surname = husb.get_primary_name().get_surname()
if not self.current_family:
print "Unknown family of child!"
return None
print "Unknown family of child!"
return None
while 1:
line = self.get_next_line()
if line == None:
@ -230,7 +226,7 @@ class GeneWebParser:
fields = line.split(" ")
if fields[0] == "-":
print "Child:"
#print "Child:"
child = None
if fields[1] == "h":
(idx,child) = self.parse_person(fields,2,RelLib.Person.MALE,father_surname)
@ -254,8 +250,8 @@ class GeneWebParser:
def read_family_comment(self,line,fields):
if not self.current_family:
print "Unknown family of child!"
return None
print "Unknown family of child!"
return None
self.current_family.set_note(self.cnv(line))
self.db.commit_family(self.current_family,self.trans)
return None
@ -299,7 +295,7 @@ class GeneWebParser:
# skip to marriage date in case person contained unmatches tokens
#Alex: this failed when fields[idx] was an empty line. Fixed.
#while idx < len(fields) and not fields[idx][0] == "+":
#while idx < len(fields) and not fields[idx][0] == "+":
while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"):
print "Unknown field: "+fields[idx]
idx = idx + 1
@ -307,33 +303,33 @@ class GeneWebParser:
while idx < len(fields) and mariageDataRe.match(fields[idx]):
if fields[idx][0] == "+":
mar_date = self.parse_date(self.decode(fields[idx]))
print " Married at: %s" % fields[idx]
#print " Married at: %s" % fields[idx]
idx = idx + 1
elif fields[idx][0] == "-":
div_date = self.parse_date(self.decode(fields[idx]))
print " Div at: %s" % fields[idx]
#print " Div at: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == "#mp":
idx = idx + 1
mar_place = self.get_or_create_place(self.decode(fields[idx]))
print " Marriage place: %s" % fields[idx]
#print " Marriage place: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == "#ms":
idx = idx + 1
mar_source = self.get_or_create_source(self.decode(fields[idx]))
print " Marriage source: %s" % fields[idx]
#print " Marriage source: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == "#sep":
idx = idx + 1
sep_date = self.parse_date(self.decode(fields[idx]))
print " Seperated since: %s" % fields[idx]
#print " Seperated since: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == "#np":
print " Are not married."
#print " Are not married."
married = 0
idx = idx + 1
elif fields[idx] == "#eng":
print " Are engaged."
#print " Are engaged."
engaged = 1
idx = idx + 1
else:
@ -385,7 +381,7 @@ class GeneWebParser:
surname = self.decode(fields[idx])
idx = idx + 1
print "Person: %s %s" % (firstname, surname)
#print "Person: %s %s" % (firstname, surname)
person = self.get_or_create_person(firstname,surname)
name = RelLib.Name()
name.set_type("Birth Name")
@ -424,113 +420,113 @@ class GeneWebParser:
while idx < len(fields) and personDataRe.match(fields[idx]):
if fields[idx][0] == '(':
print "Public Name: %s" % fields[idx]
#print "Public Name: %s" % fields[idx]
public_name = self.decode(fields[idx])
idx = idx + 1
elif fields[idx][0] == '{':
print "Firstsname Alias: %s" % fields[idx]
#print "Firstsname Alias: %s" % fields[idx]
firstname_aliases.append(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx][0] == '[':
print "Titles: %s" % fields[idx]
#print "Titles: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == '#nick':
idx = idx + 1
print "Nick Name: %s" % fields[idx]
#print "Nick Name: %s" % fields[idx]
nick_names.append(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#occu':
idx = idx + 1
print "Occupation: %s" % fields[idx]
#print "Occupation: %s" % fields[idx]
occu = self.create_event("Occupation",self.decode(fields[idx]))
person.add_event_handle(occu.get_handle())
self.db.commit_person(person,self.trans)
idx = idx + 1
elif fields[idx] == '#alias':
idx = idx + 1
print "Name Alias: %s" % fields[idx]
#print "Name Alias: %s" % fields[idx]
name_aliases.append(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#salias':
idx = idx + 1
print "Surname Alias: %s" % fields[idx]
#print "Surname Alias: %s" % fields[idx]
surname_aliases.append(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#image':
idx = idx + 1
print "Image: %s" % fields[idx]
#print "Image: %s" % fields[idx]
idx = idx + 1
elif fields[idx] == '#src':
idx = idx + 1
print "Source: %s" % fields[idx]
#print "Source: %s" % fields[idx]
source = self.get_or_create_source(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#bs':
idx = idx + 1
print "Birth Source: %s" % fields[idx]
#print "Birth Source: %s" % fields[idx]
birth_source = self.get_or_create_source(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx][0] == '!':
print "Baptize at: %s" % fields[idx]
#print "Baptize at: %s" % fields[idx]
bapt_date = self.parse_date(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#bp':
idx = idx + 1
print "Birth Place: %s" % fields[idx]
#print "Birth Place: %s" % fields[idx]
birth_place = self.get_or_create_place(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#pp':
idx = idx + 1
print "Baptize Place: %s" % fields[idx]
#print "Baptize Place: %s" % fields[idx]
bapt_place = self.get_or_create_place(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#ps':
idx = idx + 1
print "Baptize Source: %s" % fields[idx]
#print "Baptize Source: %s" % fields[idx]
bapt_source = self.get_or_create_source(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#dp':
idx = idx + 1
print "Death Place: %s" % fields[idx]
#print "Death Place: %s" % fields[idx]
death_place = self.get_or_create_place(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#ds':
idx = idx + 1
print "Death Source: %s" % fields[idx]
#print "Death Source: %s" % fields[idx]
death_source = self.get_or_create_source(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#buri':
idx = idx + 1
print "Burial Date: %s" % fields[idx]
#print "Burial Date: %s" % fields[idx]
bur_date = self.parse_date(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#crem':
idx = idx + 1
print "Cremention Date: %s" % fields[idx]
#print "Cremention Date: %s" % fields[idx]
crem_date = self.parse_date(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#bp':
idx = idx + 1
print "Burial Place: %s" % fields[idx]
#print "Burial Place: %s" % fields[idx]
bur_place = self.get_or_create_place(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#rs':
idx = idx + 1
print "Burial Source: %s" % fields[idx]
#print "Burial Source: %s" % fields[idx]
bur_source = self.get_or_create_source(self.decode(fields[idx]))
idx = idx + 1
elif fields[idx] == '#apubl':
print "This is a public record"
#print "This is a public record"
idx = idx + 1
elif fields[idx] == '#apriv':
print "This is a private record"
#print "This is a private record"
idx = idx + 1
elif dateRe.match( fields[idx]):
if not birth_date:
print "Birth Date: %s" % fields[idx]
#print "Birth Date: %s" % fields[idx]
birth_date = self.parse_date(self.decode(fields[idx]))
else:
print "Death Date: %s" % fields[idx]
#print "Death Date: %s" % fields[idx]
death_date = self.parse_date(self.decode(fields[idx]))
idx = idx + 1
else:
@ -611,8 +607,7 @@ class GeneWebParser:
return (idx,person)
def parse_date(self,field):
#Alex: this should do the trick
date = self.dp.parse(field)
date = _dp.parse(field)
return date
def create_event(self,type,desc=None,date=None,place=None,source=None):
@ -680,11 +675,10 @@ class GeneWebParser:
#
#
#-------------------------------------------------------------------------
_mime_type = 'application/x-geneweb'
_mime_type = const.app_geneweb
_filter = gtk.FileFilter()
_filter.set_name(_('GeneWeb files'))
_filter.add_mime_type(_mime_type)
from PluginMgr import register_import
register_import(importData,_filter,_mime_type,1)

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)

View File

@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004 Martin Hawlisch
# Copyright (C) 2004-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
@ -27,9 +28,9 @@
#
#-------------------------------------------------------------------------
import os
import string
import time
import re
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -51,12 +52,8 @@ import const
import Utils
import Date
import Errors
from gettext import gettext as _
from QuestionDialog import ErrorDialog
_title_string = _("Export to GeneWeb")
#-------------------------------------------------------------------------
#
#
@ -204,17 +201,17 @@ class GeneWebWriter:
def writeln(self,text):
self.g.write(self.iso8859('%s\n' % (text)))
def export_data(self,filename):
def export_data(self):
self.dirname = os.path.dirname (filename)
self.dirname = os.path.dirname (self.filename)
try:
self.g = open(filename,"w")
self.g = open(self.filename,"w")
except IOError,msg:
msg2 = _("Could not create %s") % filename
msg2 = _("Could not create %s") % self.filename
ErrorDialog(msg2,str(msg))
return 0
except:
ErrorDialog(_("Could not create %s") % filename)
ErrorDialog(_("Could not create %s") % self.filename)
return 0
if len(self.flist) < 1:
@ -566,7 +563,7 @@ def exportData(database,filename,person,option_box):
ret = 0
try:
gw = GeneWebWriter(database,person,0,filename,option_box)
ret = gw.export_data(filename)
ret = gw.export_data()
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
@ -577,11 +574,10 @@ def exportData(database,filename,person,option_box):
#
#
#-------------------------------------------------------------------------
_title = _('GeneWeb')
_title = _('G_eneWeb')
_description = _('GeneWeb is a web based genealogy program.')
_config = (_('GeneWeb export options'),GeneWebWriterOptionBox)
_filename = 'gw'
from PluginMgr import register_export
register_export(exportData,_title,_description,_config,_filename)

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Donald N. Allingham
# Copyright (C) 2000-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
@ -30,6 +30,7 @@
import time
import os
from cStringIO import StringIO
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -49,20 +50,21 @@ import TarFile
import Utils
from QuestionDialog import MissingMediaDialog
from gettext import gettext as _
_title_string = _("Export to GRAMPS package")
#-------------------------------------------------------------------------
#
# writeData
#
#-------------------------------------------------------------------------
def writeData(database,filename):
def writeData(database,filename,person,callback=None):
ret = 0
try:
PackageWriter(database,filename)
writer = PackageWriter(database,filename)
ret = writer.export()
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
return ret
#-------------------------------------------------------------------------
#
@ -76,9 +78,10 @@ class PackageWriter:
if os.path.splitext(filename)[1] != ".gpkg":
filename = filename + ".gpkg"
self.export(filename)
self.filename = filename
def export(self, filename):
def export(self):
missmedia_action = 0
#--------------------------------------------------------------
def remove_clicked():
@ -129,7 +132,6 @@ class PackageWriter:
# File is lost => do nothing, leave as is
pass
def select_clicked():
# File is lost => select a file to replace the lost one
def fs_close_window(obj):
@ -150,7 +152,7 @@ class PackageWriter:
fs_top.destroy()
#---------------------------------------------------------------
t = TarFile.TarFile(filename)
t = TarFile.TarFile(self.filename)
mtime = time.time()
# Write media files first, since the database may be modified
@ -190,18 +192,17 @@ class PackageWriter:
g.close()
t.close()
return 1
#-------------------------------------------------------------------------
#
# Register the plugin
#
#-------------------------------------------------------------------------
_mime_type = 'application/x-gramps-package'
_filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS packages'))
_filter.add_mime_type(_mime_type)
_ext_list = ('.gpkg',)
_title = _('GRAM_PS package')
_description = _('GRAMPS package is an archived XML database together with the media object files.')
_config = None
_filename = 'gpkg'
from PluginMgr import register_export
register_export(writeData,_filter,_ext_list)
register_export(writeData,_title,_description,_config,_filename)

View File

@ -13,6 +13,11 @@
<property name="default_width">480</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
@ -34,6 +39,7 @@
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="destroy_passed_object" object="gedcomExport"/>
</widget>
@ -47,6 +53,7 @@
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_ok_clicked" object="gedcomExport"/>
</widget>
@ -60,6 +67,7 @@
<property name="label">gtk-help</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-11</property>
<signal name="clicked" handler="on_help_clicked" last_modification_time="Tue, 02 Dec 2003 02:01:12 GMT"/>
</widget>
@ -104,48 +112,16 @@
<widget class="GtkTable" id="table3">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">5</property>
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<widget class="GnomeFileEntry" id="fileentry1">
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="history_id">ftree_export</property>
<property name="max_saved">10</property>
<property name="browse_dialog_title" translatable="yes">Export GEDCOM</property>
<property name="directory_entry">False</property>
<property name="modal">True</property>
<child internal-child="entry">
<widget class="GtkEntry" id="filename">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="activates_default">False</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Filename&lt;/b&gt;</property>
<property name="label" translatable="yes">&lt;b&gt;Options&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
@ -166,51 +142,6 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Options&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="restrict">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Restrict data on living people</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
@ -225,16 +156,13 @@
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">filter</property>
<accessibility>
<atkrelation target="filter" type="label-for"/>
</accessibility>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">shrink|fill</property>
<property name="y_options"></property>
</packing>
</child>
@ -254,8 +182,30 @@
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="restrict">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Restrict data on living people</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>