Philipp Hörist pushed to branch master at gajim / gajim

Commits:
877b754e by Philipp Hörist at 2018-02-12T23:39:50+01:00
Simplfy writing to config file

- use `with` statement and open() instead of os.open()
- execute run() on dialog, otherwise sys.exit() is called immediatly

- - - - -


2 changed files:

- gajim/common/optparser.py
- gajim/gui_interface.py


Changes:

=====================================
gajim/common/optparser.py
=====================================
--- a/gajim/common/optparser.py
+++ b/gajim/common/optparser.py
@@ -111,24 +111,18 @@ class OptionsParser:
         (base_dir, filename) = os.path.split(self.__filename)
         self.__tempfile = os.path.join(base_dir, '.' + filename)
         try:
-            f = os.fdopen(os.open(self.__tempfile,
-                os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0o600), 'w', 
encoding='utf-8')
+            with open(self.__tempfile, 'w', encoding='utf-8') as f:
+                app.config.foreach(self.write_line, f)
         except IOError as e:
             return str(e)
-        try:
-            app.config.foreach(self.write_line, f)
-        except IOError as e:
-            return str(e)
-        f.flush()
-        os.fsync(f.fileno())
-        f.close()
+
         if os.path.exists(self.__filename):
             if os.name == 'nt':
                 # win32 needs this
                 try:
                     os.remove(self.__filename)
-                except Exception:
-                    pass
+                except Exception as e:
+                    return str(e)
         try:
             os.rename(self.__tempfile, self.__filename)
         except IOError as e:


=====================================
gajim/gui_interface.py
=====================================
--- a/gajim/gui_interface.py
+++ b/gajim/gui_interface.py
@@ -2408,8 +2408,9 @@ class Interface:
             print(err_str, file=sys.stderr)
             # it is good to notify the user
             # in case he or she cannot see the output of the console
-            dialogs.ErrorDialog(_('Could not save your settings and '
+            error_dialog = dialogs.ErrorDialog(_('Could not save your settings 
and '
                 'preferences'), err_str)
+            error_dialog.run()
             sys.exit()
 
     @staticmethod



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/877b754ef3965d947c78e072daaf990a2a3e88e3

---
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/877b754ef3965d947c78e072daaf990a2a3e88e3
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to