progress removing onionr.py

This commit is contained in:
Kevin Froman 2019-08-04 19:34:57 -05:00
parent aea32bd1bc
commit 2f9c1de062
5 changed files with 22 additions and 14 deletions

View File

@ -20,7 +20,18 @@
import sys
from etc import onionrvalues
import logger, onionrexceptions
import onionrplugins
import onionrpluginapi
from . import arguments, recommend
def register_plugin_commands(cmd):
cmd = 'on_%s_cmd' % (cmd,)
for pl in onionrplugins.get_enabled_plugins():
pl = onionrplugins.get_plugin(pl)
if hasattr(pl, cmd):
getattr(pl, cmd)(onionrpluginapi.PluginAPI)
return True
def register():
try:
cmd = sys.argv[1]
@ -30,5 +41,6 @@ def register():
try:
arguments.get_func(cmd)()
except onionrexceptions.NotFound:
recommend.recommend()
sys.exit(3)
if not register_plugin_commands(cmd):
recommend.recommend()
sys.exit(3)

View File

@ -10,8 +10,6 @@ def get_arguments():
('stop', 'kill'): daemonlaunch.kill_daemon,
('add-address', 'addaddress', 'addadder'): keyadders.add_address
}
args = events.event('init', data=args, threaded=False)
print(args)
return args
def get_help():

View File

@ -31,7 +31,7 @@ def __event_caller(event_name, data = {}):
'''
for plugin in plugins.get_enabled_plugins():
try:
return call(plugins.get_plugin(plugin), event_name, data, get_pluginapi(data))
call(plugins.get_plugin(plugin), event_name, data, get_pluginapi(data))
except ModuleNotFoundError as e:
logger.warn('Disabling nonexistant plugin "%s"...' % plugin, terminal=True)
plugins.disable(plugin, stop_event = False)
@ -49,7 +49,7 @@ def event(event_name, data = {}, threaded = True):
thread.start()
return thread
else:
return __event_caller(event_name, data)
__event_caller(event_name, data)
def call(plugin, event_name, data = None, pluginapi = None):
'''
@ -59,7 +59,8 @@ def call(plugin, event_name, data = None, pluginapi = None):
if not plugin is None:
try:
attribute = 'on_' + str(event_name).lower()
if pluginapi is None:
pluginapi = get_pluginapi()
if hasattr(plugin, attribute):
return getattr(plugin, attribute)(pluginapi, data)

View File

@ -144,8 +144,7 @@ class WebAPI:
return self.pluginapi.get_onionr().api.getCallbacks(scope = scope)
class SharedAPI:
def __init__(self, onionr, data):
self.onionr = onionr
def __init__(self, data):
self.data = data
self.daemon = DaemonAPI(self)
@ -153,9 +152,6 @@ class SharedAPI:
self.commands = CommandAPI(self)
self.web = WebAPI(self)
def get_onionr(self):
return self.onionr
def get_data(self):
return self.data

View File

@ -96,6 +96,9 @@ class OnionrFlow:
except KeyboardInterrupt:
self.flowRunning = False
def on_flow_cmd(api, data=None):
OnionrFlow().start()
def on_init(api, data = None):
'''
This event is called after Onionr is initialized, but before the command
@ -106,8 +109,6 @@ def on_init(api, data = None):
# by simply referencing the variable `pluginapi`.
global pluginapi
pluginapi = api
flow = OnionrFlow()
return data
def on_processblocks(api, data=None):
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash