Browse files

better api for settings

  • Loading branch information...
1 parent f54f0b3 commit dceaa32e55a8991e01a9e9b7c1dc7fa5c08bd2c9 @ik5 committed Feb 6, 2013
Showing with 11 additions and 5 deletions.
  1. +11 −5 convert_quotes.py
View
16 convert_quotes.py
@@ -36,16 +36,22 @@ def init_config() :
(CONFIG, CONFIG_FILE) = init_config()
-def get_config(section, value, default=None, config = CONFIG) :
- """Get a configuration settings"""
+def save_config_file(config = CONFIG, name = CONFIG_FILE) :
+ with open(name, 'wb') as conf :
+ config.write(conf)
+def set_config(section, value, content, config = CONFIG) :
if not config.has_section(section) :
config.add_section(section)
- config.set(section, value, default)
- with open(CONFIG_FILE, 'wb') as conf :
- config.write(conf)
+ config.set(section, value, content)
+ save_config_file(config)
+
+def get_config(section, value, default=None, config = CONFIG) :
+ """Get a configuration settings"""
+ if not config.has_section(section) :
+ set_config(section, value, default, config)
return default
return config.get(section, value, default)

0 comments on commit dceaa32

Please sign in to comment.