From 3e9b8d6bd28f7144a4085dcefd8f0b9b01161602 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Tue, 22 Nov 2005 10:56:25 +0000 Subject: [PATCH] enormous cleanup in untested code --- src/common/optparser.py | 16 ++++++---------- src/gajim.py | 13 ++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/common/optparser.py b/src/common/optparser.py index e3a2db9db..928b18bf3 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -101,18 +101,14 @@ class OptionsParser: pass self.__tempfile = os.path.join(base_dir, '.' + filename) try: - fd = open(self.__tempfile, 'w') - except: - #chances are we cannot write file in a directory - err_str = _('Unable to write file in %s') % base_dir - print err_str - return err_str + f = open(self.__tempfile, 'w') + except IOError, e: + return str(e) try: gajim.config.foreach(self.write_line, fd) except IOError, e: - fd.close() - return e.errno - fd.close() + return str(e) + f.close() if os.path.exists(self.__filename): # win32 needs this try: @@ -122,7 +118,7 @@ class OptionsParser: try: os.rename(self.__tempfile, self.__filename) except IOError, e: - return e.errno + return str(e) os.chmod(self.__filename, 0600) def update_config(self, old_version, new_version): diff --git a/src/gajim.py b/src/gajim.py index cdf876e91..6f6746449 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1204,19 +1204,18 @@ class Interface: gajim.mutex_events_for_ui.unlock() time.sleep(0.01) # so threads in connection.py have time to run return True # renew timeout (loop for ever) - except KeyboardInterrupt: + except KeyboardInterrupt: # FIXME: can this happen?? CTRL+C IS CATCHED BY SIGNAL sys.exit() return False def save_config(self): - err_code = parser.write() - if err_code is not None: - strerr = os.strerror(err_code) - print strerr + err_str = parser.write() + if err_str is not None: + print >> sys.stderr, err_str # it is good to notify the user # in case he or she cannot see the output of the console - dialogs.ErrorDialog(_('Cannot save your preferences'), - strerr).get_response() + dialogs.ErrorDialog(_('Could not save your settings and preferences'), + err_str).get_response() sys.exit(1) def __init__(self):