Add ConfigObj 4.6.0 from http://www.voidspace.org.uk/python/configobj.html. Add a really simple implementation of config saving
This commit is contained in:
parent
60a1b085b4
commit
f91d76e9b4
|
@ -38,6 +38,8 @@ Classes relating to configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
|
import sys
|
||||||
|
from configobj import ConfigObj
|
||||||
from borg import Borg
|
from borg import Borg
|
||||||
from util import dbg
|
from util import dbg
|
||||||
|
|
||||||
|
@ -193,6 +195,10 @@ class Config(object):
|
||||||
"""Set our profile (which usually means change it)"""
|
"""Set our profile (which usually means change it)"""
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""Cause ConfigBase to save our config to file"""
|
||||||
|
return(self.base.save())
|
||||||
|
|
||||||
class ConfigBase(Borg):
|
class ConfigBase(Borg):
|
||||||
"""Class to provide access to our user configuration"""
|
"""Class to provide access to our user configuration"""
|
||||||
global_config = None
|
global_config = None
|
||||||
|
@ -264,6 +270,17 @@ class ConfigBase(Borg):
|
||||||
|
|
||||||
return(True)
|
return(True)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""Save the config to a file"""
|
||||||
|
sections = ['global_config', 'keybindings', 'profiles', 'plugins']
|
||||||
|
parser = ConfigObj()
|
||||||
|
parser.indent_type = ' '
|
||||||
|
for section_name in sections:
|
||||||
|
section = getattr(self, section_name)
|
||||||
|
parser[section_name] = section
|
||||||
|
|
||||||
|
parser.write(sys.stdout)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
(failed, attempted) = doctest.testmod()
|
(failed, attempted) = doctest.testmod()
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue