summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2012-12-15 03:28:06 +0100
committerFlorent Le Coz <louiz@louiz.org>2012-12-15 03:28:06 +0100
commitc7f4abaef64e994854c6dce5d01b61105a448714 (patch)
treea1be76d964b6fa387cfecc3844f40c28e6475b52 /src/config.py
parent3c83157821ab21aa8e4aa2da479437e88ede6fc9 (diff)
downloadpoezio-c7f4abaef64e994854c6dce5d01b61105a448714.tar.gz
poezio-c7f4abaef64e994854c6dce5d01b61105a448714.tar.bz2
poezio-c7f4abaef64e994854c6dce5d01b61105a448714.tar.xz
poezio-c7f4abaef64e994854c6dce5d01b61105a448714.zip
Add support for /set <option> toggle, which toggles the current value
fix #2184
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/config.py b/src/config.py
index 6bcc139e..0f375c88 100644
--- a/src/config.py
+++ b/src/config.py
@@ -158,12 +158,25 @@ class Config(RawConfigParser):
set the value in the configuration then save it
to the file
"""
+ # Special case for a 'toggle' value. We take the current value
+ # and set the opposite. Warning if the no current value exists
+ # or it is not a bool.
+ if value == "toggle":
+ current = self.get(option, "", section)
+ if current.lower() == "false":
+ value = "true"
+ elif current.lower() == "true":
+ value = "false"
+ else:
+ return "Could not toggle option: %s. Current value is %s." % (option, current or "empty")
if self.has_section(section):
RawConfigParser.set(self, section, option, value)
else:
self.add_section(section)
RawConfigParser.set(self, section, option, value)
self.write_in_file(section, option, value)
+ return "%s=%s" % (option, value)
+
def set(self, option, value, section=DEFSECTION):
"""