Command line: import cleanup and some exports
svn: r1540
This commit is contained in:
parent
19cfd008ce
commit
86be928072
@ -140,7 +140,7 @@ class Gramps:
|
|||||||
self.relationship = Plugins.relationship_function()
|
self.relationship = Plugins.relationship_function()
|
||||||
self.init_interface()
|
self.init_interface()
|
||||||
|
|
||||||
self.cl = 0
|
self.cl = 1
|
||||||
if args:
|
if args:
|
||||||
options,leftargs = getopt.getopt(args,
|
options,leftargs = getopt.getopt(args,
|
||||||
const.shortopts,const.longopts)
|
const.shortopts,const.longopts)
|
||||||
@ -190,6 +190,9 @@ class Gramps:
|
|||||||
elif o == 'a':
|
elif o == 'a':
|
||||||
action = options[opt_ix][1]
|
action = options[opt_ix][1]
|
||||||
|
|
||||||
|
if not (outfname or action):
|
||||||
|
self.cl = 0
|
||||||
|
|
||||||
if imports:
|
if imports:
|
||||||
# Create dir for imported database(s)
|
# Create dir for imported database(s)
|
||||||
self.impdir_path = os.path.expanduser("~/.gramps/import" )
|
self.impdir_path = os.path.expanduser("~/.gramps/import" )
|
||||||
@ -202,21 +205,28 @@ class Gramps:
|
|||||||
elif not os.access(self.impdir_path,os.W_OK):
|
elif not os.access(self.impdir_path,os.W_OK):
|
||||||
print "Import directory %s is not writable" % self.impdir_path
|
print "Import directory %s is not writable" % self.impdir_path
|
||||||
return
|
return
|
||||||
|
# and clean it up before use
|
||||||
|
files = os.listdir(self.impdir_path) ;
|
||||||
|
for fn in files:
|
||||||
|
if os.path.isfile(fn):
|
||||||
|
os.remove( os.path.join(self.impdir_path,fn) )
|
||||||
|
|
||||||
self.clear_database(0)
|
self.clear_database(0)
|
||||||
self.db.setSavePath(self.impdir_path)
|
self.db.setSavePath(self.impdir_path)
|
||||||
for imp in imports:
|
for imp in imports:
|
||||||
|
print "Importing: file %s, format %s." % (imp[0],imp[1])
|
||||||
self.cl_import(imp[0],imp[1])
|
self.cl_import(imp[0],imp[1])
|
||||||
|
|
||||||
if outfname:
|
if outfname:
|
||||||
|
print "Exporting: file %s, format %s." % (outfname,outformat)
|
||||||
self.cl_export(outfname,outformat)
|
self.cl_export(outfname,outformat)
|
||||||
self.cl = 1
|
|
||||||
|
|
||||||
if action:
|
if action:
|
||||||
|
print "Performing: action %s." % action
|
||||||
self.cl_action(action)
|
self.cl_action(action)
|
||||||
self.cl = 1
|
|
||||||
|
|
||||||
if self.cl:
|
if self.cl:
|
||||||
|
print "Exiting."
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
||||||
@ -731,6 +741,7 @@ class Gramps:
|
|||||||
self.source_view.change_db(self.db)
|
self.source_view.change_db(self.db)
|
||||||
self.media_view.change_db(self.db)
|
self.media_view.change_db(self.db)
|
||||||
|
|
||||||
|
if not self.cl:
|
||||||
self.topWindow.set_title("GRAMPS")
|
self.topWindow.set_title("GRAMPS")
|
||||||
self.active_person = None
|
self.active_person = None
|
||||||
self.id2col = {}
|
self.id2col = {}
|
||||||
@ -956,20 +967,55 @@ class Gramps:
|
|||||||
files = os.listdir(tmpdir_path)
|
files = os.listdir(tmpdir_path)
|
||||||
for fn in files:
|
for fn in files:
|
||||||
os.remove(os.path.join(tmpdir_path,fn))
|
os.remove(os.path.join(tmpdir_path,fn))
|
||||||
|
|
||||||
os.rmdir(tmpdir_path)
|
os.rmdir(tmpdir_path)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Invalid format: %s" % format
|
print "Invalid format: %s" % format
|
||||||
return
|
return
|
||||||
|
if not self.cl:
|
||||||
return self.post_load(self.impdir_path)
|
return self.post_load(self.impdir_path)
|
||||||
|
|
||||||
def cl_export(self,filename,format):
|
def cl_export(self,filename,format):
|
||||||
pass
|
if format == 'gedcom':
|
||||||
|
print "Command-line export to gedcom is not implemented yet."
|
||||||
|
elif format == 'gramps':
|
||||||
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
|
dbname = os.path.join(filename,const.xmlFile)
|
||||||
|
if filename:
|
||||||
|
self.save_media(filename)
|
||||||
|
self.db.save(dbname,None)
|
||||||
|
elif format == 'gramps-pkg':
|
||||||
|
import TarFile
|
||||||
|
import time
|
||||||
|
import WriteXML
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
t = TarFile.TarFile(filename)
|
||||||
|
mtime = time.time()
|
||||||
|
|
||||||
|
# Write media files first, since the database may be modified
|
||||||
|
# during the process (i.e. when removing object)
|
||||||
|
ObjectMap = self.db.getObjectMap()
|
||||||
|
for ObjectId in ObjectMap.keys():
|
||||||
|
oldfile = ObjectMap[ObjectId].getPath()
|
||||||
|
base = os.path.basename(oldfile)
|
||||||
|
if os.path.isfile(oldfile):
|
||||||
|
g = open(oldfile,"rb")
|
||||||
|
t.add_file(base,mtime,g)
|
||||||
|
g.close()
|
||||||
|
|
||||||
|
# Write XML now
|
||||||
|
g = StringIO()
|
||||||
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||||
|
gfile.write_handle(g)
|
||||||
|
mtime = time.time()
|
||||||
|
t.add_file("data.gramps",mtime,g)
|
||||||
|
g.close()
|
||||||
|
t.close()
|
||||||
|
elif format == 'iso':
|
||||||
|
print "Command-line export to iso is not implemented yet."
|
||||||
|
|
||||||
def cl_action(self,action):
|
def cl_action(self,action):
|
||||||
pass
|
print "Command-line action is not implemented yet."
|
||||||
|
|
||||||
def on_ok_button2_clicked(self,obj):
|
def on_ok_button2_clicked(self,obj):
|
||||||
filename = obj.get_filename()
|
filename = obj.get_filename()
|
||||||
@ -1017,12 +1063,10 @@ class Gramps:
|
|||||||
p.setPhotoList(nl)
|
p.setPhotoList(nl)
|
||||||
self.db.removeObject(ObjectId)
|
self.db.removeObject(ObjectId)
|
||||||
|
|
||||||
|
|
||||||
def leave_clicked():
|
def leave_clicked():
|
||||||
# File is lost => do nothing, leave as is
|
# File is lost => do nothing, leave as is
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def select_clicked():
|
def select_clicked():
|
||||||
# File is lost => select a file to replace the lost one
|
# File is lost => select a file to replace the lost one
|
||||||
def fs_close_window(obj):
|
def fs_close_window(obj):
|
||||||
|
Loading…
Reference in New Issue
Block a user