def testPluginEvent(self): logger.debug('-' * 26 + '\n') logger.info('Running plugin event test...') import onionrplugins as plugins, onionrevents as events, os if not plugins.exists('test'): os.makedirs(plugins.get_plugins_folder('test')) with open(plugins.get_plugins_folder('test') + '/main.py', 'a') as main: main.write( "print('Running')\n\ndef on_test(pluginapi, data = None):\n print('received test event!')\n print('thread test started...')\n import time\n time.sleep(1)\n \n return True\n\ndef on_start(pluginapi, data = None):\n print('start event called')\n\ndef on_stop(pluginapi, data = None):\n print('stop event called')\n\ndef on_enable(pluginapi, data = None):\n print('enable event called')\n\ndef on_disable(pluginapi, data = None):\n print('disable event called')\n" ) plugins.enable('test') plugins.start('test') if not events.call(plugins.get_plugin('test'), 'enable'): self.assertTrue(False) logger.debug('preparing to start thread', timestamp=False) thread = events.event('test', data={'tests': self}) logger.debug('thread running...', timestamp=False) thread.join() logger.debug('thread finished.', timestamp=False) self.assertTrue(True)
def testPluginStopStart(self): logger.debug('-'*26 + '\n') logger.info('Running simple plugin restart test...') import onionrplugins try: onionrplugins.start('test') onionrplugins.stop('test') self.assertTrue(True) except: self.assertTrue(False)
def reload_plugin(o_inst): ''' Reloads (stops and starts) all plugins, or the given plugin ''' if len(sys.argv) >= 3: plugin_name = sys.argv[2] logger.info('Reloading plugin "%s"...' % plugin_name) plugins.stop(plugin_name, o_inst) plugins.start(plugin_name, o_inst) else: logger.info('Reloading all plugins...') plugins.reload(o_inst)
def testPluginEvent(self): logger.debug('-'*26 + '\n') logger.info('Running plugin event test...') import onionrplugins as plugins, onionrevents as events plugins.start('test') if not events.call(plugins.get_plugin('test'), 'test'): self.assertTrue(False) events.event('test', data = {'tests': self}) self.assertTrue(True)
def reloadPlugin(self): ''' Reloads (stops and starts) all plugins, or the given plugin ''' if len(sys.argv) >= 3: plugin_name = sys.argv[2] logger.info('Reloading plugin \"' + plugin_name + '\"...') plugins.stop(plugin_name) plugins.start(plugin_name) else: logger.info('Reloading all plugins...') plugins.reload() return
def testPluginStopStart(self): logger.debug('-' * 26 + '\n') logger.info('Running simple plugin restart test...') import onionrplugins, os if not onionrplugins.exists('test'): os.makedirs(onionrplugins.get_plugins_folder('test')) with open( onionrplugins.get_plugins_folder('test') + '/main.py', 'a') as main: main.write( "print('Running')\n\ndef on_test(pluginapi, data = None):\n print('received test event!')\n return True\n\ndef on_start(pluginapi, data = None):\n print('start event called')\n\ndef on_stop(pluginapi, data = None):\n print('stop event called')\n\ndef on_enable(pluginapi, data = None):\n print('enable event called')\n\ndef on_disable(pluginapi, data = None):\n print('disable event called')\n" ) onionrplugins.enable('test') try: onionrplugins.start('test') onionrplugins.stop('test') self.assertTrue(True) except: self.assertTrue(False)
def start(self, name): onionrplugins.start(name)