[pitivi] settings: Report success when section already exists
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] settings: Report success when section already exists
- Date: Sat, 13 Jul 2019 23:15:08 +0000 (UTC)
commit e4e03f1e069c1290a4ab4b4ced264a53f42033fe
Author: Ayush <ayush mittal9398 gmail com>
Date: Fri Jul 12 02:51:23 2019 +0530
settings: Report success when section already exists
Fixes #2308
pitivi/settings.py | 16 +++++------
plugins/console/console.py | 66 ++++++++++++++++++----------------------------
tests/test_settings.py | 5 ++--
3 files changed, 34 insertions(+), 53 deletions(-)
---
diff --git a/pitivi/settings.py b/pitivi/settings.py
index f3a78e2a..ad8030b7 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -346,11 +346,12 @@ class GlobalSettings(GObject.Object, Loggable):
notification = Notification(attrname)
setattr(cls, attrname, notification)
setattr(cls, "_" + attrname, default)
- GObject.signal_new(notification.signame,
- cls,
- GObject.SignalFlags.RUN_LAST,
- None,
- ())
+ if notification.signame not in GObject.signal_list_names(cls):
+ GObject.signal_new(notification.signame,
+ cls,
+ GObject.SignalFlags.RUN_LAST,
+ None,
+ ())
else:
setattr(cls, attrname, default)
if section and key:
@@ -364,12 +365,9 @@ class GlobalSettings(GObject.Object, Loggable):
Args:
section (str): The section name.
-
- Raises:
- ConfigError: If the section already exists.
"""
if section in cls.options:
- raise ConfigError("Duplicate Section \"%s\"." % section)
+ return
cls.options[section] = {}
@classmethod
diff --git a/plugins/console/console.py b/plugins/console/console.py
index 1c541897..d22af578 100644
--- a/plugins/console/console.py
+++ b/plugins/console/console.py
@@ -30,7 +30,6 @@ from utils import Namespace
from widgets import ConsoleWidget
from pitivi.dialogs.prefs import PreferencesDialog
-from pitivi.settings import ConfigError
class PitiviNamespace(Namespace):
@@ -90,46 +89,31 @@ class Console(GObject.GObject, Peas.Activatable):
def do_activate(self):
api = self.object
self.app = api.app
- try:
- self.app.settings.addConfigSection("console")
- except ConfigError:
- pass
-
- try:
- self.app.settings.addConfigOption(attrname="consoleColor",
- section="console",
- key="console-color",
- notify=True,
- default=Console.DEFAULT_COLOR)
- except ConfigError:
- pass
-
- try:
- self.app.settings.addConfigOption(attrname="consoleErrorColor",
- section="console",
- key="console-error-color",
- notify=True,
- default=Console.DEFAULT_STDERR_COLOR)
- except ConfigError:
- pass
-
- try:
- self.app.settings.addConfigOption(attrname="consoleOutputColor",
- section="console",
- key="console-output-color",
- notify=True,
- default=Console.DEFAULT_STDOUT_COLOR)
- except ConfigError:
- pass
-
- try:
- self.app.settings.addConfigOption(attrname="consoleFont",
- section="console",
- key="console-font",
- notify=True,
- default=Console.DEFAULT_FONT.to_string())
- except ConfigError:
- pass
+ self.app.settings.addConfigSection("console")
+
+ self.app.settings.addConfigOption(attrname="consoleColor",
+ section="console",
+ key="console-color",
+ notify=True,
+ default=Console.DEFAULT_COLOR)
+
+ self.app.settings.addConfigOption(attrname="consoleErrorColor",
+ section="console",
+ key="console-error-color",
+ notify=True,
+ default=Console.DEFAULT_STDERR_COLOR)
+
+ self.app.settings.addConfigOption(attrname="consoleOutputColor",
+ section="console",
+ key="console-output-color",
+ notify=True,
+ default=Console.DEFAULT_STDOUT_COLOR)
+
+ self.app.settings.addConfigOption(attrname="consoleFont",
+ section="console",
+ key="console-font",
+ notify=True,
+ default=Console.DEFAULT_FONT.to_string())
self.app.settings.reload_attribute_from_file("console", "consoleColor")
self.app.settings.reload_attribute_from_file("console",
diff --git a/tests/test_settings.py b/tests/test_settings.py
index 314958e4..5105b93d 100644
--- a/tests/test_settings.py
+++ b/tests/test_settings.py
@@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Tests for the pitivi.settings module."""
-# pylint: disable=missing-docstring
+# pylint: disable=missing-docstring,no-self-use
import os
import tempfile
from unittest import mock
@@ -68,8 +68,7 @@ class TestGlobalSettings(common.TestCase):
def test_add_section(self):
GlobalSettings.addConfigSection("section-a")
- with self.assertRaises(ConfigError):
- GlobalSettings.addConfigSection("section-a")
+ GlobalSettings.addConfigSection("section-a")
def test_add_config_option(self):
def add_option():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]