# Path: kotori/util/configuration.py
# def read_list(string, separator=u',', empty_elements=True):
#     data = list(map(str.strip, string.split(separator)))
#     if empty_elements == False:
#         data = [x for x in data if bool(x)]
#     return data
# 
# Path: kotori/util/errors.py
# def last_error_and_traceback():
#     error_entry = traceback_get_exception(0)
#     error_last = traceback_get_exception(-1)
#     sep = '-' * 60
#     payload_location = "\n".join([sep, format_exception_location(error_entry, "Entry point:"), sep, format_exception_location(error_last, "Source of exception:")])
#     payload = ''.join(["ERROR: ", error_entry['message'], "\n", payload_location, "\n"])
# 
#     # add full traceback
#     buffer = StringIO()
#     traceback.print_exc(file=buffer)
#     buffer.seek(0)
#     payload += '\n' + buffer.read()
# 
#     return payload
# 
# Path: kotori/util/logger.py
# def changeLogLevel(namespace, loglevel=LogLevel.info):
#     predicate.setLogLevelForNamespace(namespace, loglevel)
# 
# Path: kotori/version.py
# __VERSION__ = '0.26.12'


from pkg_resources import EntryPoint
from pyramid.settings import asbool
from twisted.logger import Logger, LogLevel
from kotori.util.configuration import read_list
from kotori.util.errors import last_error_and_traceback
from kotori.util.logger import changeLogLevel
from kotori.version import __VERSION__
        from kotori.vendor.hydro2motion.database.influx import h2m_boot_influx_database
        from kotori.vendor.hydro2motion.network.udp import h2m_boot_udp_adapter
        from kotori.vendor.hydro2motion.web.server import boot_web
        from kotori.vendor.hiveeyes.application import hiveeyes_boot
        from kotori.vendor.lst.application import lst_boot

        if not factory:
            return

        try:
            application_settings = self.settings[name]
            application = factory(name=name, application_settings=application_settings, global_settings=self.settings)
            application.startService()
            return application
        except Exception as ex:
            log.failure('Error running application factory "{name}":\n{log_failure}', name=name)
            return

    def get_application_factory(self, name):

        # Get application information from configuration object
        try:
            application_settings = self.settings[name]
            app_factory = \
                'app_factory' in application_settings and \
                application_settings.app_factory or \
                application_settings.application
        except:
            log.failure('Application configuration object for "{name}" not found, missing setting "app_factory"', name=name)
            return

        try:
            factory_callable = self.load_entrypoint(app_factory)
        except:
            log.failure('Error loading application entrypoint "{app_factory}" for "{name}":\n{ex}',

# Path: kotori/util/configuration.py
# def read_list(string, separator=u',', empty_elements=True):
#     data = list(map(str.strip, string.split(separator)))
#     if empty_elements == False:
#         data = [x for x in data if bool(x)]
#     return data
# 
# Path: kotori/util/errors.py
# def last_error_and_traceback():
#     error_entry = traceback_get_exception(0)
#     error_last = traceback_get_exception(-1)
#     sep = '-' * 60
#     payload_location = "\n".join([sep, format_exception_location(error_entry, "Entry point:"), sep, format_exception_location(error_last, "Source of exception:")])
#     payload = ''.join(["ERROR: ", error_entry['message'], "\n", payload_location, "\n"])
# 
#     # add full traceback
#     buffer = StringIO()
#     traceback.print_exc(file=buffer)
#     buffer.seek(0)
#     payload += '\n' + buffer.read()
# 
#     return payload
# 
# Path: kotori/util/logger.py
# def changeLogLevel(namespace, loglevel=LogLevel.info):
#     predicate.setLogLevelForNamespace(namespace, loglevel)
# 
# Path: kotori/version.py
# __VERSION__ = '0.26.12'


# Path: kotori/core.py
from pkg_resources import EntryPoint
from pyramid.settings import asbool
from twisted.logger import Logger, LogLevel
from kotori.util.configuration import read_list
from kotori.util.errors import last_error_and_traceback
from kotori.util.logger import changeLogLevel
from kotori.version import __VERSION__
        from kotori.vendor.hydro2motion.database.influx import h2m_boot_influx_database
        from kotori.vendor.hydro2motion.network.udp import h2m_boot_udp_adapter
        from kotori.vendor.hydro2motion.web.server import boot_web
        from kotori.vendor.hiveeyes.application import hiveeyes_boot
        from kotori.vendor.lst.application import lst_boot


        if not factory:
            return

        try:
            application_settings = self.settings[name]
            application = factory(name=name, application_settings=application_settings, global_settings=self.settings)
            application.startService()
            return application
        except Exception as ex:
            log.failure('Error running application factory "{name}":\n{log_failure}', name=name)
            return

    def get_application_factory(self, name):

        # Get application information from configuration object
        try:
            application_settings = self.settings[name]
            app_factory = \
                'app_factory' in application_settings and \
                application_settings.app_factory or \
                application_settings.application
        except:
            log.failure('Application configuration object for "{name}" not found, missing setting "app_factory"', name=name)
            return

        try:
            factory_callable = self.load_entrypoint(app_factory)
        except:
            log.failure('Error loading application entrypoint "{app_factory}" for "{name}":\n{ex}',

                name=name, app_factory=app_factory, ex=last_error_and_traceback())