Command line: check action
svn: r1541
This commit is contained in:
parent
57d17bf163
commit
92b6a832ce
@ -146,7 +146,7 @@ class Gramps:
|
|||||||
const.shortopts,const.longopts)
|
const.shortopts,const.longopts)
|
||||||
if leftargs:
|
if leftargs:
|
||||||
print "Unrecognized option: %s" % leftargs[0]
|
print "Unrecognized option: %s" % leftargs[0]
|
||||||
return
|
os._exit(1)
|
||||||
outfname = ''
|
outfname = ''
|
||||||
action = ''
|
action = ''
|
||||||
imports = []
|
imports = []
|
||||||
@ -160,7 +160,7 @@ class Gramps:
|
|||||||
format = options[opt_ix+1][1]
|
format = options[opt_ix+1][1]
|
||||||
if format not in [ 'gedcom', 'gramps', 'gramps-pkg' ]:
|
if format not in [ 'gedcom', 'gramps', 'gramps-pkg' ]:
|
||||||
print "Invalid format: %s" % format
|
print "Invalid format: %s" % format
|
||||||
return
|
os._exit(1)
|
||||||
elif string.upper(fname[-3:]) == "GED":
|
elif string.upper(fname[-3:]) == "GED":
|
||||||
format = 'gedcom'
|
format = 'gedcom'
|
||||||
elif string.upper(fname[-3:]) == "TGZ":
|
elif string.upper(fname[-3:]) == "TGZ":
|
||||||
@ -169,7 +169,7 @@ class Gramps:
|
|||||||
format = 'gramps'
|
format = 'gramps'
|
||||||
else:
|
else:
|
||||||
print "Unrecognized format for input file %s" % fname
|
print "Unrecognized format for input file %s" % fname
|
||||||
return
|
os._exit(1)
|
||||||
imports.append((fname,format))
|
imports.append((fname,format))
|
||||||
elif o == 'o':
|
elif o == 'o':
|
||||||
outfname = options[opt_ix][1]
|
outfname = options[opt_ix][1]
|
||||||
@ -177,7 +177,7 @@ class Gramps:
|
|||||||
outformat = options[opt_ix+1][1]
|
outformat = options[opt_ix+1][1]
|
||||||
if outformat not in [ 'gedcom', 'gramps', 'gramps-pkg', 'iso' ]:
|
if outformat not in [ 'gedcom', 'gramps', 'gramps-pkg', 'iso' ]:
|
||||||
print "Invalid format: %s" % outformat
|
print "Invalid format: %s" % outformat
|
||||||
return
|
os._exit(1)
|
||||||
elif string.upper(outfname[-3:]) == "GED":
|
elif string.upper(outfname[-3:]) == "GED":
|
||||||
outformat = 'gedcom'
|
outformat = 'gedcom'
|
||||||
elif string.upper(outfname[-3:]) == "TGZ":
|
elif string.upper(outfname[-3:]) == "TGZ":
|
||||||
@ -186,9 +186,12 @@ class Gramps:
|
|||||||
outformat = 'gramps'
|
outformat = 'gramps'
|
||||||
else:
|
else:
|
||||||
print "Unrecognized format for output file %s" % outfname
|
print "Unrecognized format for output file %s" % outfname
|
||||||
return
|
os._exit(1)
|
||||||
elif o == 'a':
|
elif o == 'a':
|
||||||
action = options[opt_ix][1]
|
action = options[opt_ix][1]
|
||||||
|
if action not in [ 'check', 'summary' ]:
|
||||||
|
print "Unknown action: %s." % action
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
if not (outfname or action):
|
if not (outfname or action):
|
||||||
self.cl = 0
|
self.cl = 0
|
||||||
@ -222,7 +225,7 @@ class Gramps:
|
|||||||
self.cl_export(outfname,outformat)
|
self.cl_export(outfname,outformat)
|
||||||
|
|
||||||
if action:
|
if action:
|
||||||
print "Performing: action %s." % action
|
print "Performing action: %s." % action
|
||||||
self.cl_action(action)
|
self.cl_action(action)
|
||||||
|
|
||||||
if self.cl:
|
if self.cl:
|
||||||
@ -924,13 +927,13 @@ class Gramps:
|
|||||||
try:
|
try:
|
||||||
ReadGedcom.importData(self.db,filename)
|
ReadGedcom.importData(self.db,filename)
|
||||||
except:
|
except:
|
||||||
pass
|
print "Error importing %s" % filename
|
||||||
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)
|
||||||
except:
|
except:
|
||||||
pass
|
print "Error importing %s" % filename
|
||||||
elif format == 'gramps-pkg':
|
elif format == 'gramps-pkg':
|
||||||
# Create tempdir, if it does not exist, then check for writability
|
# Create tempdir, if it does not exist, then check for writability
|
||||||
tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
|
tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
|
||||||
@ -939,10 +942,10 @@ class Gramps:
|
|||||||
os.mkdir(tmpdir_path,0700)
|
os.mkdir(tmpdir_path,0700)
|
||||||
except:
|
except:
|
||||||
print "Could not create temporary directory %s" % tmpdir_path
|
print "Could not create temporary directory %s" % tmpdir_path
|
||||||
return
|
os._exit(1)
|
||||||
elif not os.access(tmpdir_path,os.W_OK):
|
elif not os.access(tmpdir_path,os.W_OK):
|
||||||
print "Temporary directory %s is not writable" % tmpdir_path
|
print "Temporary directory %s is not writable" % tmpdir_path
|
||||||
return
|
os._exit(1)
|
||||||
else: # tempdir exists and writable -- clean it up if not empty
|
else: # tempdir exists and writable -- clean it up if not empty
|
||||||
files = os.listdir(tmpdir_path) ;
|
files = os.listdir(tmpdir_path) ;
|
||||||
for fn in files:
|
for fn in files:
|
||||||
@ -955,14 +958,14 @@ class Gramps:
|
|||||||
t.close()
|
t.close()
|
||||||
except:
|
except:
|
||||||
print "Error extracting into %s" % tmpdir_path
|
print "Error extracting into %s" % tmpdir_path
|
||||||
return
|
os._exit(1)
|
||||||
|
|
||||||
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ReadXML.importData(self.db,dbname,None)
|
ReadXML.importData(self.db,dbname,None)
|
||||||
except:
|
except:
|
||||||
pass
|
print "Error importing %s" % filename
|
||||||
# Clean up tempdir after ourselves
|
# Clean up tempdir after ourselves
|
||||||
files = os.listdir(tmpdir_path)
|
files = os.listdir(tmpdir_path)
|
||||||
for fn in files:
|
for fn in files:
|
||||||
@ -970,13 +973,14 @@ class Gramps:
|
|||||||
os.rmdir(tmpdir_path)
|
os.rmdir(tmpdir_path)
|
||||||
else:
|
else:
|
||||||
print "Invalid format: %s" % format
|
print "Invalid format: %s" % format
|
||||||
return
|
os._exit(1)
|
||||||
if not self.cl:
|
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):
|
||||||
if format == 'gedcom':
|
if format == 'gedcom':
|
||||||
print "Command-line export to gedcom is not implemented yet."
|
print "Command-line export to gedcom is not implemented yet."
|
||||||
|
os._exit(0)
|
||||||
elif format == 'gramps':
|
elif format == 'gramps':
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
dbname = os.path.join(filename,const.xmlFile)
|
dbname = os.path.join(filename,const.xmlFile)
|
||||||
@ -1013,9 +1017,28 @@ class Gramps:
|
|||||||
t.close()
|
t.close()
|
||||||
elif format == 'iso':
|
elif format == 'iso':
|
||||||
print "Command-line export to iso is not implemented yet."
|
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):
|
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):
|
def on_ok_button2_clicked(self,obj):
|
||||||
filename = obj.get_filename()
|
filename = obj.get_filename()
|
||||||
|
@ -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
|
||||||
@ -44,7 +44,9 @@ def runTool(database,active_person,callback):
|
|||||||
checker.cleanup_missing_photos()
|
checker.cleanup_missing_photos()
|
||||||
checker.check_parent_relationships()
|
checker.check_parent_relationships()
|
||||||
checker.cleanup_empty_families(0)
|
checker.cleanup_empty_families(0)
|
||||||
checker.report()
|
errs = checker.build_report(0)
|
||||||
|
if errs:
|
||||||
|
checker.report(0)
|
||||||
except:
|
except:
|
||||||
import DisplayTrace
|
import DisplayTrace
|
||||||
DisplayTrace.DisplayTrace()
|
DisplayTrace.DisplayTrace()
|
||||||
@ -206,7 +208,7 @@ class CheckIntegrity:
|
|||||||
family.setFather(mother)
|
family.setFather(mother)
|
||||||
family.setMother(father)
|
family.setMother(father)
|
||||||
|
|
||||||
def report(self):
|
def build_report(self,cl=0):
|
||||||
bad_photos = len(self.bad_photo)
|
bad_photos = len(self.bad_photo)
|
||||||
replaced_photos = len(self.replaced_photo)
|
replaced_photos = len(self.replaced_photo)
|
||||||
removed_photos = len(self.removed_photo)
|
removed_photos = len(self.removed_photo)
|
||||||
@ -219,16 +221,19 @@ class CheckIntegrity:
|
|||||||
errors = blink + efam + photos + rel
|
errors = blink + efam + photos + rel
|
||||||
|
|
||||||
if errors == 0:
|
if errors == 0:
|
||||||
OkDialog(_("No errors were found"),
|
if cl:
|
||||||
_('The database has passed internal checks'))
|
print "No errors were found: the database has passed internal checks."
|
||||||
return
|
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 > 0:
|
||||||
if blink == 1:
|
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:
|
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:
|
for c in self.broken_links:
|
||||||
cn = c[0].getPrimaryName().getName()
|
cn = c[0].getPrimaryName().getName()
|
||||||
f = c[1].getFather()
|
f = c[1].getFather()
|
||||||
@ -240,14 +245,14 @@ class CheckIntegrity:
|
|||||||
pn = f.getPrimaryName().getName()
|
pn = f.getPrimaryName().getName()
|
||||||
else:
|
else:
|
||||||
pn = m.getPrimaryName().getName()
|
pn = m.getPrimaryName().getName()
|
||||||
text.write('\t')
|
self.text.write('\t')
|
||||||
text.write('_("%s was removed from the family of %s\n") % (cn,pn)')
|
self.text.write('_("%s was removed from the family of %s\n") % (cn,pn)')
|
||||||
|
|
||||||
if plink > 0:
|
if plink > 0:
|
||||||
if plink == 1:
|
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:
|
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:
|
for c in self.broken_parent_links:
|
||||||
cn = c[0].getPrimaryName().getName()
|
cn = c[0].getPrimaryName().getName()
|
||||||
f = c[1].getFather()
|
f = c[1].getFather()
|
||||||
@ -259,48 +264,54 @@ class CheckIntegrity:
|
|||||||
pn = f.getPrimaryName().getName()
|
pn = f.getPrimaryName().getName()
|
||||||
else:
|
else:
|
||||||
pn = m.getPrimaryName().getName()
|
pn = m.getPrimaryName().getName()
|
||||||
text.write('\t')
|
self.text.write('\t')
|
||||||
text.write(_("%s was restored to the family of %s\n") % (cn,pn))
|
self.text.write(_("%s was restored to the family of %s\n") % (cn,pn))
|
||||||
|
|
||||||
if efam == 1:
|
if efam == 1:
|
||||||
text.write(_("1 empty family was found\n"))
|
self.text.write(_("1 empty family was found\n"))
|
||||||
elif efam > 1:
|
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:
|
if rel == 1:
|
||||||
text.write(_("1 corrupted family relationship fixed\n"))
|
self.text.write(_("1 corrupted family relationship fixed\n"))
|
||||||
elif rel > 1:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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__)
|
return errors
|
||||||
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)
|
def report(self,cl=0):
|
||||||
textwindow.get_buffer().set_text(text.getvalue())
|
if cl:
|
||||||
text.close()
|
print self.text.getvalue()
|
||||||
top.show()
|
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()
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user