Start reading config file

This commit is contained in:
Florian Bruhin 2014-03-10 00:37:35 +01:00
parent c64d1029a7
commit 1ae1b19888
2 changed files with 21 additions and 1 deletions

View File

@ -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."""

View File

@ -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):