# Path: stoqdrivers/exceptions.py
# class ConfigError(Exception):
#     "Bad config file arguments or sections"
# 
# Path: stoqdrivers/translation.py
# def stoqdrivers_gettext(message):
#     return gettext.dgettext('stoqdrivers', message)


import os
from configparser import ConfigParser
from stoqdrivers.exceptions import ConfigError
from stoqdrivers.translation import stoqdrivers_gettext
        self._load_config()

    def get_homepath(self):
        return os.path.join(os.getenv('HOME'), '.' + self.domain)

    def _open_config(self, path):
        filename = os.path.join(path, self.filename)
        if not os.path.exists(filename):
            return False
        self.config.read(filename)
        return True

    def _load_config(self):
        # Try to load configuration  from:
        # 1) $HOME/.$domain/$filename
        # 2) $PREFIX/etc/$domain/$filename
        # 3) /etc/$filename

        # This is a bit hackish:
        # $prefix / lib / $DOMAIN / lib / configparser.py
        #    -4      -3     -2      -1       0
        filename = os.path.abspath(__file__)
        stripped = filename.split(os.sep)[:-4]
        self.prefix = os.path.join(os.sep, *stripped)

        homepath = self.get_homepath()
        etcpath = os.path.join(self.prefix, 'etc', self.domain)
        globetcpath = os.path.join(os.sep, 'etc', self.domain)
        if not (self._open_config(homepath) or self._open_config(etcpath) or
                self._open_config(globetcpath)):

# Path: stoqdrivers/exceptions.py
# class ConfigError(Exception):
#     "Bad config file arguments or sections"
# 
# Path: stoqdrivers/translation.py
# def stoqdrivers_gettext(message):
#     return gettext.dgettext('stoqdrivers', message)


# Path: stoqdrivers/configparser.py
import os
from configparser import ConfigParser
from stoqdrivers.exceptions import ConfigError
from stoqdrivers.translation import stoqdrivers_gettext

        self._load_config()

    def get_homepath(self):
        return os.path.join(os.getenv('HOME'), '.' + self.domain)

    def _open_config(self, path):
        filename = os.path.join(path, self.filename)
        if not os.path.exists(filename):
            return False
        self.config.read(filename)
        return True

    def _load_config(self):
        # Try to load configuration  from:
        # 1) $HOME/.$domain/$filename
        # 2) $PREFIX/etc/$domain/$filename
        # 3) /etc/$filename

        # This is a bit hackish:
        # $prefix / lib / $DOMAIN / lib / configparser.py
        #    -4      -3     -2      -1       0
        filename = os.path.abspath(__file__)
        stripped = filename.split(os.sep)[:-4]
        self.prefix = os.path.join(os.sep, *stripped)

        homepath = self.get_homepath()
        etcpath = os.path.join(self.prefix, 'etc', self.domain)
        globetcpath = os.path.join(os.sep, 'etc', self.domain)
        if not (self._open_config(homepath) or self._open_config(etcpath) or
                self._open_config(globetcpath)):

            raise ConfigError(_("Config file %s not found in: `%s', `%s' and "