mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-23 14:10:18 +00:00
Implemented custom interface loading
This commit is contained in:
parent
4223203134
commit
4a4b625075
@ -148,6 +148,7 @@ class Reticulum:
|
|||||||
configpath = ""
|
configpath = ""
|
||||||
storagepath = ""
|
storagepath = ""
|
||||||
cachepath = ""
|
cachepath = ""
|
||||||
|
interfacepath = ""
|
||||||
|
|
||||||
__instance = None
|
__instance = None
|
||||||
|
|
||||||
@ -218,6 +219,7 @@ class Reticulum:
|
|||||||
Reticulum.cachepath = Reticulum.configdir+"/storage/cache"
|
Reticulum.cachepath = Reticulum.configdir+"/storage/cache"
|
||||||
Reticulum.resourcepath = Reticulum.configdir+"/storage/resources"
|
Reticulum.resourcepath = Reticulum.configdir+"/storage/resources"
|
||||||
Reticulum.identitypath = Reticulum.configdir+"/storage/identities"
|
Reticulum.identitypath = Reticulum.configdir+"/storage/identities"
|
||||||
|
Reticulum.interfacepath = Reticulum.configdir+"/interfaces"
|
||||||
|
|
||||||
Reticulum.__transport_enabled = False
|
Reticulum.__transport_enabled = False
|
||||||
Reticulum.__remote_management_enabled = False
|
Reticulum.__remote_management_enabled = False
|
||||||
@ -263,6 +265,9 @@ class Reticulum:
|
|||||||
if not os.path.isdir(Reticulum.identitypath):
|
if not os.path.isdir(Reticulum.identitypath):
|
||||||
os.makedirs(Reticulum.identitypath)
|
os.makedirs(Reticulum.identitypath)
|
||||||
|
|
||||||
|
if not os.path.isdir(Reticulum.interfacepath):
|
||||||
|
os.makedirs(Reticulum.interfacepath)
|
||||||
|
|
||||||
if os.path.isfile(self.configpath):
|
if os.path.isfile(self.configpath):
|
||||||
try:
|
try:
|
||||||
self.config = ConfigObj(self.configpath)
|
self.config = ConfigObj(self.configpath)
|
||||||
@ -671,6 +676,34 @@ class Reticulum:
|
|||||||
interface_post_init(interface)
|
interface_post_init(interface)
|
||||||
interface.start()
|
interface.start()
|
||||||
|
|
||||||
|
if interface == None:
|
||||||
|
# Interface was not handled by any internal interface types,
|
||||||
|
# attempt to load and initialise it from user-supplied modules
|
||||||
|
interface_type = c["type"]
|
||||||
|
interface_file = f"{interface_type}.py"
|
||||||
|
interface_path = os.path.join(self.interfacepath, interface_file)
|
||||||
|
if not os.path.isfile(interface_path):
|
||||||
|
RNS.log(f"Could not locate external interface module \"{interface_file}\" in \"{self.interfacepath}\"", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
RNS.log(f"Loading external interface \"{interface_file}\" from \"{self.interfacepath}\"", RNS.LOG_NOTICE)
|
||||||
|
interface_globals = {}
|
||||||
|
interface_globals["Interface"] = Interface.Interface
|
||||||
|
interface_globals["RNS"] = RNS
|
||||||
|
with open(interface_path) as class_file:
|
||||||
|
interface_code = class_file.read()
|
||||||
|
exec(interface_code, interface_globals)
|
||||||
|
interface_class = interface_globals["interface_class"]
|
||||||
|
|
||||||
|
if interface_class != None:
|
||||||
|
interface = interface_class(RNS.Transport, interface_config)
|
||||||
|
interface_post_init(interface)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"External interface initialisation failed for {interface_type} / {name}", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
RNS.log("Skipping disabled interface \""+name+"\"", RNS.LOG_DEBUG)
|
RNS.log("Skipping disabled interface \""+name+"\"", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user