How to use the isbntools._initapp.conf.has_section function in isbntools

To help you get started, we’ve selected a few isbntools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xlcnd / isbntools / isbntools / _hook.py View on Github external
# -*- coding: utf-8 -*-

"""Functions to work with isbntools.conf file."""

import os
import sys

from .__init__ import __version__
from ._initapp import conf
from .app import defaults_conf, pkg_path

__all__ = ('pkg_version', 'pkg_path', 'pkg_options', 'reg_mod', 'conf_file',
           'reg_plugin', 'reg_apikey', 'mk_conf', 'print_conf', 'reg_myopt')

pkg_version = __version__
pkg_options = conf.items('MODULES') if conf.has_section('MODULES') else []
conf_file = conf.files[-1] if conf.files else defaults_conf

VIRTUAL = True if hasattr(sys, 'real_prefix') else False


def _write2conf(section, opts):
    if not conf.has_section(section):
        conf.add_section(section)
    for k, v in opts.items():
        conf.set(section, k, v)
    with open(conf_file, 'w') as f:
        conf.write(f)


def reg_mod(opts):
    _write2conf('MODULES', opts)