added doc_dir and keywords init to config

main
Fabien Benureau 12 years ago
parent a354e79523
commit ac4b682307

@ -19,6 +19,7 @@ DFT_COLOR = 'yes'
DFT_PLUGINS = 'texnote'
DFT_CONFIG = {'papers_dir' : DFT_PAPERS_DIR,
'doc_dir' : os.path.join(DFT_PAPERS_DIR, 'doc'),
'open_cmd' : DFT_OPEN_CMD,
'edit_cmd' : DFT_EDIT_CMD,
'import_copy' : DFT_IMPORT_COPY,
@ -41,10 +42,12 @@ def config(section = MAIN_SECTION):
class Config(object):
def __init__(self):
def __init__(self, **kwargs):
object.__setattr__(self, '_cfg', configparser.SafeConfigParser(DFT_CONFIG))
object.__setattr__(self, '_section', MAIN_SECTION) # active section
self._cfg.add_section(self._section)
for name, value in kwargs.items():
self.__setattr__(name, value)
def as_global(self):
global _config

@ -58,3 +58,7 @@ class TestConfig(unittest.TestCase):
config(section = 'bla3').color
self.assertEqual(config(section = 'bla3').get('color', default = 'green'), 'green')
self.assertEqual(config(section = 'bla3').get('color', default = config().color), True)
def test_keywords(self):
a = configs.Config(papers_dir = '/blabla')
self.assertEqual(a.papers_dir, '/blabla')

Loading…
Cancel
Save