Commit e4e03f1e authored by Ayush Mittal's avatar Ayush Mittal Committed by Alexandru Băluț

settings: Report success when section already exists

Fixes #2308
parent 1625bbf5
Pipeline #95131 failed with stages
in 80 minutes and 39 seconds
......@@ -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
......
......@@ -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",
......
......@@ -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():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment