Finishing command line options
svn: r1564
This commit is contained in:
parent
8b2e282bc0
commit
e727f0075b
@ -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
|
||||||
@ -18,10 +18,6 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# Modified by Alex Roitman to handle media object files.
|
|
||||||
#
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Standard Python Modules
|
# Standard Python Modules
|
||||||
@ -61,7 +57,7 @@ except:
|
|||||||
# Must takes care of renaming media files according to their new IDs.
|
# Must takes care of renaming media files according to their new IDs.
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def importData(database, filename, callback):
|
def importData(database, filename, callback,cl=0):
|
||||||
|
|
||||||
filename = os.path.normpath(filename)
|
filename = os.path.normpath(filename)
|
||||||
basefile = os.path.dirname(filename)
|
basefile = os.path.dirname(filename)
|
||||||
@ -90,29 +86,55 @@ def importData(database, filename, callback):
|
|||||||
else:
|
else:
|
||||||
xml_file = open(filename,"r")
|
xml_file = open(filename,"r")
|
||||||
except IOError,msg:
|
except IOError,msg:
|
||||||
ErrorDialog(_("%s could not be opened") % filename,str(msg))
|
if cl:
|
||||||
return 0
|
print "Error: %s could not be opened Exiting." % filename
|
||||||
|
print msg
|
||||||
|
os._exit(1)
|
||||||
|
else:
|
||||||
|
ErrorDialog(_("%s could not be opened") % filename,str(msg))
|
||||||
|
return 0
|
||||||
except:
|
except:
|
||||||
ErrorDialog(_("%s could not be opened") % filename)
|
if cl:
|
||||||
return 0
|
print "Error: %s could not be opened. Exiting." % filename
|
||||||
|
os._exit(1)
|
||||||
|
else:
|
||||||
|
ErrorDialog(_("%s could not be opened") % filename)
|
||||||
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
parser.parse(xml_file)
|
parser.parse(xml_file)
|
||||||
except IOError,msg:
|
except IOError,msg:
|
||||||
ErrorDialog(_("Error reading %s") % filename,str(msg))
|
if cl:
|
||||||
import traceback
|
print "Error reading %s" % filename
|
||||||
traceback.print_exc()
|
print msg
|
||||||
return 0
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
os._exit(1)
|
||||||
|
else:
|
||||||
|
ErrorDialog(_("Error reading %s") % filename,str(msg))
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return 0
|
||||||
except ExpatError, msg:
|
except ExpatError, msg:
|
||||||
ErrorDialog(_("Error reading %s") % filename,
|
if cl:
|
||||||
_("The file is probably either corrupt or not a valid GRAMPS database."))
|
print "Error reading %s" % filename
|
||||||
return 0
|
print "The file is probably either corrupt or not a valid GRAMPS database."
|
||||||
|
os._exit(1)
|
||||||
|
else:
|
||||||
|
ErrorDialog(_("Error reading %s") % filename,
|
||||||
|
_("The file is probably either corrupt or not a valid GRAMPS database."))
|
||||||
|
return 0
|
||||||
except ValueError, msg:
|
except ValueError, msg:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
import DisplayTrace
|
if cl:
|
||||||
DisplayTrace.DisplayTrace()
|
import traceback
|
||||||
return 0
|
traceback.print_exc()
|
||||||
|
os._exit(1)
|
||||||
|
else:
|
||||||
|
import DisplayTrace
|
||||||
|
DisplayTrace.DisplayTrace()
|
||||||
|
return 0
|
||||||
|
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
|
|
||||||
@ -190,14 +212,18 @@ def importData(database, filename, callback):
|
|||||||
try:
|
try:
|
||||||
shutil.copy2(oldfile,newfile)
|
shutil.copy2(oldfile,newfile)
|
||||||
except:
|
except:
|
||||||
# File is lost => ask what to do
|
if cl:
|
||||||
MissingMediaDialog(_("Media object could not be found"),
|
print "Warning: media file %s was not found," \
|
||||||
_("%(file_name)s is referenced in the database, but no longer exists. "
|
% os.path.basename(oldfile), "so it was ignored."
|
||||||
"The file may have been deleted or moved to a different location. "
|
else:
|
||||||
"You may choose to either remove the reference from the database, "
|
# File is lost => ask what to do
|
||||||
"keep the reference to the missing file, or select a new file."
|
MissingMediaDialog(_("Media object could not be found"),
|
||||||
) % { 'file_name' : oldfile },
|
_("%(file_name)s is referenced in the database, but no longer exists. "
|
||||||
remove_clicked, leave_clicked, select_clicked)
|
"The file may have been deleted or moved to a different location. "
|
||||||
|
"You may choose to either remove the reference from the database, "
|
||||||
|
"keep the reference to the missing file, or select a new file."
|
||||||
|
) % { 'file_name' : oldfile },
|
||||||
|
remove_clicked, leave_clicked, select_clicked)
|
||||||
|
|
||||||
del parser
|
del parser
|
||||||
return 1
|
return 1
|
||||||
|
@ -116,6 +116,7 @@ class Gramps:
|
|||||||
self.bookmarks = None
|
self.bookmarks = None
|
||||||
self.c_details = 6
|
self.c_details = 6
|
||||||
self.id2col = {}
|
self.id2col = {}
|
||||||
|
self.cl = 0
|
||||||
|
|
||||||
gtk.rc_parse(const.gtkrcFile)
|
gtk.rc_parse(const.gtkrcFile)
|
||||||
|
|
||||||
@ -140,7 +141,6 @@ class Gramps:
|
|||||||
self.relationship = Plugins.relationship_function()
|
self.relationship = Plugins.relationship_function()
|
||||||
self.init_interface()
|
self.init_interface()
|
||||||
|
|
||||||
self.cl = 1
|
|
||||||
if args:
|
if args:
|
||||||
try:
|
try:
|
||||||
options,leftargs = getopt.getopt(args,
|
options,leftargs = getopt.getopt(args,
|
||||||
@ -153,8 +153,8 @@ class Gramps:
|
|||||||
if leftargs:
|
if leftargs:
|
||||||
print "Unrecognized option: %s" % leftargs[0]
|
print "Unrecognized option: %s" % leftargs[0]
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
outfname = ''
|
exports = []
|
||||||
action = ''
|
actions = []
|
||||||
imports = []
|
imports = []
|
||||||
for opt_ix in range(len(options)):
|
for opt_ix in range(len(options)):
|
||||||
o = options[opt_ix][0][1]
|
o = options[opt_ix][0][1]
|
||||||
@ -199,14 +199,15 @@ class Gramps:
|
|||||||
else:
|
else:
|
||||||
print "Unrecognized format for output file %s" % outfname
|
print "Unrecognized format for output file %s" % outfname
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
exports.append((outfname,outformat))
|
||||||
elif o == 'a':
|
elif o == 'a':
|
||||||
action = options[opt_ix][1]
|
action = options[opt_ix][1]
|
||||||
if action not in [ 'check', 'summary' ]:
|
if action not in [ 'check', 'summary' ]:
|
||||||
print "Unknown action: %s." % action
|
print "Unknown action: %s." % action
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
actions.append(action)
|
||||||
|
|
||||||
if not (outfname or action):
|
self.cl = bool(exports or actions)
|
||||||
self.cl = 0
|
|
||||||
|
|
||||||
if imports:
|
if imports:
|
||||||
# Create dir for imported database(s)
|
# Create dir for imported database(s)
|
||||||
@ -215,16 +216,18 @@ class Gramps:
|
|||||||
try:
|
try:
|
||||||
os.mkdir(self.impdir_path,0700)
|
os.mkdir(self.impdir_path,0700)
|
||||||
except:
|
except:
|
||||||
print "Could not create import directory %s" % impdir_path
|
print "Could not create import directory %s. Exiting." \
|
||||||
return
|
% impdir_path
|
||||||
|
os._exit(1)
|
||||||
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. Exiting." \
|
||||||
return
|
% self.impdir_path
|
||||||
|
os._exit(1)
|
||||||
# and clean it up before use
|
# and clean it up before use
|
||||||
files = os.listdir(self.impdir_path) ;
|
files = os.listdir(self.impdir_path) ;
|
||||||
for fn in files:
|
for fn in files:
|
||||||
if os.path.isfile(fn):
|
if os.path.isfile(os.path.join(self.impdir_path,fn)):
|
||||||
os.remove( os.path.join(self.impdir_path,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)
|
||||||
@ -232,15 +235,21 @@ class Gramps:
|
|||||||
print "Importing: file %s, format %s." % (imp[0],imp[1])
|
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:
|
for expt in exports:
|
||||||
print "Exporting: file %s, format %s." % (outfname,outformat)
|
print "Exporting: file %s, format %s." % (expt[0],expt[1])
|
||||||
self.cl_export(outfname,outformat)
|
self.cl_export(expt[0],expt[1])
|
||||||
|
|
||||||
if action:
|
for action in actions:
|
||||||
print "Performing action: %s." % action
|
print "Performing action: %s." % action
|
||||||
self.cl_action(action)
|
self.cl_action(action)
|
||||||
|
|
||||||
if self.cl:
|
if self.cl:
|
||||||
|
print "Cleaning up."
|
||||||
|
# clean import dir up after use
|
||||||
|
files = os.listdir(self.impdir_path) ;
|
||||||
|
for fn in files:
|
||||||
|
if os.path.isfile(os.path.join(self.impdir_path,fn)):
|
||||||
|
os.remove(os.path.join(self.impdir_path,fn))
|
||||||
print "Exiting."
|
print "Exiting."
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
@ -960,7 +969,7 @@ class Gramps:
|
|||||||
elif format == 'gramps':
|
elif format == 'gramps':
|
||||||
try:
|
try:
|
||||||
dbname = os.path.join(filename,const.xmlFile)
|
dbname = os.path.join(filename,const.xmlFile)
|
||||||
ReadXML.importData(self.db,dbname,None)
|
ReadXML.importData(self.db,dbname,None,self.cl)
|
||||||
except:
|
except:
|
||||||
print "Error importing %s" % filename
|
print "Error importing %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -1051,6 +1060,9 @@ class Gramps:
|
|||||||
g = open(oldfile,"rb")
|
g = open(oldfile,"rb")
|
||||||
t.add_file(base,mtime,g)
|
t.add_file(base,mtime,g)
|
||||||
g.close()
|
g.close()
|
||||||
|
else:
|
||||||
|
print "Warning: media file %s was not found," % base,\
|
||||||
|
"so it was ignored."
|
||||||
except:
|
except:
|
||||||
print "Error exporting media files to %s" % filename
|
print "Error exporting media files to %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -1074,7 +1086,7 @@ class Gramps:
|
|||||||
print "Error exporting %s" % filename
|
print "Error exporting %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
else:
|
else:
|
||||||
print "Invalid format: %s" % format
|
print "Invalid format: %s" % format
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
def cl_action(self,action):
|
def cl_action(self,action):
|
||||||
@ -1082,15 +1094,16 @@ class Gramps:
|
|||||||
import Check
|
import Check
|
||||||
checker = Check.CheckIntegrity(self.db)
|
checker = Check.CheckIntegrity(self.db)
|
||||||
checker.check_for_broken_family_links()
|
checker.check_for_broken_family_links()
|
||||||
checker.cleanup_missing_photos()
|
checker.cleanup_missing_photos(1)
|
||||||
checker.check_parent_relationships()
|
checker.check_parent_relationships()
|
||||||
checker.cleanup_empty_families(0)
|
checker.cleanup_empty_families(0)
|
||||||
errs = checker.build_report(1)
|
errs = checker.build_report(1)
|
||||||
if errs:
|
if errs:
|
||||||
checker.report(1)
|
checker.report(1)
|
||||||
elif action == 'summary':
|
elif action == 'summary':
|
||||||
print "Command-line summary is not implemented yet."
|
import Summary
|
||||||
os._exit(0)
|
text = Summary.build_report(self.db,None)
|
||||||
|
print text
|
||||||
else:
|
else:
|
||||||
print "Unknown action: %s." % action
|
print "Unknown action: %s." % action
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -1175,14 +1188,18 @@ class Gramps:
|
|||||||
if os.path.isfile(oldfile):
|
if os.path.isfile(oldfile):
|
||||||
RelImage.import_media_object(oldfile,filename,base)
|
RelImage.import_media_object(oldfile,filename,base)
|
||||||
else:
|
else:
|
||||||
# File is lost => ask what to do
|
if self.cl:
|
||||||
MissingMediaDialog(_("Media object could not be found"),
|
print "Warning: media file %s was not found," \
|
||||||
_("%(file_name)s is referenced in the database, but no longer exists. "
|
% os.path.basename(oldfile), "so it was ignored."
|
||||||
"The file may have been deleted or moved to a different location. "
|
else:
|
||||||
"You may choose to either remove the reference from the database, "
|
# File is lost => ask what to do
|
||||||
"keep the reference to the missing file, or select a new file."
|
MissingMediaDialog(_("Media object could not be found"),
|
||||||
) % { 'file_name' : oldfile },
|
_("%(file_name)s is referenced in the database, but no longer exists. "
|
||||||
remove_clicked, leave_clicked, select_clicked)
|
"The file may have been deleted or moved to a different location. "
|
||||||
|
"You may choose to either remove the reference from the database, "
|
||||||
|
"keep the reference to the missing file, or select a new file."
|
||||||
|
) % { 'file_name' : oldfile },
|
||||||
|
remove_clicked, leave_clicked, select_clicked)
|
||||||
|
|
||||||
def save_file(self,filename,comment):
|
def save_file(self,filename,comment):
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ def runTool(database,active_person,callback):
|
|||||||
try:
|
try:
|
||||||
checker = CheckIntegrity(database)
|
checker = CheckIntegrity(database)
|
||||||
checker.check_for_broken_family_links()
|
checker.check_for_broken_family_links()
|
||||||
checker.cleanup_missing_photos()
|
checker.cleanup_missing_photos(0)
|
||||||
checker.check_parent_relationships()
|
checker.check_parent_relationships()
|
||||||
checker.cleanup_empty_families(0)
|
checker.cleanup_empty_families(0)
|
||||||
errs = checker.build_report(0)
|
errs = checker.build_report(0)
|
||||||
@ -94,7 +94,7 @@ class CheckIntegrity:
|
|||||||
Utils.modified()
|
Utils.modified()
|
||||||
self.broken_links.append((child,family))
|
self.broken_links.append((child,family))
|
||||||
|
|
||||||
def cleanup_missing_photos(self):
|
def cleanup_missing_photos(self,cl=0):
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def remove_clicked():
|
def remove_clicked():
|
||||||
# File is lost => remove all references and the object itself
|
# File is lost => remove all references and the object itself
|
||||||
@ -160,13 +160,18 @@ class CheckIntegrity:
|
|||||||
for ObjectId in ObjectMap.keys():
|
for ObjectId in ObjectMap.keys():
|
||||||
photo_name = ObjectMap[ObjectId].getPath()
|
photo_name = ObjectMap[ObjectId].getPath()
|
||||||
if not os.path.isfile(photo_name):
|
if not os.path.isfile(photo_name):
|
||||||
MissingMediaDialog(_("Media object could not be found"),
|
if cl:
|
||||||
_("%(file_name)s is referenced in the database, but no longer exists. "
|
print "Warning: media file %s was not found." \
|
||||||
"The file may have been deleted or moved to a different location. "
|
% os.path.basename(photo_name)
|
||||||
"You may choose to either remove the reference from the database, "
|
self.bad_photo.append(ObjectMap[ObjectId])
|
||||||
"keep the reference to the missing file, or select a new file."
|
else:
|
||||||
) % { 'file_name' : photo_name },
|
MissingMediaDialog(_("Media object could not be found"),
|
||||||
remove_clicked, leave_clicked, select_clicked)
|
_("%(file_name)s is referenced in the database, but no longer exists. "
|
||||||
|
"The file may have been deleted or moved to a different location. "
|
||||||
|
"You may choose to either remove the reference from the database, "
|
||||||
|
"keep the reference to the missing file, or select a new file."
|
||||||
|
) % { 'file_name' : photo_name },
|
||||||
|
remove_clicked, leave_clicked, select_clicked)
|
||||||
|
|
||||||
def cleanup_empty_families(self,automatic):
|
def cleanup_empty_families(self,automatic):
|
||||||
for key in self.db.getFamilyMap().keys():
|
for key in self.db.getFamilyMap().keys():
|
||||||
|
@ -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
|
||||||
@ -48,22 +48,10 @@ from gnome.ui import *
|
|||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
# Build the text of the report
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
def report(database,person):
|
def build_report(database,person):
|
||||||
|
|
||||||
base = os.path.dirname(__file__)
|
|
||||||
glade_file = "%s/summary.glade" % base
|
|
||||||
|
|
||||||
topDialog = gtk.glade.XML(glade_file,"summary")
|
|
||||||
topDialog.signal_autoconnect({
|
|
||||||
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
||||||
})
|
|
||||||
|
|
||||||
Utils.set_titles(topDialog.get_widget('summary'),
|
|
||||||
topDialog.get_widget('title'),
|
|
||||||
_('Database summary'))
|
|
||||||
|
|
||||||
personList = database.getPersonMap().values()
|
personList = database.getPersonMap().values()
|
||||||
familyList = database.getFamilyMap().values()
|
familyList = database.getFamilyMap().values()
|
||||||
@ -132,6 +120,30 @@ def report(database,person):
|
|||||||
for p in notfound:
|
for p in notfound:
|
||||||
text = text + "%s\n" % p
|
text = text + "%s\n" % p
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Output report in a window
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
def report(database,person):
|
||||||
|
|
||||||
|
text = build_report(database,person)
|
||||||
|
|
||||||
|
base = os.path.dirname(__file__)
|
||||||
|
glade_file = "%s/summary.glade" % base
|
||||||
|
|
||||||
|
topDialog = gtk.glade.XML(glade_file,"summary")
|
||||||
|
topDialog.signal_autoconnect({
|
||||||
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
||||||
|
})
|
||||||
|
|
||||||
|
Utils.set_titles(topDialog.get_widget('summary'),
|
||||||
|
topDialog.get_widget('title'),
|
||||||
|
_('Database summary'))
|
||||||
|
|
||||||
|
|
||||||
top = topDialog.get_widget("summary")
|
top = topDialog.get_widget("summary")
|
||||||
textwindow = topDialog.get_widget("textwindow")
|
textwindow = topDialog.get_widget("textwindow")
|
||||||
textwindow.get_buffer().set_text(text)
|
textwindow.get_buffer().set_text(text)
|
||||||
|
@ -143,6 +143,10 @@ class PackageWriter:
|
|||||||
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
||||||
if obj.getMimeType()[0:5] == "image":
|
if obj.getMimeType()[0:5] == "image":
|
||||||
self.make_thumbnail(base,root,obj.getPath())
|
self.make_thumbnail(base,root,obj.getPath())
|
||||||
|
else:
|
||||||
|
print "Warning: media file %s was not found," % root,\
|
||||||
|
"so it was ignored."
|
||||||
|
|
||||||
# Write XML now
|
# Write XML now
|
||||||
g = gnome.vfs.create('burn:///%s/data.gramps' % base,gnome.vfs.OPEN_WRITE )
|
g = gnome.vfs.create('burn:///%s/data.gramps' % base,gnome.vfs.OPEN_WRITE )
|
||||||
gfile = WriteXML.XmlWriter(self.db,None,1)
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||||
|
Loading…
Reference in New Issue
Block a user