From 9480bc89939fc4395e070a74632d01b02ab7bf4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Sep 2018 20:36:41 +0200 Subject: [PATCH] Do not fail on configparser error The client should not crash if the profiles.cfg is corrupted because it prevent the user to use the profile manager and correct the error. issue7751 review49611002 --- tryton/gui/window/dblogin.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tryton/gui/window/dblogin.py b/tryton/gui/window/dblogin.py index f47fb6fbee..bee02f9804 100644 --- a/tryton/gui/window/dblogin.py +++ b/tryton/gui/window/dblogin.py @@ -7,6 +7,7 @@ import gobject import os import gettext import threading +import logging from gi.repository import Gtk @@ -17,6 +18,7 @@ import tryton.rpc as rpc from tryton.common.underline import set_underline _ = gettext.gettext +logger = logging.getLogger(__name__) class DBListEditor(object): @@ -493,7 +495,10 @@ class DBLogin(object): self.profiles.set(name, 'database', 'demo%s' % short_version) self.profiles.set(name, 'username', 'demo') else: - self.profiles.read(self.profile_cfg) + try: + self.profiles.read(self.profile_cfg) + except configparser.ParsingError: + logger.error("Fail to parse profiles.cfg", exc_info=True) for section in self.profiles.sections(): active = all(self.profiles.has_option(section, option) for option in ('host', 'database')) @@ -544,8 +549,11 @@ class DBLogin(object): if not profile_info[1]: continue profile = profile_info[0] - profile_host = self.profiles.get(profile, 'host') - profile_db = self.profiles.get(profile, 'database') + try: + profile_host = self.profiles.get(profile, 'host') + profile_db = self.profiles.get(profile, 'database') + except configparser.NoOptionError: + continue if (host == common.get_hostname(profile_host) and port == common.get_port(profile_host) and database == profile_db): @@ -566,12 +574,15 @@ class DBLogin(object): profile_name = CONFIG['login.profile'] can_use_profile = self.profiles.has_section(profile_name) if can_use_profile: - for (configname, sectionname) in [ + for (configname, option) in [ ('login.host', 'host'), ('login.db', 'database'), ]: - if (self.profiles.get(profile_name, sectionname) - != CONFIG[configname]): + try: + value = self.profiles.get(profile_name, option) + except configparser.NoOptionError: + value = None + if value != CONFIG[configname]: can_use_profile = False break