config.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def __init__(self, config_file=None):

                if config_file:
                        try:
                                # ConfigParser doesn't do a good job of
                                # error reporting, so we'll just try to open
                                # the file
                                open(config_file, "r").close()
                        except (EnvironmentError) as err:
                                raise PkglintConfigException(
                                    _("unable to read config file: {0} ").format(
                                    err))
                try:
                        if six.PY2:
                                self.config = configparser.SafeConfigParser(
                                    defaults)
                        else:
                                # SafeConfigParser has been renamed to
                                # ConfigParser in Python 3.2.
                                self.config = configparser.ConfigParser(
                                    defaults)
                        if not config_file:
                                if six.PY2:
                                        self.config.readfp(
                                            open("/usr/share/lib/pkg/pkglintrc"))
                                else:
                                        self.config.read_file(
                                            open("/usr/share/lib/pkg/pkglintrc"))
                                self.config.read(
                                    [os.path.expanduser("~/.pkglintrc")])
                        else:
                                self.config.read(config_file)

                        # sanity check our config by looking for a known key
                        self.config.get("pkglint", "log_level")
                except configparser.Error as err:
                        raise PkglintConfigException(
                            _("missing or corrupt pkglintrc file "
                            "{config_file}: {err}").format(**locals()))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号