From 65050b3a40e7b9a6799322198c6603d33a5a2cd8 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 9 Dec 2005 04:49:49 +0000 Subject: [PATCH] * src/Report.py (parse_target_frame): Check permissions for the specified file. svn: r5516 --- gramps2/ChangeLog | 2 ++ gramps2/src/Report.py | 55 +++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 4661f7b3c..640b41b88 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -18,6 +18,8 @@ of the person happened over 150 years ago; (too_old): add function; (not_too_old): require definite year for a positive decision. + * src/Report.py (parse_target_frame): Check permissions for the + specified file. 2005-12-07 Eero Tamminen * src/po/fi.po: Translation update to latest template diff --git a/gramps2/src/Report.py b/gramps2/src/Report.py index 1ed563e00..25b497663 100644 --- a/gramps2/src/Report.py +++ b/gramps2/src/Report.py @@ -1409,20 +1409,51 @@ class ReportDialog(BareReportDialog): if not self.target_path: return None - if not self.get_target_is_directory() and os.path.isdir(self.target_path): - ErrorDialog(_("Invalid file name"), - _("The filename that you gave is a directory.\n" - "You need to provide a valid filename.")) - return None + # First we check whether the selected path exists + if os.path.exists(self.target_path): - if os.path.isfile(self.target_path): - a = OptionDialog(_('File already exists'), - _('You can choose to either overwrite the file, or change ' - 'the selected filename.'), - _('_Overwrite'),None, - _('_Change filename'),None) + # selected path is an existing dir + if os.path.isdir(self.target_path): + # check whether we asked for a dir + if not self.get_target_is_directory(): + ErrorDialog(_("Invalid file name"), + _("The filename that you gave is a " + "directory.\n" + "You need to provide a valid filename.")) + return None + # check whether the dir has rwx permissions + if not os.access(self.target_path,os.R_OK|os.W_OK|os.X_OK): + ErrorDialog(_('Permission problem'), + _("You do not have permissions to write " + "under the directory %s\n\n" + "Please select another directory or correct" + "the permissions." % self.target_path) + ) + return None + + # selected path is an exsting file + if os.path.isfile(self.target_path): + a = OptionDialog(_('File already exists'), + _('You can choose to either overwrite the ' + 'file, or change the selected filename.'), + _('_Overwrite'),None, + _('_Change filename'),None) - if a.get_response() == gtk.RESPONSE_YES: + if a.get_response() == gtk.RESPONSE_YES: + return None + + # selected path does not exist yet + else: + # we will need to create the file/dir + # need to make sure we can create in the parent dir + parent_dir = os.path.dirname(os.path.normpath(self.target_path)) + if not os.access(self.parent_dir,os.W_OK): + ErrorDialog(_('Permission problem'), + _("You do not have permissions to create " + "%s\n\n" + "Please select another path or correct" + "the permissions." % self.target_path) + ) return None self.set_default_directory(os.path.dirname(self.target_path) + os.sep)