def __init__(self, configuration, bot_name="vex"): # get the settings path and then load the settings from file settings_path = configuration.get('settings_path') settings = configuration.load_settings(settings_path) self.messaging = Messaging(settings) # create the plugin manager self.plugin_manager = pluginmanager.PluginInterface() # add the entry points of interest self.plugin_manager.add_entry_points(('vexbot.plugins', 'vexbot.adapters')) # create the subprocess manager and add in the plugins self.subprocess_manager = SubprocessManager() self._update_plugins(settings, self.subprocess_manager, self.plugin_manager) subprocesses_to_start = settings.get('startup_adapters', []) subprocesses_to_start.extend(settings.get('startup_plugins', [])) self.subprocess_manager.start(subprocesses_to_start) self.name = bot_name self._logger = logging.getLogger(__name__) self.command_manager = BotCommandManager(robot=self) try: import setproctitle setproctitle.setproctitle(bot_name) except ImportError: pass
def __init__(self, bot_name: str, connection: dict=None, subprocess_manager=None): if connection is None: connection = _get_default_port_config() self.messaging = _Messaging(bot_name, **connection) log_name = __name__ if __name__ != '__main__' else 'vexbot.robot' self._logger = _logging.getLogger(log_name) if subprocess_manager is None and SubprocessManager: subprocess_manager = SubprocessManager() else: err = ('If you would like to use the subporcess manager, please ' 'run `pip install -e .[process_manager]` from the ' 'directory') self._logger.warn(err) # NOTE: probably need some kind of config here if Language: self.language = Language() else: err = ('If you would like to use natural language processing,' ' please run `pip install -e.[nlp]` from the directory') self._logger.warn(err) self.language = False # self.intents = BotIntents() self.subprocess_manager = subprocess_manager self.command_observer = _CommandObserver(self, self.messaging, self.subprocess_manager, self.language) self.messaging.command.subscribe(self.command_observer) self.messaging.chatter.subscribe(LogObserver(pass_through=True))
def setUp(self): self.subprocess_manager = SubprocessManager()
class TestSubprocessManager(unittest.TestCase): def setUp(self): self.subprocess_manager = SubprocessManager() # register a subprocess? With a name? def test_registered_subprocesses(self): test_obj = object() self.subprocess_manager.register('test', test_obj) registered = self.subprocess_manager.registered_subprocesses() self.assertIn('test', registered) def test_register_with_blacklist(self): blacklisted = 'black' self.subprocess_manager.blacklist.append(blacklisted) self.subprocess_manager.register(blacklisted, None) registered = self.subprocess_manager.registered_subprocesses() self.assertNotIn(blacklisted, registered) def test_update_setting_value(self): self.subprocess_manager.update_settings('test', {'test_value': 'old'}) self.subprocess_manager.update_setting_value('test', 'test_value', 'new') result = self.subprocess_manager.get_settings('test') self.assertEqual(result['test_value'], 'new') self.assertNotEqual(result['test_value'], 'old') def test_update_setting(self): settings = {'setting': 'value'} self.subprocess_manager.update_settings('test', settings) gotten_settings = self.subprocess_manager.get_settings('test') self.assertEqual(settings, gotten_settings)
class Robot: def __init__(self, configuration, bot_name="vex"): # get the settings path and then load the settings from file settings_path = configuration.get('settings_path') settings = configuration.load_settings(settings_path) self.messaging = Messaging(settings) # create the plugin manager self.plugin_manager = pluginmanager.PluginInterface() # add the entry points of interest self.plugin_manager.add_entry_points(('vexbot.plugins', 'vexbot.adapters')) # create the subprocess manager and add in the plugins self.subprocess_manager = SubprocessManager() self._update_plugins(settings, self.subprocess_manager, self.plugin_manager) subprocesses_to_start = settings.get('startup_adapters', []) subprocesses_to_start.extend(settings.get('startup_plugins', [])) self.subprocess_manager.start(subprocesses_to_start) self.name = bot_name self._logger = logging.getLogger(__name__) self.command_manager = BotCommandManager(robot=self) try: import setproctitle setproctitle.setproctitle(bot_name) except ImportError: pass def run(self): while True: frame = self.messaging.subscription_socket.recv_multipart() msg = None try: msg = decode_vex_message(frame) except Exception: pass if msg: # Right now this is hardcoded into being only # the shell adapter # change this to some kind of auth code if ((msg.source == 'shell' or msg.source == 'command_line') and msg.type == 'CMD'): self.command_manager.parse_commands(msg) def _update_plugins(self, settings, subprocess_manager=None, plugin_manager=None): """ Helper process which loads the plugins from the entry points """ if subprocess_manager is None: subprocess_manager = self.subprocess_manager if plugin_manager is None: plugin_manager = self.plugin_manager collect_ep = plugin_manager.collect_entry_point_plugins plugins, plugin_names = collect_ep() plugins = [plugin.__file__ for plugin in plugins] for plugin, name in zip(plugins, plugin_names): subprocess_manager.register(name, sys.executable, {'filepath': plugin}) for name in plugin_names: try: plugin_settings = settings[name] except KeyError: plugin_settings = {} self.subprocess_manager.update_settings(name, plugin_settings)
def __init__(self): self.messaging = Message() self.subprocess_manager = SubprocessManager()
class Robot: def __init__(self, configuration, bot_name="vex"): # get the settings path and then load the settings from file settings_path = configuration.get('settings_path') settings = configuration.load_settings(settings_path) self.messaging = Messaging(settings) # create the plugin manager self.plugin_manager = pluginmanager.PluginInterface() # add the entry points of interest self.plugin_manager.add_entry_points( ('vexbot.plugins', 'vexbot.adapters')) # create the subprocess manager and add in the plugins self.subprocess_manager = SubprocessManager() self._update_plugins(settings, self.subprocess_manager, self.plugin_manager) subprocesses_to_start = settings.get('startup_adapters', []) subprocesses_to_start.extend(settings.get('startup_plugins', [])) self.subprocess_manager.start(subprocesses_to_start) self.name = bot_name self._logger = logging.getLogger(__name__) self.command_manager = BotCommandManager(robot=self) try: import setproctitle setproctitle.setproctitle(bot_name) except ImportError: pass def run(self): while True: frame = self.messaging.subscription_socket.recv_multipart() msg = None try: msg = decode_vex_message(frame) except Exception: pass if msg: # Right now this is hardcoded into being only # the shell adapter # change this to some kind of auth code if ((msg.source == 'shell' or msg.source == 'command_line') and msg.type == 'CMD'): self.command_manager.parse_commands(msg) def _update_plugins(self, settings, subprocess_manager=None, plugin_manager=None): """ Helper process which loads the plugins from the entry points """ if subprocess_manager is None: subprocess_manager = self.subprocess_manager if plugin_manager is None: plugin_manager = self.plugin_manager collect_ep = plugin_manager.collect_entry_point_plugins plugins, plugin_names = collect_ep() plugins = [plugin.__file__ for plugin in plugins] for plugin, name in zip(plugins, plugin_names): subprocess_manager.register(name, sys.executable, {'filepath': plugin}) for name in plugin_names: try: plugin_settings = settings[name] except KeyError: plugin_settings = {} self.subprocess_manager.update_settings(name, plugin_settings)