From 1ae1b19888c6ced1e37405015757157b799e5b19 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 10 Mar 2014 00:37:35 +0100 Subject: [PATCH] Start reading config file --- qutebrowser/config/config.py | 7 ++++++- qutebrowser/config/sections.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 43b9db257..2d4f4a37e 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -55,7 +55,7 @@ class Config: Attributes: config: The configuration data as an OrderedDict. - _configparser: A custom ConfigParser instance to load/save files. + _configparser: A ReadConfigParser instance to load the config. _wrapper_args: A dict with the default kwargs for the config wrappers. _configdir: The dictionary to read the config from and save it in. _configfile: The config file path. @@ -73,6 +73,11 @@ class Config: 'break_on_hyphens': False, } self._configdir = configdir + for secname, section in self.config.items(): + try: + section.from_cp(self._configparser[secname]) + except KeyError: + pass def __getitem__(self, key): """Get a section from the config.""" diff --git a/qutebrowser/config/sections.py b/qutebrowser/config/sections.py index df66883d9..24826fbb8 100644 --- a/qutebrowser/config/sections.py +++ b/qutebrowser/config/sections.py @@ -17,6 +17,7 @@ """Setting sections used for qutebrowser.""" +import logging from collections import OrderedDict import qutebrowser.config.conftypes as conftypes @@ -88,6 +89,12 @@ class KeyValue: """Get dict item tuples.""" return self.values.items() + def from_cp(self, sect): + """Initialize the values from a configparser section.""" + for k, v in sect.items(): + logging.debug("'{}' = '{}'".format(k, v)) + self.values[k].rawvalue = v + class ValueList: @@ -164,6 +171,14 @@ class ValueList: self.update_valdict() return self.valdict.items() + def from_cp(self, sect): + """Initialize the values from a configparser section.""" + keytype = self.types[0]() + valtype = self.types[1]() + for k, v in sect.items(): + keytype.validate(k) + valtype.validate(v) + self.values[keytype.transform(k)] = valtype.transform(v) class SearchEngines(ValueList):