diff --git a/zenmap/zenmapCore/UmitConfigParser.py b/zenmap/zenmapCore/UmitConfigParser.py index 5768640dd..5677fb77e 100644 --- a/zenmap/zenmapCore/UmitConfigParser.py +++ b/zenmap/zenmapCore/UmitConfigParser.py @@ -129,6 +129,7 @@ class UmitConfigParser(ConfigParser): def __init__(self, *args): self.filenames = None + self.failed = False ConfigParser.__init__(self, *args) def set(self, section, option, value): @@ -149,7 +150,14 @@ class UmitConfigParser(ConfigParser): def save_changes(self): if self.filenames: log.debug("saving to %s" % self.filenames) - self.write(open(self.filenames, 'w')) + try: + fp = open(self.filenames, 'w') + except Exception as e: + self.failed = e + log.error(">>> Can't save to %s: %s" % (self.filenames, e)) + return + self.write(fp) + self.failed = False else: log.debug(">>> UmitConfigParser can't save changes: no filename") diff --git a/zenmap/zenmapGUI/MainWindow.py b/zenmap/zenmapGUI/MainWindow.py index 8dc6a3aec..3a41b65d9 100644 --- a/zenmap/zenmapGUI/MainWindow.py +++ b/zenmap/zenmapGUI/MainWindow.py @@ -156,7 +156,7 @@ from zenmapCore.RecentScans import recent_scans from zenmapCore.UmitLogging import log import zenmapCore.I18N import zenmapGUI.Print -from zenmapCore.UmitConf import SearchConfig, is_maemo, WindowConfig +from zenmapCore.UmitConf import SearchConfig, is_maemo, WindowConfig, config_parser from zenmapCore.NetworkInventory import FilteredNetworkInventory UmitScanWindow = None @@ -906,23 +906,19 @@ This scan has not been run yet. Start the scan with the "Scan" button first.')) return True window = WindowConfig() - try: - window.x, window.y = self.get_position() - window.width, window.height = self.get_size() - window.save_changes() - except IOError as e: - if e.errno == errno.EACCES: - alert = HIGAlertDialog( - message_format=_("Can't save Zenmap configuration"), - # newline before path to help avoid weird line wrapping - secondary_text=_( - 'Permission denied when writing to\n%s' - '\nMake sure the file exists and is writable.' - ) % (Path.user_config_file)) - alert.run() - alert.destroy() - else: - raise + window.x, window.y = self.get_position() + window.width, window.height = self.get_size() + window.save_changes() + if config_parser.failed: + alert = HIGAlertDialog( + message_format=_("Can't save Zenmap configuration"), + # newline before path to help avoid weird line wrapping + secondary_text=_( + 'An error occurred when saving to\n%s' + '\nThe error was: %s.' + ) % (Path.user_config_file, config_parser.failed)) + alert.run() + alert.destroy() self.destroy() diff --git a/zenmap/zenmapGUI/NmapOutputViewer.py b/zenmap/zenmapGUI/NmapOutputViewer.py index 2e8f30d35..26b5cc9d2 100644 --- a/zenmap/zenmapGUI/NmapOutputViewer.py +++ b/zenmap/zenmapGUI/NmapOutputViewer.py @@ -126,7 +126,6 @@ import gtk import gtk.gdk import pango import re -import errno import zenmapCore.I18N from zenmapCore.UmitLogging import log @@ -264,20 +263,7 @@ class NmapOutputViewer (gtk.VBox): self.nmap_highlight.__setattr__(widget.property_name, wid_props) nmap_out_prop.destroy() - try: - self.nmap_highlight.save_changes() - except IOError as e: - if e.errno == errno.EACCES: - alert = HIGAlertDialog( - message_format=_("Can't save Zenmap configuration"), - secondary_text=_( - 'Permission denied when writing to \n%s' - '\nMake sure the file exists and is writable.' - ) % (Path.user_config_file)) - alert.run() - alert.destroy() - else: - raise + self.nmap_highlight.save_changes() self.apply_highlighting() def apply_highlighting(self, start_iter=None, end_iter=None):