# Path: repocribro/extending/extension_master.py
# class ExtensionsMaster:
#     """Collector & master of Extensions
# 
#     Extension master finds and holds all the **repocribro** extensions
#     and is used for calling operations on them and collecting the results.
#     """
# 
#     #: String used for looking up the extensions
#     ENTRYPOINT_GROUP = 'repocribro.ext'
#     #: Error message mask for extension load error
#     LOAD_ERROR_MSG = 'Extension "{}" ({}) is not making an Extension ' \
#                      '(sub)class instance. It will be ignored!'
# 
#     @classmethod
#     def _collect_extensions(cls, name=None):
#         """Method for selecting extensions within ``ENTRYPOINT_GROUP``
# 
#         :param name: Can be used to select single entrypoint/extension
#         :type name: str
#         :return: Generator of selected entry points
#         :rtype: ``pkg_resources.WorkingSet.iter_entry_points``
#         """
#         return pkg_resources.iter_entry_points(
#             group=cls.ENTRYPOINT_GROUP, name=name
#         )
# 
#     def __init__(self, *args, **kwargs):
#         """Collects all the extensions to be mantained by this object
# 
#         :param args: positional args to be passed to extensions
#         :param kwargs: keywords args to be passed to extensions
# 
#         .. todo:: There might be some problem with ordering of extensions
#         """
#         entry_points = self._collect_extensions()
#         self.exts = []
#         for ep in entry_points:
#             ext_maker = ep.load()
#             e = ext_maker(master=self, *args, **kwargs)
#             if not isinstance(e, Extension):
#                 print(self.LOAD_ERROR_MSG.format(
#                     ep.name, ep.module_name, file=sys.stderr
#                 ))
#             else:
#                 self.exts.append(e)
#         self.exts.sort(key=lambda e: e.PRIORITY)
# 
#     def call(self, hook_name, default=None, *args, **kwargs):
#         """Call the hook on all extensions registered
# 
#         :param hook_name: Name of hook to be called
#         :type hook_name: str
#         :param default: Default return value if hook operation not found
#         :param args: Positional args to be passed to the hook operation
#         :param kwargs: Keywords args to be passed to the hook operation
#         :return: Result of the operation on the requested hook
#         """
#         return [ext.call(hook_name, default, *args, **kwargs)
#                 for ext in self.exts]
# 
# Path: repocribro/config.py
# def create_config(cfg_files, env_prefix='REPOCRIBRO'):
#     """Factory for making Repocribro config object
# 
#     :param cfg_files: Single or more config file(s)
#     :return: Constructed config object
#     :rtype: ``repocribro.config.Config``
#     """
#     config = Config()
#     config.read(cfg_files)
#     config.mark_mandatory('flask', 'secret_key')
#     config.mark_mandatory('flask', 'SQLALCHEMY_DATABASE_URI')
#     config.default['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'true'
#     config.read_envs(env_prefix)
#     return config
# 
# def check_config(config, exit_code=1):
#     """Procedure for checking mandatory config
# 
#     If there are some missing mandatory configurations this
#     procedure prints info on stderr and exits program with
#     specified exit code.
# 
#     :param config: Configuration object
#     :type config: ``repocribro.config.Config``
#     :param exit_code: Exit code on fail
#     :type exit_code: int
#     :raises: SystemExit
#     """
#     import sys
#     config_errors = config.check()
#     if len(config_errors) == 0:
#         return
#     print('Missing configuration:', file=sys.stderr)
#     for err in config_errors:
#         print('-> ' + err, file=sys.stderr)
#     sys.exit(exit_code)


import flask
import jinja2
import os
from .extending import ExtensionsMaster
from .config import create_config, check_config
    from .database import db
    from .security import permissions
        from werkzeug.serving import run_simple
        from werkzeug.wsgi import DispatcherMiddleware
        """Call hook on all extensions

        :param what_to_call: name of hook to call
        :type what_to_call: str
        :return: result of the call
        """
        ext_master = self.container.get('ext_master')
        return ext_master.call(what_to_call)


def create_app(cfg_files=['DEFAULT']):
    """Factory for making the web Flask application

    :param cfg_files: Single or more config file(s)
    :return: Constructed web application
    :rtype: ``repocribro.repocribro.Repocribro``
    """
    app = Repocribro()
    ext_master = ExtensionsMaster(app=app, db=db)
    app.container.set_singleton('ext_master', ext_master)

    if cfg_files == ['DEFAULT']:
        cfg_files = os.environ.get('REPOCRIBRO_CONFIG_FILE',
                                   DEFAULT_CONFIG_FILES)

    config = create_config(cfg_files)
    config.set('flask', 'release', RELEASE)
    app.container.set_singleton('config', config)
    ext_master.call('setup_config')
    config.update_flask_cfg(app)

# Path: repocribro/extending/extension_master.py
# class ExtensionsMaster:
#     """Collector & master of Extensions
# 
#     Extension master finds and holds all the **repocribro** extensions
#     and is used for calling operations on them and collecting the results.
#     """
# 
#     #: String used for looking up the extensions
#     ENTRYPOINT_GROUP = 'repocribro.ext'
#     #: Error message mask for extension load error
#     LOAD_ERROR_MSG = 'Extension "{}" ({}) is not making an Extension ' \
#                      '(sub)class instance. It will be ignored!'
# 
#     @classmethod
#     def _collect_extensions(cls, name=None):
#         """Method for selecting extensions within ``ENTRYPOINT_GROUP``
# 
#         :param name: Can be used to select single entrypoint/extension
#         :type name: str
#         :return: Generator of selected entry points
#         :rtype: ``pkg_resources.WorkingSet.iter_entry_points``
#         """
#         return pkg_resources.iter_entry_points(
#             group=cls.ENTRYPOINT_GROUP, name=name
#         )
# 
#     def __init__(self, *args, **kwargs):
#         """Collects all the extensions to be mantained by this object
# 
#         :param args: positional args to be passed to extensions
#         :param kwargs: keywords args to be passed to extensions
# 
#         .. todo:: There might be some problem with ordering of extensions
#         """
#         entry_points = self._collect_extensions()
#         self.exts = []
#         for ep in entry_points:
#             ext_maker = ep.load()
#             e = ext_maker(master=self, *args, **kwargs)
#             if not isinstance(e, Extension):
#                 print(self.LOAD_ERROR_MSG.format(
#                     ep.name, ep.module_name, file=sys.stderr
#                 ))
#             else:
#                 self.exts.append(e)
#         self.exts.sort(key=lambda e: e.PRIORITY)
# 
#     def call(self, hook_name, default=None, *args, **kwargs):
#         """Call the hook on all extensions registered
# 
#         :param hook_name: Name of hook to be called
#         :type hook_name: str
#         :param default: Default return value if hook operation not found
#         :param args: Positional args to be passed to the hook operation
#         :param kwargs: Keywords args to be passed to the hook operation
#         :return: Result of the operation on the requested hook
#         """
#         return [ext.call(hook_name, default, *args, **kwargs)
#                 for ext in self.exts]
# 
# Path: repocribro/config.py
# def create_config(cfg_files, env_prefix='REPOCRIBRO'):
#     """Factory for making Repocribro config object
# 
#     :param cfg_files: Single or more config file(s)
#     :return: Constructed config object
#     :rtype: ``repocribro.config.Config``
#     """
#     config = Config()
#     config.read(cfg_files)
#     config.mark_mandatory('flask', 'secret_key')
#     config.mark_mandatory('flask', 'SQLALCHEMY_DATABASE_URI')
#     config.default['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'true'
#     config.read_envs(env_prefix)
#     return config
# 
# def check_config(config, exit_code=1):
#     """Procedure for checking mandatory config
# 
#     If there are some missing mandatory configurations this
#     procedure prints info on stderr and exits program with
#     specified exit code.
# 
#     :param config: Configuration object
#     :type config: ``repocribro.config.Config``
#     :param exit_code: Exit code on fail
#     :type exit_code: int
#     :raises: SystemExit
#     """
#     import sys
#     config_errors = config.check()
#     if len(config_errors) == 0:
#         return
#     print('Missing configuration:', file=sys.stderr)
#     for err in config_errors:
#         print('-> ' + err, file=sys.stderr)
#     sys.exit(exit_code)


# Path: repocribro/repocribro.py
import flask
import jinja2
import os
from .extending import ExtensionsMaster
from .config import create_config, check_config
    from .database import db
    from .security import permissions
        from werkzeug.serving import run_simple
        from werkzeug.wsgi import DispatcherMiddleware

        """Call hook on all extensions

        :param what_to_call: name of hook to call
        :type what_to_call: str
        :return: result of the call
        """
        ext_master = self.container.get('ext_master')
        return ext_master.call(what_to_call)


def create_app(cfg_files=['DEFAULT']):
    """Factory for making the web Flask application

    :param cfg_files: Single or more config file(s)
    :return: Constructed web application
    :rtype: ``repocribro.repocribro.Repocribro``
    """
    app = Repocribro()
    ext_master = ExtensionsMaster(app=app, db=db)
    app.container.set_singleton('ext_master', ext_master)

    if cfg_files == ['DEFAULT']:
        cfg_files = os.environ.get('REPOCRIBRO_CONFIG_FILE',
                                   DEFAULT_CONFIG_FILES)

    config = create_config(cfg_files)
    config.set('flask', 'release', RELEASE)
    app.container.set_singleton('config', config)
    ext_master.call('setup_config')
    config.update_flask_cfg(app)

    check_config(config)