progress removing onionr.py
This commit is contained in:
parent
aea32bd1bc
commit
2f9c1de062
@ -20,7 +20,18 @@
|
|||||||
import sys
|
import sys
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
import logger, onionrexceptions
|
import logger, onionrexceptions
|
||||||
|
import onionrplugins
|
||||||
|
import onionrpluginapi
|
||||||
from . import arguments, recommend
|
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():
|
def register():
|
||||||
try:
|
try:
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
@ -30,5 +41,6 @@ def register():
|
|||||||
try:
|
try:
|
||||||
arguments.get_func(cmd)()
|
arguments.get_func(cmd)()
|
||||||
except onionrexceptions.NotFound:
|
except onionrexceptions.NotFound:
|
||||||
recommend.recommend()
|
if not register_plugin_commands(cmd):
|
||||||
sys.exit(3)
|
recommend.recommend()
|
||||||
|
sys.exit(3)
|
@ -10,8 +10,6 @@ def get_arguments():
|
|||||||
('stop', 'kill'): daemonlaunch.kill_daemon,
|
('stop', 'kill'): daemonlaunch.kill_daemon,
|
||||||
('add-address', 'addaddress', 'addadder'): keyadders.add_address
|
('add-address', 'addaddress', 'addadder'): keyadders.add_address
|
||||||
}
|
}
|
||||||
args = events.event('init', data=args, threaded=False)
|
|
||||||
print(args)
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def get_help():
|
def get_help():
|
||||||
|
@ -31,7 +31,7 @@ def __event_caller(event_name, data = {}):
|
|||||||
'''
|
'''
|
||||||
for plugin in plugins.get_enabled_plugins():
|
for plugin in plugins.get_enabled_plugins():
|
||||||
try:
|
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:
|
except ModuleNotFoundError as e:
|
||||||
logger.warn('Disabling nonexistant plugin "%s"...' % plugin, terminal=True)
|
logger.warn('Disabling nonexistant plugin "%s"...' % plugin, terminal=True)
|
||||||
plugins.disable(plugin, stop_event = False)
|
plugins.disable(plugin, stop_event = False)
|
||||||
@ -49,7 +49,7 @@ def event(event_name, data = {}, threaded = True):
|
|||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
else:
|
else:
|
||||||
return __event_caller(event_name, data)
|
__event_caller(event_name, data)
|
||||||
|
|
||||||
def call(plugin, event_name, data = None, pluginapi = None):
|
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:
|
if not plugin is None:
|
||||||
try:
|
try:
|
||||||
attribute = 'on_' + str(event_name).lower()
|
attribute = 'on_' + str(event_name).lower()
|
||||||
|
if pluginapi is None:
|
||||||
|
pluginapi = get_pluginapi()
|
||||||
if hasattr(plugin, attribute):
|
if hasattr(plugin, attribute):
|
||||||
return getattr(plugin, attribute)(pluginapi, data)
|
return getattr(plugin, attribute)(pluginapi, data)
|
||||||
|
|
||||||
|
@ -144,8 +144,7 @@ class WebAPI:
|
|||||||
return self.pluginapi.get_onionr().api.getCallbacks(scope = scope)
|
return self.pluginapi.get_onionr().api.getCallbacks(scope = scope)
|
||||||
|
|
||||||
class SharedAPI:
|
class SharedAPI:
|
||||||
def __init__(self, onionr, data):
|
def __init__(self, data):
|
||||||
self.onionr = onionr
|
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
self.daemon = DaemonAPI(self)
|
self.daemon = DaemonAPI(self)
|
||||||
@ -153,9 +152,6 @@ class SharedAPI:
|
|||||||
self.commands = CommandAPI(self)
|
self.commands = CommandAPI(self)
|
||||||
self.web = WebAPI(self)
|
self.web = WebAPI(self)
|
||||||
|
|
||||||
def get_onionr(self):
|
|
||||||
return self.onionr
|
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
|
@ -96,6 +96,9 @@ class OnionrFlow:
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.flowRunning = False
|
self.flowRunning = False
|
||||||
|
|
||||||
|
def on_flow_cmd(api, data=None):
|
||||||
|
OnionrFlow().start()
|
||||||
|
|
||||||
def on_init(api, data = None):
|
def on_init(api, data = None):
|
||||||
'''
|
'''
|
||||||
This event is called after Onionr is initialized, but before the command
|
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`.
|
# by simply referencing the variable `pluginapi`.
|
||||||
global pluginapi
|
global pluginapi
|
||||||
pluginapi = api
|
pluginapi = api
|
||||||
flow = OnionrFlow()
|
|
||||||
return data
|
|
||||||
|
|
||||||
def on_processblocks(api, data=None):
|
def on_processblocks(api, data=None):
|
||||||
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
|
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
|
||||||
|
Loading…
Reference in New Issue
Block a user