* src/gramps_main.py: better error messages on database write failure

* src/WriteXML.py: better error messages on database write failure
* src/GrampsXML.py: better error messages on database write failure

* src/PeopleView.py (PeopleView.add_to_person_list): don't attempt to sort the
model unless it has be assigned.


svn: r2736
This commit is contained in:
Don Allingham 2004-02-01 03:16:23 +00:00
parent b0b30654b2
commit d2ef9e69fe
3 changed files with 36 additions and 9 deletions

View File

@ -36,7 +36,7 @@ class GrampsXML(RelLib.GrampsDB):
def save(self,name,callback):
WriteXML.exportData(self,name,callback)
def load(self,name,callback):
ReadXML.loadData(self,name,callback)
for key in self.personMap.keys():

View File

@ -68,8 +68,8 @@ except:
#-------------------------------------------------------------------------
def exportData(database, filename, callback):
if os.path.isfile(filename):
shutil.copyfile(filename, filename + ".bak")
try:
shutil.copyfile(filename, filename + ".bak")
shutil.copystat(filename, filename + ".bak")
except:
pass
@ -77,7 +77,9 @@ def exportData(database, filename, callback):
compress = GrampsCfg.uncompress == 0 and _gzip_ok == 1
try:
print "xmlwriter"
g = XmlWriter(database,callback,0,compress)
print "done"
g.write(filename)
except:
import DisplayTrace
@ -128,14 +130,39 @@ class XmlWriter:
"""
Write the database to the specified file.
"""
base = os.path.dirname(filename)
if os.path.isdir(base):
if not os.access(base,os.W_OK) or not os.access(base,os.R_OK):
ErrorDialog(_('Failure writing %s') % filename,
_("The database cannot be saved because you do not "
"have permission to write to the directory. "
"Please make sure you have write access to the "
"directory and try again."))
return
if os.path.exists(filename):
if not os.access(filename,os.W_OK):
ErrorDialog(_('Failure writing %s') % filename,
_("The database cannot be saved because you do not "
"have permission to write to the file. "
"Please make sure you have write access to the "
"file and try again."))
return
self.fileroot = os.path.dirname(filename)
if self.compress:
try:
g = gzip.open(filename,"wb")
except:
try:
if self.compress:
try:
g = gzip.open(filename,"wb")
except:
g = open(filename,"w")
else:
g = open(filename,"w")
else:
g = open(filename,"w")
except IOError,msg:
ErrorDialog(_('Failure writing %s') % filename,msg)
return
self.g = codecs.getwriter("utf8")(g)
self.write_xml_data()

View File

@ -1200,7 +1200,7 @@ class Gramps:
self.db.clear_added_media_objects()
except (OSError,IOError), msg:
emsg = _("Could not create %s") % filename
ErrorDialog(emsg,_("An error was detected while trying to create the file"))
ErrorDialog(emsg,msg)
return
self.db.setSavePath(old_file)