Esempio n. 1
0
def init_cliapp(app, cliconf):
    app.commands.update(load_handlers(app, 'Command', path=os.path.join(module_path, 'commands')))

    xpl = app.commands['Explore']
    ins = app.commands['Insert']
    xpl.explorers = load_handlers(conf['bulk_db'], 'Explorer', path=os.path.join(module_path, 'explorers'))
    ins.inserters = xpl.explorers
Esempio n. 2
0
File: cli.py Progetto: JobTK/eme
    def run_tasks(self, tasks=None):
        # todo: use absolute path!
        handler_tasks = load_handlers(self, 'Task')

        # Logging
        logger = logging.getLogger('geosch')
        logger.setLevel(logging.DEBUG)

        # file log
        fh = logging.FileHandler(self.conf.get('logfile', 'logs.txt'))
        lvl = self.conf.get('loglevel', 'WARNING')
        fh.setLevel(getattr(logging, lvl))

        # console log
        ch = logging.StreamHandler()
        ch.setLevel(logging.ERROR)

        formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
        ch.setFormatter(formatter)
        fh.setFormatter(formatter)

        logger.addHandler(ch)
        logger.addHandler(fh)

        self.logger = logger
        self.debug_log = self.conf.get('scheduler.log_deep', False)

        if tasks is None:
            # all tasks
            tasks = handler_tasks.keys()

        for name in tasks:
            handler_tasks[name].run()
Esempio n. 3
0
File: cli.py Progetto: oboforty/eme
    def __init__(self, conf, fbase='cliapp/'):
        # if len(config) == 0:
        #     raise Exception("Empty config file provided")
        self.conf = conf

        self.prefix = "$eme~:"
        sys.path.append(fbase)

        #cmdir = self.conf.get('cli.commands_dir', default='commands')
        self.commands = load_handlers(self, 'Command', path=fbase+'/commands')
Esempio n. 4
0
    def __init__(self):
        # eme/examples/simple_website is the working directory.
        script_path = dirname(realpath(__file__))
        conf = load_settings(join(script_path, 'config.ini'))

        super().__init__(conf, script_path)

        self.load_controllers(load_handlers(self,
                                            'Api',
                                            module_path='api',
                                            path=join(script_path, 'api')),
                              conf=conf.get('routing', {}))

        # Initialize database & modules
        assert ctx.get_session() != None
        self.init_modules(modules, conf)
Esempio n. 5
0
    def __init__(self, config: dict, fbase='wsapp'):
        if len(config) == 0:
            raise Exception("Empty config file provided")
        conf = config['websocket']
        sys.path.append(fbase)

        self.host = conf.get('host', '0.0.0.0')
        self.port = conf.get('port')

        self.debug = conf.get('debug')

        # ws handler
        signal.signal(signal.SIGINT, self.close_sig_handler)
        self.clients = {}
        self.func_params = {}
        self.groups = load_handlers(self,
                                    "Group",
                                    conf.get('groups_dir'),
                                    prefix_path=fbase)

        # Logging
        logger = logging.getLogger(conf.get('logprefix', 'eme'))
        logger.setLevel(logging.DEBUG)

        # file log
        fh = logging.FileHandler(conf.get('logfile', join(fbase, 'logs.txt')))
        lvl = conf.get('loglevel', 'WARNING')
        fh.setLevel(getattr(logging, lvl))

        # console log
        ch = logging.StreamHandler()
        ch.setLevel(logging.ERROR)

        formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
        ch.setFormatter(formatter)
        fh.setFormatter(formatter)

        logger.addHandler(ch)
        logger.addHandler(fh)

        self.logger = logger
Esempio n. 6
0
    def __init__(self, config: dict, path='wsapp'):
        if len(config) == 0:
            raise Exception("Empty config file provided")
        conf = config['websocket']
        sys.path.append(path)

        # Socket
        self.host = conf.get('host', '0.0.0.0')
        self.port = conf.get('port', 3000)

        # Flags
        self.debug = conf.get('debug')

        # ws handler
        self.url_map = {}
        self.load_groups(
            load_handlers(self, 'Group', path=join(path, 'groups')), conf)

        signal.signal(signal.SIGINT, self.close_sig_handler)

        if conf.get('rooms'):
            self.rooms = defaultdict(set)
        else:
            self.rooms = None
Esempio n. 7
0
def init_cliapp(app, conf):
    app.commands.update(load_handlers(app, 'Command', path=os.path.join(module_path, 'commands')))
Esempio n. 8
0
from unittest.mock import MagicMock, patch

import flask
from eme.entities import load_handlers, EntityPatch
from flask import request

from modules.eme_utils.responses import ApiResponse

obj_webapp = MagicMock()
controllers = load_handlers(obj_webapp, "Controller", "webapp/")

obj_serverapp = MagicMock()
groups = load_handlers(obj_serverapp, "Group", "serverapp/")


def mock_http(controller_action, form_data=None, **kwargs):
    controller, action = controller_action.split(':')
    print("  >{}:{} {}".format(controller, action, kwargs))

    if form_data:
        request_mock = patch.object(flask, "request")

        with patch('request.form') as mock:
            mock.return_value = form_data

    resp = getattr(controllers[controller], action)(**kwargs)

    if resp:
        if isinstance(resp, ApiResponse):
            return resp.json