Command line: check action

svn: r1541
This commit is contained in:
Alex Roitman 2003-05-19 04:54:14 +00:00
parent 86be928072
commit dc0cec92e3
2 changed files with 88 additions and 54 deletions

View File

@ -146,7 +146,7 @@ class Gramps:
const.shortopts,const.longopts)
if leftargs:
print "Unrecognized option: %s" % leftargs[0]
return
os._exit(1)
outfname = ''
action = ''
imports = []
@ -160,7 +160,7 @@ class Gramps:
format = options[opt_ix+1][1]
if format not in [ 'gedcom', 'gramps', 'gramps-pkg' ]:
print "Invalid format: %s" % format
return
os._exit(1)
elif string.upper(fname[-3:]) == "GED":
format = 'gedcom'
elif string.upper(fname[-3:]) == "TGZ":
@ -169,7 +169,7 @@ class Gramps:
format = 'gramps'
else:
print "Unrecognized format for input file %s" % fname
return
os._exit(1)
imports.append((fname,format))
elif o == 'o':
outfname = options[opt_ix][1]
@ -177,7 +177,7 @@ class Gramps:
outformat = options[opt_ix+1][1]
if outformat not in [ 'gedcom', 'gramps', 'gramps-pkg', 'iso' ]:
print "Invalid format: %s" % outformat
return
os._exit(1)
elif string.upper(outfname[-3:]) == "GED":
outformat = 'gedcom'
elif string.upper(outfname[-3:]) == "TGZ":
@ -186,9 +186,12 @@ class Gramps:
outformat = 'gramps'
else:
print "Unrecognized format for output file %s" % outfname
return
os._exit(1)
elif o == 'a':
action = options[opt_ix][1]
if action not in [ 'check', 'summary' ]:
print "Unknown action: %s." % action
os._exit(1)
if not (outfname or action):
self.cl = 0
@ -222,7 +225,7 @@ class Gramps:
self.cl_export(outfname,outformat)
if action:
print "Performing: action %s." % action
print "Performing action: %s." % action
self.cl_action(action)
if self.cl:
@ -924,13 +927,13 @@ class Gramps:
try:
ReadGedcom.importData(self.db,filename)
except:
pass
print "Error importing %s" % filename
elif format == 'gramps':
try:
dbname = os.path.join(filename,const.xmlFile)
ReadXML.importData(self.db,dbname,None)
except:
pass
print "Error importing %s" % filename
elif format == 'gramps-pkg':
# Create tempdir, if it does not exist, then check for writability
tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
@ -939,10 +942,10 @@ class Gramps:
os.mkdir(tmpdir_path,0700)
except:
print "Could not create temporary directory %s" % tmpdir_path
return
os._exit(1)
elif not os.access(tmpdir_path,os.W_OK):
print "Temporary directory %s is not writable" % tmpdir_path
return
os._exit(1)
else: # tempdir exists and writable -- clean it up if not empty
files = os.listdir(tmpdir_path) ;
for fn in files:
@ -955,14 +958,14 @@ class Gramps:
t.close()
except:
print "Error extracting into %s" % tmpdir_path
return
os._exit(1)
dbname = os.path.join(tmpdir_path,const.xmlFile)
try:
ReadXML.importData(self.db,dbname,None)
except:
pass
print "Error importing %s" % filename
# Clean up tempdir after ourselves
files = os.listdir(tmpdir_path)
for fn in files:
@ -970,13 +973,14 @@ class Gramps:
os.rmdir(tmpdir_path)
else:
print "Invalid format: %s" % format
return
os._exit(1)
if not self.cl:
return self.post_load(self.impdir_path)
def cl_export(self,filename,format):
if format == 'gedcom':
print "Command-line export to gedcom is not implemented yet."
os._exit(0)
elif format == 'gramps':
filename = os.path.normpath(os.path.abspath(filename))
dbname = os.path.join(filename,const.xmlFile)
@ -1013,9 +1017,28 @@ class Gramps:
t.close()
elif format == 'iso':
print "Command-line export to iso is not implemented yet."
os._exit(0)
else:
print "Invalid format: %s" % format
os._exit(1)
def cl_action(self,action):
print "Command-line action is not implemented yet."
if action == 'check':
import Check
checker = Check.CheckIntegrity(self.db)
checker.check_for_broken_family_links()
checker.cleanup_missing_photos()
checker.check_parent_relationships()
checker.cleanup_empty_families(0)
errs = checker.build_report(1)
if errs:
checker.report(1)
elif action == 'summary':
print "Command-line summary is not implemented yet."
os._exit(0)
else:
print "Unknown action: %s." % action
os._exit(1)
def on_ok_button2_clicked(self,obj):
filename = obj.get_filename()

View File

@ -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
@ -44,7 +44,9 @@ def runTool(database,active_person,callback):
checker.cleanup_missing_photos()
checker.check_parent_relationships()
checker.cleanup_empty_families(0)
checker.report()
errs = checker.build_report(0)
if errs:
checker.report(0)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
@ -206,7 +208,7 @@ class CheckIntegrity:
family.setFather(mother)
family.setMother(father)
def report(self):
def build_report(self,cl=0):
bad_photos = len(self.bad_photo)
replaced_photos = len(self.replaced_photo)
removed_photos = len(self.removed_photo)
@ -219,16 +221,19 @@ class CheckIntegrity:
errors = blink + efam + photos + rel
if errors == 0:
OkDialog(_("No errors were found"),
_('The database has passed internal checks'))
return
if cl:
print "No errors were found: the database has passed internal checks."
else:
OkDialog(_("No errors were found"),
_('The database has passed internal checks'))
return 0
text = cStringIO.StringIO()
self.text = cStringIO.StringIO()
if blink > 0:
if blink == 1:
text.write(_("1 broken child/family link was fixed\n"))
self.text.write(_("1 broken child/family link was fixed\n"))
else:
text.write(_("%d broken child/family links were found\n") % blink)
self.text.write(_("%d broken child/family links were found\n") % blink)
for c in self.broken_links:
cn = c[0].getPrimaryName().getName()
f = c[1].getFather()
@ -240,14 +245,14 @@ class CheckIntegrity:
pn = f.getPrimaryName().getName()
else:
pn = m.getPrimaryName().getName()
text.write('\t')
text.write('_("%s was removed from the family of %s\n") % (cn,pn)')
self.text.write('\t')
self.text.write('_("%s was removed from the family of %s\n") % (cn,pn)')
if plink > 0:
if plink == 1:
text.write(_("1 broken spouse/family link was fixed\n"))
self.text.write(_("1 broken spouse/family link was fixed\n"))
else:
text.write(_("%d broken spouse/family links were found\n") % plink)
self.text.write(_("%d broken spouse/family links were found\n") % plink)
for c in self.broken_parent_links:
cn = c[0].getPrimaryName().getName()
f = c[1].getFather()
@ -259,48 +264,54 @@ class CheckIntegrity:
pn = f.getPrimaryName().getName()
else:
pn = m.getPrimaryName().getName()
text.write('\t')
text.write(_("%s was restored to the family of %s\n") % (cn,pn))
self.text.write('\t')
self.text.write(_("%s was restored to the family of %s\n") % (cn,pn))
if efam == 1:
text.write(_("1 empty family was found\n"))
self.text.write(_("1 empty family was found\n"))
elif efam > 1:
text.write(_("%d empty families were found\n") % efam)
self.text.write(_("%d empty families were found\n") % efam)
if rel == 1:
text.write(_("1 corrupted family relationship fixed\n"))
self.text.write(_("1 corrupted family relationship fixed\n"))
elif rel > 1:
text.write(_("%d corrupted family relationship fixed\n") % rel)
self.text.write(_("%d corrupted family relationship fixed\n") % rel)
if photos == 1:
text.write(_("1 media object was referenced, but not found\n"))
self.text.write(_("1 media object was referenced, but not found\n"))
elif photos > 1:
text.write(_("%d media objects were referenced, but not found\n") % photos)
self.text.write(_("%d media objects were referenced, but not found\n") % photos)
if bad_photos == 1:
text.write(_("Reference to 1 missing media object was kept\n"))
self.text.write(_("Reference to 1 missing media object was kept\n"))
elif bad_photos > 1:
text.write(_("References to %d media objects were kept\n") % bad_photos)
self.text.write(_("References to %d media objects were kept\n") % bad_photos)
if replaced_photos == 1:
text.write(_("1 missing media object was replaced\n"))
self.text.write(_("1 missing media object was replaced\n"))
elif replaced_photos > 1:
text.write(_("%d missing media objects were replaced\n") % replaced_photos)
self.text.write(_("%d missing media objects were replaced\n") % replaced_photos)
if removed_photos == 1:
text.write(_("1 missing media object was removed\n"))
self.text.write(_("1 missing media object was removed\n"))
elif removed_photos > 1:
text.write(_("%d missing media objects were removed\n") % removed_photos)
self.text.write(_("%d missing media objects were removed\n") % removed_photos)
base = os.path.dirname(__file__)
glade_file = base + os.sep + "summary.glade"
topDialog = gtk.glade.XML(glade_file,"summary")
topDialog.signal_autoconnect({
"destroy_passed_object" : Utils.destroy_passed_object,
})
title = _("Check Integrity")
top = topDialog.get_widget("summary")
textwindow = topDialog.get_widget("textwindow")
return errors
Utils.set_titles(top,topDialog.get_widget("title"),title)
textwindow.get_buffer().set_text(text.getvalue())
text.close()
top.show()
def report(self,cl=0):
if cl:
print self.text.getvalue()
else:
base = os.path.dirname(__file__)
glade_file = base + os.sep + "summary.glade"
topDialog = gtk.glade.XML(glade_file,"summary")
topDialog.signal_autoconnect({
"destroy_passed_object" : Utils.destroy_passed_object,
})
title = _("Check Integrity")
top = topDialog.get_widget("summary")
textwindow = topDialog.get_widget("textwindow")
Utils.set_titles(top,topDialog.get_widget("title"),title)
textwindow.get_buffer().set_text(self.text.getvalue())
self.text.close()
top.show()
#------------------------------------------------------------------------
#