Command line imports: gedcom and iso
svn: r1552
This commit is contained in:
parent
74181893a6
commit
dff8864a3f
@ -1010,23 +1010,37 @@ class Gramps:
|
||||
|
||||
def cl_export(self,filename,format):
|
||||
if format == 'gedcom':
|
||||
print "Command-line export to gedcom is not implemented yet."
|
||||
os._exit(0)
|
||||
import WriteGedcom
|
||||
try:
|
||||
g = WriteGedcom.GedcomWriter(self.db,None,1,filename)
|
||||
del g
|
||||
except:
|
||||
print "Error exporting %s" % filename
|
||||
os._exit(1)
|
||||
elif format == 'gramps':
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
dbname = os.path.join(filename,const.xmlFile)
|
||||
if filename:
|
||||
try:
|
||||
self.save_media(filename)
|
||||
self.db.save(dbname,None)
|
||||
except:
|
||||
print "Error exporting %s" % filename
|
||||
os._exit(1)
|
||||
elif format == 'gramps-pkg':
|
||||
import TarFile
|
||||
import time
|
||||
import WriteXML
|
||||
from cStringIO import StringIO
|
||||
|
||||
try:
|
||||
t = TarFile.TarFile(filename)
|
||||
mtime = time.time()
|
||||
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)
|
||||
ObjectMap = self.db.getObjectMap()
|
||||
@ -1037,7 +1051,10 @@ class Gramps:
|
||||
g = open(oldfile,"rb")
|
||||
t.add_file(base,mtime,g)
|
||||
g.close()
|
||||
|
||||
except:
|
||||
print "Error exporting media files to %s" % filename
|
||||
os._exit(1)
|
||||
try:
|
||||
# Write XML now
|
||||
g = StringIO()
|
||||
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||
@ -1046,9 +1063,16 @@ class Gramps:
|
||||
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':
|
||||
print "Command-line export to iso is not implemented yet."
|
||||
os._exit(0)
|
||||
import WriteCD
|
||||
try:
|
||||
WriteCD.PackageWriter(self.db,1,filename)
|
||||
except:
|
||||
print "Error exporting %s" % filename
|
||||
os._exit(1)
|
||||
else:
|
||||
print "Invalid format: %s" % format
|
||||
os._exit(1)
|
||||
|
@ -71,13 +71,17 @@ def writeData(database,person):
|
||||
#-------------------------------------------------------------------------
|
||||
class PackageWriter:
|
||||
|
||||
def __init__(self,database):
|
||||
def __init__(self,database,cl=0,name=""):
|
||||
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")
|
||||
|
||||
|
||||
dic = {
|
||||
"destroy_passed_object" : Utils.destroy_passed_object,
|
||||
"on_ok_clicked" : self.on_ok_clicked
|
||||
@ -115,6 +119,36 @@ class PackageWriter:
|
||||
th.write(data)
|
||||
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):
|
||||
Utils.destroy_passed_object(obj)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -334,7 +334,7 @@ def writeData(database,person):
|
||||
class GedcomWriter:
|
||||
"""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.person = person
|
||||
self.restrict = 1
|
||||
@ -350,7 +350,12 @@ class GedcomWriter:
|
||||
self.pidmap = {}
|
||||
self.sidval = 0
|
||||
self.sidmap = {}
|
||||
self.cl = cl
|
||||
self.name = name
|
||||
|
||||
if self.cl:
|
||||
self.cl_setup()
|
||||
else:
|
||||
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
|
||||
|
||||
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
||||
@ -487,6 +492,41 @@ class GedcomWriter:
|
||||
self.export_data(name)
|
||||
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):
|
||||
try:
|
||||
self.g = open(filename,"w")
|
||||
@ -558,16 +598,18 @@ class GedcomWriter:
|
||||
for key in pkeys:
|
||||
self.write_person(self.db.getPerson(key))
|
||||
index = index + 1
|
||||
if index%100 == 0:
|
||||
if index%100 == 0 and not self.cl:
|
||||
self.pbar.set_fraction(index/nump)
|
||||
while(gtk.events_pending()):
|
||||
gtk.mainiteration()
|
||||
if not self.cl:
|
||||
self.pbar.set_fraction(1.0)
|
||||
|
||||
self.write_families()
|
||||
if self.source_refs:
|
||||
self.write_sources()
|
||||
else:
|
||||
if not self.cl:
|
||||
self.sbar.set_fraction(1.0)
|
||||
|
||||
self.g.write("0 TRLR\n")
|
||||
@ -666,10 +708,11 @@ class GedcomWriter:
|
||||
break
|
||||
|
||||
index = index + 1
|
||||
if index % 100 == 0:
|
||||
if index % 100 == 0 and not self.cl:
|
||||
self.fbar.set_fraction(index/nump)
|
||||
while(gtk.events_pending()):
|
||||
gtk.mainiteration()
|
||||
if not self.cl:
|
||||
self.fbar.set_fraction(1.0)
|
||||
|
||||
def write_sources(self):
|
||||
@ -691,10 +734,11 @@ class GedcomWriter:
|
||||
if source.getNote():
|
||||
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
|
||||
index = index + 1
|
||||
if index % 100 == 0:
|
||||
if index % 100 == 0 and not self.cl:
|
||||
self.sbar.set_fraction(index/nump)
|
||||
while(gtk.events_pending()):
|
||||
gtk.mainiteration()
|
||||
if not self.cl:
|
||||
self.sbar.set_fraction(1.0)
|
||||
|
||||
def write_person(self,person):
|
||||
|
Loading…
Reference in New Issue
Block a user