Command line imports: gedcom and iso
svn: r1552
This commit is contained in:
parent
7eded566a4
commit
f5c9c8f2cd
@ -1010,45 +1010,69 @@ class Gramps:
|
|||||||
|
|
||||||
def cl_export(self,filename,format):
|
def cl_export(self,filename,format):
|
||||||
if format == 'gedcom':
|
if format == 'gedcom':
|
||||||
print "Command-line export to gedcom is not implemented yet."
|
import WriteGedcom
|
||||||
os._exit(0)
|
try:
|
||||||
|
g = WriteGedcom.GedcomWriter(self.db,None,1,filename)
|
||||||
|
del g
|
||||||
|
except:
|
||||||
|
print "Error exporting %s" % filename
|
||||||
|
os._exit(1)
|
||||||
elif format == 'gramps':
|
elif format == 'gramps':
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
dbname = os.path.join(filename,const.xmlFile)
|
dbname = os.path.join(filename,const.xmlFile)
|
||||||
if filename:
|
if filename:
|
||||||
self.save_media(filename)
|
try:
|
||||||
self.db.save(dbname,None)
|
self.save_media(filename)
|
||||||
|
self.db.save(dbname,None)
|
||||||
|
except:
|
||||||
|
print "Error exporting %s" % filename
|
||||||
|
os._exit(1)
|
||||||
elif format == 'gramps-pkg':
|
elif format == 'gramps-pkg':
|
||||||
import TarFile
|
import TarFile
|
||||||
import time
|
import time
|
||||||
import WriteXML
|
import WriteXML
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
t = TarFile.TarFile(filename)
|
try:
|
||||||
mtime = time.time()
|
t = TarFile.TarFile(filename)
|
||||||
|
mtime = time.time()
|
||||||
|
except:
|
||||||
|
print "Error creating %s" % filename
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
# Write media files first, since the database may be modified
|
try:
|
||||||
# during the process (i.e. when removing object)
|
# Write media files first, since the database may be modified
|
||||||
ObjectMap = self.db.getObjectMap()
|
# during the process (i.e. when removing object)
|
||||||
for ObjectId in ObjectMap.keys():
|
ObjectMap = self.db.getObjectMap()
|
||||||
oldfile = ObjectMap[ObjectId].getPath()
|
for ObjectId in ObjectMap.keys():
|
||||||
base = os.path.basename(oldfile)
|
oldfile = ObjectMap[ObjectId].getPath()
|
||||||
if os.path.isfile(oldfile):
|
base = os.path.basename(oldfile)
|
||||||
g = open(oldfile,"rb")
|
if os.path.isfile(oldfile):
|
||||||
t.add_file(base,mtime,g)
|
g = open(oldfile,"rb")
|
||||||
g.close()
|
t.add_file(base,mtime,g)
|
||||||
|
g.close()
|
||||||
# Write XML now
|
except:
|
||||||
g = StringIO()
|
print "Error exporting media files to %s" % filename
|
||||||
gfile = WriteXML.XmlWriter(self.db,None,1)
|
os._exit(1)
|
||||||
gfile.write_handle(g)
|
try:
|
||||||
mtime = time.time()
|
# Write XML now
|
||||||
t.add_file("data.gramps",mtime,g)
|
g = StringIO()
|
||||||
g.close()
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||||
t.close()
|
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':
|
elif format == 'iso':
|
||||||
print "Command-line export to iso is not implemented yet."
|
import WriteCD
|
||||||
os._exit(0)
|
try:
|
||||||
|
WriteCD.PackageWriter(self.db,1,filename)
|
||||||
|
except:
|
||||||
|
print "Error exporting %s" % filename
|
||||||
|
os._exit(1)
|
||||||
else:
|
else:
|
||||||
print "Invalid format: %s" % format
|
print "Invalid format: %s" % format
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -1979,7 +2003,7 @@ class Gramps:
|
|||||||
except OSError,msg:
|
except OSError,msg:
|
||||||
ErrorDialog(_('Example database not created'),str(msg))
|
ErrorDialog(_('Example database not created'),str(msg))
|
||||||
|
|
||||||
self.read_file(dest)
|
self.read_file(dest)
|
||||||
|
|
||||||
DARKEN = 1.4
|
DARKEN = 1.4
|
||||||
|
|
||||||
|
@ -71,26 +71,30 @@ def writeData(database,person):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class PackageWriter:
|
class PackageWriter:
|
||||||
|
|
||||||
def __init__(self,database):
|
def __init__(self,database,cl=0,name=""):
|
||||||
self.db = database
|
self.db = database
|
||||||
|
self.cl = cl
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
if self.cl:
|
||||||
|
self.cl_run()
|
||||||
|
else:
|
||||||
|
base = os.path.dirname(__file__)
|
||||||
|
glade_file = "%s/%s" % (base,"cdexport.glade")
|
||||||
|
|
||||||
base = os.path.dirname(__file__)
|
dic = {
|
||||||
glade_file = "%s/%s" % (base,"cdexport.glade")
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
||||||
|
"on_ok_clicked" : self.on_ok_clicked
|
||||||
|
}
|
||||||
|
|
||||||
|
self.top = gtk.glade.XML(glade_file,"packageExport")
|
||||||
dic = {
|
|
||||||
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
||||||
"on_ok_clicked" : self.on_ok_clicked
|
|
||||||
}
|
|
||||||
|
|
||||||
self.top = gtk.glade.XML(glade_file,"packageExport")
|
|
||||||
|
|
||||||
Utils.set_titles(self.top.get_widget('packageExport'),
|
Utils.set_titles(self.top.get_widget('packageExport'),
|
||||||
self.top.get_widget('title'),
|
self.top.get_widget('title'),
|
||||||
_('Export to CD'))
|
_('Export to CD'))
|
||||||
|
|
||||||
self.top.signal_autoconnect(dic)
|
self.top.signal_autoconnect(dic)
|
||||||
self.top.get_widget("packageExport").show()
|
self.top.get_widget("packageExport").show()
|
||||||
|
|
||||||
def copy_file(self,src,dest):
|
def copy_file(self,src,dest):
|
||||||
original = open(src,"r")
|
original = open(src,"r")
|
||||||
@ -115,6 +119,36 @@ class PackageWriter:
|
|||||||
th.write(data)
|
th.write(data)
|
||||||
th.close()
|
th.close()
|
||||||
|
|
||||||
|
def cl_run(self):
|
||||||
|
base = os.path.basename(self.name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
uri = gnome.vfs.URI('burn:///%s' % base)
|
||||||
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
||||||
|
except gnome.vfs.error, msg:
|
||||||
|
print msg
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
uri = gnome.vfs.URI('burn:///%s/.thumb' % base)
|
||||||
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
||||||
|
except gnome.vfs.error, msg:
|
||||||
|
print msg
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
for obj in self.db.getObjectMap().values():
|
||||||
|
oldfile = obj.getPath()
|
||||||
|
root = os.path.basename(oldfile)
|
||||||
|
if os.path.isfile(oldfile):
|
||||||
|
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
||||||
|
if obj.getMimeType()[0:5] == "image":
|
||||||
|
self.make_thumbnail(base,root,obj.getPath())
|
||||||
|
# Write XML now
|
||||||
|
g = gnome.vfs.create('burn:///%s/data.gramps' % base,gnome.vfs.OPEN_WRITE )
|
||||||
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||||
|
gfile.write_handle(g)
|
||||||
|
g.close()
|
||||||
|
|
||||||
def on_ok_clicked(self,obj):
|
def on_ok_clicked(self,obj):
|
||||||
Utils.destroy_passed_object(obj)
|
Utils.destroy_passed_object(obj)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000 Donald N. Allingham
|
# Copyright (C) 2000-2003 Donald N. Allingham
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -334,7 +334,7 @@ def writeData(database,person):
|
|||||||
class GedcomWriter:
|
class GedcomWriter:
|
||||||
"""Writes a GEDCOM file from the passed database"""
|
"""Writes a GEDCOM file from the passed database"""
|
||||||
|
|
||||||
def __init__(self,db,person):
|
def __init__(self,db,person,cl=0,name=""):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.person = person
|
self.person = person
|
||||||
self.restrict = 1
|
self.restrict = 1
|
||||||
@ -350,66 +350,71 @@ class GedcomWriter:
|
|||||||
self.pidmap = {}
|
self.pidmap = {}
|
||||||
self.sidval = 0
|
self.sidval = 0
|
||||||
self.sidmap = {}
|
self.sidmap = {}
|
||||||
|
self.cl = cl
|
||||||
|
self.name = name
|
||||||
|
|
||||||
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
|
if self.cl:
|
||||||
|
self.cl_setup()
|
||||||
|
else:
|
||||||
|
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
|
||||||
|
|
||||||
|
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
||||||
|
self.topDialog.signal_autoconnect({
|
||||||
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
||||||
|
"gnu_free" : self.gnu_free,
|
||||||
|
"standard_copyright" : self.standard_copyright,
|
||||||
|
"no_copyright" : self.no_copyright,
|
||||||
|
"on_ok_clicked" : self.on_ok_clicked
|
||||||
|
})
|
||||||
|
|
||||||
|
Utils.set_titles(self.topDialog.get_widget('gedcomExport'),
|
||||||
|
self.topDialog.get_widget('title'),
|
||||||
|
_('GEDCOM export'))
|
||||||
|
|
||||||
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
filter_obj = self.topDialog.get_widget("filter")
|
||||||
self.topDialog.signal_autoconnect({
|
self.copy = 0
|
||||||
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
||||||
"gnu_free" : self.gnu_free,
|
|
||||||
"standard_copyright" : self.standard_copyright,
|
|
||||||
"no_copyright" : self.no_copyright,
|
|
||||||
"on_ok_clicked" : self.on_ok_clicked
|
|
||||||
})
|
|
||||||
|
|
||||||
Utils.set_titles(self.topDialog.get_widget('gedcomExport'),
|
all = GenericFilter.GenericFilter()
|
||||||
self.topDialog.get_widget('title'),
|
all.set_name(_("Entire Database"))
|
||||||
_('GEDCOM export'))
|
all.add_rule(GenericFilter.Everyone([]))
|
||||||
|
|
||||||
|
des = GenericFilter.GenericFilter()
|
||||||
|
des.set_name(_("Descendants of %s") % person.getPrimaryName().getName())
|
||||||
|
des.add_rule(GenericFilter.IsDescendantOf([person.getId()]))
|
||||||
|
|
||||||
|
ans = GenericFilter.GenericFilter()
|
||||||
|
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
|
||||||
|
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
|
||||||
|
|
||||||
|
com = GenericFilter.GenericFilter()
|
||||||
|
com.set_name(_("People with common ancestor with %s") %
|
||||||
|
person.getPrimaryName().getName())
|
||||||
|
com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()]))
|
||||||
|
|
||||||
|
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
|
||||||
|
filter_obj.set_menu(self.filter_menu)
|
||||||
|
|
||||||
|
gedmap = GedcomInfo.GedcomInfoDB()
|
||||||
|
|
||||||
|
target_obj = self.topDialog.get_widget("target")
|
||||||
|
myMenu = gtk.Menu()
|
||||||
|
for name in gedmap.get_name_list():
|
||||||
|
menuitem = gtk.MenuItem(name)
|
||||||
|
myMenu.append(menuitem)
|
||||||
|
data = gedmap.get_description(name)
|
||||||
|
menuitem.set_data("data",data)
|
||||||
|
menuitem.show()
|
||||||
|
|
||||||
|
target_obj.set_menu(myMenu)
|
||||||
|
self.target_menu = myMenu
|
||||||
|
|
||||||
|
pathname = "%s.ged" % os.path.dirname(db.getSavePath())
|
||||||
|
|
||||||
filter_obj = self.topDialog.get_widget("filter")
|
filetgt = self.topDialog.get_widget('fileentry1')
|
||||||
self.copy = 0
|
filetgt.set_filename(pathname)
|
||||||
|
|
||||||
all = GenericFilter.GenericFilter()
|
|
||||||
all.set_name(_("Entire Database"))
|
|
||||||
all.add_rule(GenericFilter.Everyone([]))
|
|
||||||
|
|
||||||
des = GenericFilter.GenericFilter()
|
|
||||||
des.set_name(_("Descendants of %s") % person.getPrimaryName().getName())
|
|
||||||
des.add_rule(GenericFilter.IsDescendantOf([person.getId()]))
|
|
||||||
|
|
||||||
ans = GenericFilter.GenericFilter()
|
|
||||||
ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName())
|
|
||||||
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
|
|
||||||
|
|
||||||
com = GenericFilter.GenericFilter()
|
|
||||||
com.set_name(_("People with common ancestor with %s") %
|
|
||||||
person.getPrimaryName().getName())
|
|
||||||
com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()]))
|
|
||||||
|
|
||||||
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
|
|
||||||
filter_obj.set_menu(self.filter_menu)
|
|
||||||
|
|
||||||
gedmap = GedcomInfo.GedcomInfoDB()
|
|
||||||
|
|
||||||
target_obj = self.topDialog.get_widget("target")
|
|
||||||
myMenu = gtk.Menu()
|
|
||||||
for name in gedmap.get_name_list():
|
|
||||||
menuitem = gtk.MenuItem(name)
|
|
||||||
myMenu.append(menuitem)
|
|
||||||
data = gedmap.get_description(name)
|
|
||||||
menuitem.set_data("data",data)
|
|
||||||
menuitem.show()
|
|
||||||
|
|
||||||
target_obj.set_menu(myMenu)
|
|
||||||
self.target_menu = myMenu
|
|
||||||
|
|
||||||
pathname = "%s.ged" % os.path.dirname(db.getSavePath())
|
|
||||||
|
|
||||||
filetgt = self.topDialog.get_widget('fileentry1')
|
|
||||||
filetgt.set_filename(pathname)
|
|
||||||
|
|
||||||
self.topDialog.get_widget("gedcomExport").show()
|
|
||||||
|
|
||||||
|
self.topDialog.get_widget("gedcomExport").show()
|
||||||
|
|
||||||
def gnu_free(self,obj):
|
def gnu_free(self,obj):
|
||||||
self.copy = 1
|
self.copy = 1
|
||||||
|
|
||||||
@ -487,6 +492,41 @@ class GedcomWriter:
|
|||||||
self.export_data(name)
|
self.export_data(name)
|
||||||
closebtn.set_sensitive(1)
|
closebtn.set_sensitive(1)
|
||||||
|
|
||||||
|
def cl_setup(self):
|
||||||
|
self.restrict = 0
|
||||||
|
self.private = 0
|
||||||
|
self.copy = 0
|
||||||
|
|
||||||
|
for p in self.db.getPersonKeys():
|
||||||
|
self.plist[p] = 1
|
||||||
|
|
||||||
|
gedmap = GedcomInfo.GedcomInfoDB()
|
||||||
|
self.target_ged = gedmap.standard
|
||||||
|
|
||||||
|
self.dest = self.target_ged.get_dest()
|
||||||
|
self.adopt = self.target_ged.get_adopt()
|
||||||
|
self.conc = self.target_ged.get_conc()
|
||||||
|
self.altname = self.target_ged.get_alt_name()
|
||||||
|
self.cal = self.target_ged.get_alt_calendar()
|
||||||
|
self.obje = self.target_ged.get_obje()
|
||||||
|
self.resi = self.target_ged.get_resi()
|
||||||
|
self.prefix = self.target_ged.get_prefix()
|
||||||
|
self.source_refs = self.target_ged.get_source_refs()
|
||||||
|
|
||||||
|
self.cnvtxt = keep_utf8
|
||||||
|
|
||||||
|
self.flist = {}
|
||||||
|
self.slist = {}
|
||||||
|
|
||||||
|
for key in self.plist.keys():
|
||||||
|
p = self.db.getPerson(key)
|
||||||
|
add_persons_sources(p,self.slist,self.private)
|
||||||
|
for family in p.getFamilyList():
|
||||||
|
add_familys_sources(family,self.slist,self.private)
|
||||||
|
self.flist[family.getId()] = 1
|
||||||
|
|
||||||
|
self.export_data(self.name)
|
||||||
|
|
||||||
def export_data(self,filename):
|
def export_data(self,filename):
|
||||||
try:
|
try:
|
||||||
self.g = open(filename,"w")
|
self.g = open(filename,"w")
|
||||||
@ -558,17 +598,19 @@ class GedcomWriter:
|
|||||||
for key in pkeys:
|
for key in pkeys:
|
||||||
self.write_person(self.db.getPerson(key))
|
self.write_person(self.db.getPerson(key))
|
||||||
index = index + 1
|
index = index + 1
|
||||||
if index%100 == 0:
|
if index%100 == 0 and not self.cl:
|
||||||
self.pbar.set_fraction(index/nump)
|
self.pbar.set_fraction(index/nump)
|
||||||
while(gtk.events_pending()):
|
while(gtk.events_pending()):
|
||||||
gtk.mainiteration()
|
gtk.mainiteration()
|
||||||
self.pbar.set_fraction(1.0)
|
if not self.cl:
|
||||||
|
self.pbar.set_fraction(1.0)
|
||||||
|
|
||||||
self.write_families()
|
self.write_families()
|
||||||
if self.source_refs:
|
if self.source_refs:
|
||||||
self.write_sources()
|
self.write_sources()
|
||||||
else:
|
else:
|
||||||
self.sbar.set_fraction(1.0)
|
if not self.cl:
|
||||||
|
self.sbar.set_fraction(1.0)
|
||||||
|
|
||||||
self.g.write("0 TRLR\n")
|
self.g.write("0 TRLR\n")
|
||||||
self.g.close()
|
self.g.close()
|
||||||
@ -666,11 +708,12 @@ class GedcomWriter:
|
|||||||
break
|
break
|
||||||
|
|
||||||
index = index + 1
|
index = index + 1
|
||||||
if index % 100 == 0:
|
if index % 100 == 0 and not self.cl:
|
||||||
self.fbar.set_fraction(index/nump)
|
self.fbar.set_fraction(index/nump)
|
||||||
while(gtk.events_pending()):
|
while(gtk.events_pending()):
|
||||||
gtk.mainiteration()
|
gtk.mainiteration()
|
||||||
self.fbar.set_fraction(1.0)
|
if not self.cl:
|
||||||
|
self.fbar.set_fraction(1.0)
|
||||||
|
|
||||||
def write_sources(self):
|
def write_sources(self):
|
||||||
nump = float(len(self.slist))
|
nump = float(len(self.slist))
|
||||||
@ -691,11 +734,12 @@ class GedcomWriter:
|
|||||||
if source.getNote():
|
if source.getNote():
|
||||||
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
|
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
|
||||||
index = index + 1
|
index = index + 1
|
||||||
if index % 100 == 0:
|
if index % 100 == 0 and not self.cl:
|
||||||
self.sbar.set_fraction(index/nump)
|
self.sbar.set_fraction(index/nump)
|
||||||
while(gtk.events_pending()):
|
while(gtk.events_pending()):
|
||||||
gtk.mainiteration()
|
gtk.mainiteration()
|
||||||
self.sbar.set_fraction(1.0)
|
if not self.cl:
|
||||||
|
self.sbar.set_fraction(1.0)
|
||||||
|
|
||||||
def write_person(self,person):
|
def write_person(self,person):
|
||||||
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId()))
|
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId()))
|
||||||
|
Loading…
Reference in New Issue
Block a user