Start reading config file
This commit is contained in:
parent
c64d1029a7
commit
1ae1b19888
@ -55,7 +55,7 @@ class Config:
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
config: The configuration data as an OrderedDict.
|
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.
|
_wrapper_args: A dict with the default kwargs for the config wrappers.
|
||||||
_configdir: The dictionary to read the config from and save it in.
|
_configdir: The dictionary to read the config from and save it in.
|
||||||
_configfile: The config file path.
|
_configfile: The config file path.
|
||||||
@ -73,6 +73,11 @@ class Config:
|
|||||||
'break_on_hyphens': False,
|
'break_on_hyphens': False,
|
||||||
}
|
}
|
||||||
self._configdir = configdir
|
self._configdir = configdir
|
||||||
|
for secname, section in self.config.items():
|
||||||
|
try:
|
||||||
|
section.from_cp(self._configparser[secname])
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Get a section from the config."""
|
"""Get a section from the config."""
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
"""Setting sections used for qutebrowser."""
|
"""Setting sections used for qutebrowser."""
|
||||||
|
|
||||||
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import qutebrowser.config.conftypes as conftypes
|
import qutebrowser.config.conftypes as conftypes
|
||||||
@ -88,6 +89,12 @@ class KeyValue:
|
|||||||
"""Get dict item tuples."""
|
"""Get dict item tuples."""
|
||||||
return self.values.items()
|
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:
|
class ValueList:
|
||||||
|
|
||||||
@ -164,6 +171,14 @@ class ValueList:
|
|||||||
self.update_valdict()
|
self.update_valdict()
|
||||||
return self.valdict.items()
|
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):
|
class SearchEngines(ValueList):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user