Python fapws.config.load_config() Examples

The following are 10 code examples of fapws.config.load_config(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fapws.config , or try the search function .
Example #1
Source File: bottle.py    From warriorframework with Apache License 2.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #2
Source File: bottle.py    From warriorframework with Apache License 2.0 5 votes vote down vote up
def load_config(self, filename):
        """ Load values from an ``*.ini`` style config file.

            If the config file contains sections, their names are used as
            namespaces for the values within. The two special sections
            ``DEFAULT`` and ``bottle`` refer to the root namespace (no prefix).
        """
        conf = ConfigParser()
        conf.read(filename)
        for section in conf.sections():
            for key, value in conf.items(section):
                if section not in ('DEFAULT', 'bottle'):
                    key = section + '.' + key
                self[key] = value
        return self 
Example #3
Source File: bottle.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #4
Source File: bottle.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def load_config(self, filename):
        """ Load values from an ``*.ini`` style config file.

            If the config file contains sections, their names are used as
            namespaces for the values within. The two special sections
            ``DEFAULT`` and ``bottle`` refer to the root namespace (no prefix).
        """
        conf = ConfigParser()
        conf.read(filename)
        for section in conf.sections():
            for key, value in conf.items(section):
                if section not in ('DEFAULT', 'bottle'):
                    key = section + '.' + key
                self[key] = value
        return self 
Example #5
Source File: bottle.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #6
Source File: bottle.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def load_config(self, filename):
        """ Load values from an ``*.ini`` style config file.

            If the config file contains sections, their names are used as
            namespaces for the values within. The two special sections
            ``DEFAULT`` and ``bottle`` refer to the root namespace (no prefix).
        """
        conf = ConfigParser()
        conf.read(filename)
        for section in conf.sections():
            for key, value in conf.items(section):
                if section not in ('DEFAULT', 'bottle'):
                    key = section + '.' + key
                self[key] = value
        return self 
Example #7
Source File: bottle.py    From silvia-pi with MIT License 4 votes vote down vote up
def load_config(self, filename, **options):
        """ Load values from an ``*.ini`` style config file.

            A configuration file consists of sections, each led by a
            ``[section]`` header, followed by key/value entries separated by
            either ``=`` or ``:``. Section names and keys are case-insensitive.
            Leading and trailing whitespace is removed from keys and values.
            Values can be omitted, in which case the key/value delimiter may
            also be left out. Values can also span multiple lines, as long as
            they are indented deeper than the first line of the value. Commends
            are prefixed by ``#`` or ``;`` and may only appear on their own on
            an otherwise empty line.

            Both section and key names may contain dots (``.``) as namespace
            separators. The actual configuration parameter name is constructed
            by joining section name and key name together and converting to
            lower case.

            The special sections ``bottle`` and ``ROOT`` refer to the root
            namespace and the ``DEFAULT`` section defines default values for all
            other sections.

            With Python 3, extended string interpolation is enabled.

            :param filename: The path of a config file, or a list of paths.
            :param options: All keyword parameters are passed to the underlying
                :class:`python:configparser.ConfigParser` constructor call.

        """
        options.setdefault('allow_no_value', True)
        if py3k:
            options.setdefault('interpolation',
                               configparser.ExtendedInterpolation())
        conf = configparser.ConfigParser(**options)
        conf.read(filename)
        for section in conf.sections():
            for key in conf.options(section):
                value = conf.get(section, key)
                if section not in ['bottle', 'ROOT']:
                    key = section + '.' + key
                self[key.lower()] = value
        return self 
Example #8
Source File: bottle.py    From silvia-pi with MIT License 4 votes vote down vote up
def _main(argv):  # pragma: no coverage
    args, parser = _cli_parse(argv)

    def _cli_error(cli_msg):
        parser.print_help()
        _stderr('\nError: %s\n' % cli_msg)
        sys.exit(1)

    if args.version:
        _stdout('Bottle %s\n' % __version__)
        sys.exit(0)
    if not args.app:
        _cli_error("No application entry point specified.")

    sys.path.insert(0, '.')
    sys.modules.setdefault('bottle', sys.modules['__main__'])

    host, port = (args.bind or 'localhost'), 8080
    if ':' in host and host.rfind(']') < host.rfind(':'):
        host, port = host.rsplit(':', 1)
    host = host.strip('[]')

    config = ConfigDict()

    for cfile in args.conf or []:
        try:
            if cfile.endswith('.json'):
                with open(cfile, 'rb') as fp:
                    config.load_dict(json_loads(fp.read()))
            else:
                config.load_config(cfile)
        except configparser.Error as parse_error:
            _cli_error(parse_error)
        except IOError:
            _cli_error("Unable to read config file %r" % cfile)
        except (UnicodeError, TypeError, ValueError) as error:
            _cli_error("Unable to parse config file %r: %s" % (cfile, error))

    for cval in args.param or []:
        if '=' in cval:
            config.update((cval.split('=', 1),))
        else:
            config[cval] = True

    run(args.app,
        host=host,
        port=int(port),
        server=args.server,
        reloader=args.reload,
        plugins=args.plugin,
        debug=args.debug,
        config=config) 
Example #9
Source File: bottle.py    From slack-machine with MIT License 4 votes vote down vote up
def load_config(self, filename, **options):
        """ Load values from an ``*.ini`` style config file.

            A configuration file consists of sections, each led by a
            ``[section]`` header, followed by key/value entries separated by
            either ``=`` or ``:``. Section names and keys are case-insensitive.
            Leading and trailing whitespace is removed from keys and values.
            Values can be omitted, in which case the key/value delimiter may
            also be left out. Values can also span multiple lines, as long as
            they are indented deeper than the first line of the value. Commands
            are prefixed by ``#`` or ``;`` and may only appear on their own on
            an otherwise empty line.

            Both section and key names may contain dots (``.``) as namespace
            separators. The actual configuration parameter name is constructed
            by joining section name and key name together and converting to
            lower case.

            The special sections ``bottle`` and ``ROOT`` refer to the root
            namespace and the ``DEFAULT`` section defines default values for all
            other sections.

            With Python 3, extended string interpolation is enabled.

            :param filename: The path of a config file, or a list of paths.
            :param options: All keyword parameters are passed to the underlying
                :class:`python:configparser.ConfigParser` constructor call.

        """
        options.setdefault('allow_no_value', True)
        if py3k:
            options.setdefault('interpolation',
                               configparser.ExtendedInterpolation())
        conf = configparser.ConfigParser(**options)
        conf.read(filename)
        for section in conf.sections():
            for key in conf.options(section):
                value = conf.get(section, key)
                if section not in ['bottle', 'ROOT']:
                    key = section + '.' + key
                self[key.lower()] = value
        return self 
Example #10
Source File: bottle.py    From slack-machine with MIT License 4 votes vote down vote up
def _main(argv):  # pragma: no coverage
    args, parser = _cli_parse(argv)

    def _cli_error(cli_msg):
        parser.print_help()
        _stderr('\nError: %s\n' % cli_msg)
        sys.exit(1)

    if args.version:
        _stdout('Bottle %s\n' % __version__)
        sys.exit(0)
    if not args.app:
        _cli_error("No application entry point specified.")

    sys.path.insert(0, '.')
    sys.modules.setdefault('bottle', sys.modules['__main__'])

    host, port = (args.bind or 'localhost'), 8080
    if ':' in host and host.rfind(']') < host.rfind(':'):
        host, port = host.rsplit(':', 1)
    host = host.strip('[]')

    config = ConfigDict()

    for cfile in args.conf or []:
        try:
            if cfile.endswith('.json'):
                with open(cfile, 'rb') as fp:
                    config.load_dict(json_loads(fp.read()))
            else:
                config.load_config(cfile)
        except configparser.Error as parse_error:
            _cli_error(parse_error)
        except IOError:
            _cli_error("Unable to read config file %r" % cfile)
        except (UnicodeError, TypeError, ValueError) as error:
            _cli_error("Unable to parse config file %r: %s" % (cfile, error))

    for cval in args.param or []:
        if '=' in cval:
            config.update((cval.split('=', 1),))
        else:
            config[cval] = True

    run(args.app,
        host=host,
        port=int(port),
        server=args.server,
        reloader=args.reload,
        plugins=args.plugin,
        debug=args.debug,
        config=config)