Skip to content

Commit

Permalink
Working on a basic config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ik5 committed Feb 6, 2013
1 parent 073e8f4 commit f54f0b3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions convert_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,46 @@
import logging
import atexit
import traceback
import ConfigParser

def init_config() :
"""Initialize config file"""

home = os.path.expanduser('~')

config_dir = 'config'
if os.name == 'posix' :
config_dir = '.%s' % (config_dir)

conf = '{0}{1}{2}{1}{3}{1}{4}'.format(home, os.sep,
config_dir, 'pyquotes',
'settings.conf')

config_dir = os.path.dirname(conf)
if not os.path.exists(config_dir) :
os.makedirs(config_dir)

config = ConfigParser.ConfigParser()
config.read(conf)

return [config, conf]


(CONFIG, CONFIG_FILE) = init_config()

def get_config(section, value, default=None, config = CONFIG) :
"""Get a configuration settings"""

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)

return default

return config.get(section, value, default)

def init_logger() :
"""initialize the logger"""
Expand Down

0 comments on commit f54f0b3

Please sign in to comment.