* 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 3a728b13c7
commit 1ead1fc695
3 changed files with 36 additions and 9 deletions

View File

@ -68,8 +68,8 @@ except:
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def exportData(database, filename, callback): def exportData(database, filename, callback):
if os.path.isfile(filename): if os.path.isfile(filename):
shutil.copyfile(filename, filename + ".bak")
try: try:
shutil.copyfile(filename, filename + ".bak")
shutil.copystat(filename, filename + ".bak") shutil.copystat(filename, filename + ".bak")
except: except:
pass pass
@ -77,7 +77,9 @@ def exportData(database, filename, callback):
compress = GrampsCfg.uncompress == 0 and _gzip_ok == 1 compress = GrampsCfg.uncompress == 0 and _gzip_ok == 1
try: try:
print "xmlwriter"
g = XmlWriter(database,callback,0,compress) g = XmlWriter(database,callback,0,compress)
print "done"
g.write(filename) g.write(filename)
except: except:
import DisplayTrace import DisplayTrace
@ -128,14 +130,39 @@ class XmlWriter:
""" """
Write the database to the specified file. 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) self.fileroot = os.path.dirname(filename)
if self.compress: try:
try: if self.compress:
g = gzip.open(filename,"wb") try:
except: g = gzip.open(filename,"wb")
except:
g = open(filename,"w")
else:
g = open(filename,"w") g = open(filename,"w")
else: except IOError,msg:
g = open(filename,"w") ErrorDialog(_('Failure writing %s') % filename,msg)
return
self.g = codecs.getwriter("utf8")(g) self.g = codecs.getwriter("utf8")(g)
self.write_xml_data() self.write_xml_data()

View File

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