From 4173a47ade97750f07297b5c9f1c72edfe61c86c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 9 Apr 2014 22:44:07 +0200 Subject: [PATCH] Try to implement set command --- qutebrowser/config/config.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 0c452d045..093ea11a3 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -28,7 +28,7 @@ import os.path import logging import textwrap import configparser -from configparser import ConfigParser, ExtendedInterpolation +from configparser import ConfigParser, ExtendedInterpolation, NoSectionError #from qutebrowser.utils.misc import read_file import qutebrowser.config.configdata as configdata @@ -213,6 +213,35 @@ class Config: newval = val.typ.transform(newval) return newval + # FIXME completion for values + @cmdutils.register(name='set', instance='config', completion=['setting'], + split_args=False, nargs=(3,3)) + def set_wrapper(self, secopt, val): + """Set the value for a section/option. + + Wrapper for the set-command to have section/option in one arg. + + Arguments: + secopt: Section and option, delimited by a space. + + """ + sect, opt = secopt.split() + self.set(sect, opt, val) + + def set(self, section, option, value): + """Set an option.""" + if value: + value = self._interpolation.before_set(self, section, option, + value) + if not section or section == self.default_section: + sectdict = self._defaults + else: + try: + sectdict = self._sections[section] + except KeyError: + raise NoSectionError(section) + sectdict[self.optionxform(option)] = value + def save(self): """Save the config file.""" if not os.path.exists(self._configdir):