8 Creates and reads config file using ConfigParser::
12 overlay path = ~/src/my-overlay/
16 from ConfigParser import RawConfigParser as _Parser
17 from ConfigParser import NoSectionError, NoOptionError
20 from logging.config import fileConfig
22 from g_pypi.portage_utils import get_keyword, get_portdir_overlay, get_repo_name
25 __docformat__ = 'restructuredtext'
27 CONFIG_DIR = os.path.expanduser("~/.g-pypi")
29 def get_rc_filename():
30 """Return rc_file filename"""
31 return os.path.join(CONFIG_DIR, "g-pypirc")
34 "Possibly overrides 'g-pypi' logger stored in logging package"
35 logger = logging.getLogger('g-pypi')
37 fileConfig(fname=get_rc_filename())
38 except (NoSectionError, NoOptionError), e:
39 logger.info('using default logger')
41 return logging.getLogger('g-pypi')
43 def setup_config(cls=None):
44 """Read config file, create if it doesn't exist"""
48 config.add_section('options')
49 config.set('options', 'background', 'dark')
50 config.add_section('core')
51 config.set('core', 'keyword', get_keyword())
52 config.set('core', 'overlay', get_repo_name(get_portdir_overlay()))
53 config.set('core', 'overlay_path', '')
54 config.set('core', 'format', 'ansi')
55 config.read([get_rc_filename()])
58 class Parser (_Parser):
59 "Extended ConfigParser with `setboolean()` and similar methods."
60 def setboolean(self, section, option, value):
61 self.set(section, option, str(value).lower())
63 def get(self, section, option, default=None):
64 logger = logging.getLogger('g-pypi')
66 value = _Parser.get(self, section, option)
67 except (NoSectionError, NoOptionError), e:
68 logger.warning(str(e))
72 CONFIG = setup_config()