Finishing command line options

svn: r1564
This commit is contained in:
Alex Roitman 2003-05-21 18:06:41 +00:00
parent 8b2e282bc0
commit e727f0075b
5 changed files with 144 additions and 80 deletions

View File

@ -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,26 +86,52 @@ def importData(database, filename, callback):
else: else:
xml_file = open(filename,"r") xml_file = open(filename,"r")
except IOError,msg: except IOError,msg:
if cl:
print "Error: %s could not be opened Exiting." % filename
print msg
os._exit(1)
else:
ErrorDialog(_("%s could not be opened") % filename,str(msg)) ErrorDialog(_("%s could not be opened") % filename,str(msg))
return 0 return 0
except: except:
if cl:
print "Error: %s could not be opened. Exiting." % filename
os._exit(1)
else:
ErrorDialog(_("%s could not be opened") % filename) ErrorDialog(_("%s could not be opened") % filename)
return 0 return 0
try: try:
parser.parse(xml_file) parser.parse(xml_file)
except IOError,msg: except IOError,msg:
if cl:
print "Error reading %s" % filename
print msg
import traceback
traceback.print_exc()
os._exit(1)
else:
ErrorDialog(_("Error reading %s") % filename,str(msg)) ErrorDialog(_("Error reading %s") % filename,str(msg))
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return 0 return 0
except ExpatError, msg: except ExpatError, msg:
if cl:
print "Error reading %s" % filename
print "The file is probably either corrupt or not a valid GRAMPS database."
os._exit(1)
else:
ErrorDialog(_("Error reading %s") % filename, ErrorDialog(_("Error reading %s") % filename,
_("The file is probably either corrupt or not a valid GRAMPS database.")) _("The file is probably either corrupt or not a valid GRAMPS database."))
return 0 return 0
except ValueError, msg: except ValueError, msg:
pass pass
except: except:
if cl:
import traceback
traceback.print_exc()
os._exit(1)
else:
import DisplayTrace import DisplayTrace
DisplayTrace.DisplayTrace() DisplayTrace.DisplayTrace()
return 0 return 0
@ -190,6 +212,10 @@ def importData(database, filename, callback):
try: try:
shutil.copy2(oldfile,newfile) shutil.copy2(oldfile,newfile)
except: except:
if cl:
print "Warning: media file %s was not found," \
% os.path.basename(oldfile), "so it was ignored."
else:
# File is lost => ask what to do # File is lost => ask what to do
MissingMediaDialog(_("Media object could not be found"), MissingMediaDialog(_("Media object could not be found"),
_("%(file_name)s is referenced in the database, but no longer exists. " _("%(file_name)s is referenced in the database, but no longer exists. "

View File

@ -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,15 +216,17 @@ 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)
@ -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)
@ -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)
@ -1174,6 +1187,10 @@ class Gramps:
ObjectMap[ObjectId].setPath(newfile) ObjectMap[ObjectId].setPath(newfile)
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:
if self.cl:
print "Warning: media file %s was not found," \
% os.path.basename(oldfile), "so it was ignored."
else: else:
# File is lost => ask what to do # File is lost => ask what to do
MissingMediaDialog(_("Media object could not be found"), MissingMediaDialog(_("Media object could not be found"),

View File

@ -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,6 +160,11 @@ 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):
if cl:
print "Warning: media file %s was not found." \
% os.path.basename(photo_name)
self.bad_photo.append(ObjectMap[ObjectId])
else:
MissingMediaDialog(_("Media object could not be found"), MissingMediaDialog(_("Media object could not be found"),
_("%(file_name)s is referenced in the database, but no longer exists. " _("%(file_name)s is referenced in the database, but no longer exists. "
"The file may have been deleted or moved to a different location. " "The file may have been deleted or moved to a different location. "

View File

@ -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)

View File

@ -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)