mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-02-22 08:00:00 -05:00
Added daemon mode
This commit is contained in:
parent
34b377bafe
commit
c6e26e7f7f
@ -66,7 +66,8 @@ class Conversation:
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
Conversation.created_callback()
|
||||
if Conversation.created_callback != None:
|
||||
Conversation.created_callback()
|
||||
|
||||
return ingested_path
|
||||
|
||||
|
@ -86,7 +86,9 @@ class Directory:
|
||||
self.announce_stream.insert(0, (timestamp, source_hash, app_data, False))
|
||||
while len(self.announce_stream) > Directory.ANNOUNCE_STREAM_MAXLENGTH:
|
||||
self.announce_stream.pop()
|
||||
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
||||
|
||||
if hasattr(self.app.ui, "main_display"):
|
||||
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
||||
|
||||
def node_announce_received(self, source_hash, app_data, associated_peer):
|
||||
if app_data != None:
|
||||
@ -101,7 +103,8 @@ class Directory:
|
||||
node_entry = DirectoryEntry(source_hash, display_name=app_data.decode("utf-8"), trust_level=DirectoryEntry.TRUSTED, hosts_node=True)
|
||||
self.remember(node_entry)
|
||||
|
||||
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
||||
if hasattr(self.app.ui, "main_display"):
|
||||
self.app.ui.main_display.sub_displays.network_display.directory_change_callback()
|
||||
|
||||
def remove_announce_with_timestamp(self, timestamp):
|
||||
selected_announce = None
|
||||
|
@ -46,7 +46,7 @@ class NomadNetworkApp:
|
||||
if issubclass(e_type, KeyboardInterrupt):
|
||||
sys.__excepthook__(e_type, e_value, e_traceback)
|
||||
|
||||
def __init__(self, configdir = None, rnsconfigdir = None):
|
||||
def __init__(self, configdir = None, rnsconfigdir = None, daemon = False):
|
||||
self.version = __version__
|
||||
self.enable_client = False
|
||||
self.enable_node = False
|
||||
@ -239,6 +239,10 @@ class NomadNetworkApp:
|
||||
job_thread.setDaemon(True)
|
||||
job_thread.start()
|
||||
|
||||
# Override UI choice from config on --daemon switch
|
||||
if daemon:
|
||||
self.uimode = nomadnet.ui.UI_NONE
|
||||
|
||||
# This stderr redirect is needed to stop urwid
|
||||
# from spewing KeyErrors to the console and thus,
|
||||
# messing up the UI. A pull request to fix the
|
||||
|
@ -1 +1 @@
|
||||
__version__ = "0.1.7"
|
||||
__version__ = "0.1.8"
|
||||
|
@ -7,14 +7,15 @@ import argparse
|
||||
import nomadnet
|
||||
|
||||
|
||||
def program_setup(configdir, rnsconfigdir):
|
||||
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir)
|
||||
def program_setup(configdir, rnsconfigdir, daemon):
|
||||
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir, daemon = daemon)
|
||||
|
||||
def main():
|
||||
try:
|
||||
parser = argparse.ArgumentParser(description="Nomad Network Client")
|
||||
parser.add_argument("--config", action="store", default=None, help="path to alternative Nomad Network config directory", type=str)
|
||||
parser.add_argument("--rnsconfig", action="store", default=None, help="path to alternative Reticulum config directory", type=str)
|
||||
parser.add_argument("-d", "--daemon", action="store_true", default=False, help="run Nomad Network in daemon mode")
|
||||
parser.add_argument("--version", action="version", version="Nomad Network Client {version}".format(version=__version__))
|
||||
|
||||
args = parser.parse_args()
|
||||
@ -29,7 +30,7 @@ def main():
|
||||
else:
|
||||
rnsconfigarg = None
|
||||
|
||||
program_setup(configarg, rnsconfigarg)
|
||||
program_setup(configarg, rnsconfigarg, args.daemon)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
|
@ -4,5 +4,5 @@ import nomadnet
|
||||
class MenuUI:
|
||||
|
||||
def __init__(self):
|
||||
RNS.log("Menu UI not implemented", RNS.LOG_ERROR)
|
||||
RNS.log("Menu UI not implemented", RNS.LOG_ERROR, _override_destination=True)
|
||||
nomadnet.panic()
|
16
nomadnet/ui/NoneUI.py
Normal file
16
nomadnet/ui/NoneUI.py
Normal file
@ -0,0 +1,16 @@
|
||||
import RNS
|
||||
import nomadnet
|
||||
import time
|
||||
|
||||
from nomadnet import NomadNetworkApp
|
||||
|
||||
class NoneUI:
|
||||
|
||||
def __init__(self):
|
||||
self.app = NomadNetworkApp.get_shared_instance()
|
||||
self.app.ui = self
|
||||
|
||||
RNS.log("Nomad Network started in daemon mode, all further messages are logged to "+str(self.app.logfilepath), RNS.LOG_INFO, _override_destination=True)
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
@ -12,11 +12,15 @@ UI_MENU = 0x01
|
||||
UI_TEXT = 0x02
|
||||
UI_GRAPHICAL = 0x03
|
||||
UI_WEB = 0x04
|
||||
UI_MODES = [UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
|
||||
UI_MODES = [UI_NONE, UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
|
||||
|
||||
def spawn(uimode):
|
||||
if uimode in UI_MODES:
|
||||
RNS.log("Starting user interface...", RNS.LOG_INFO)
|
||||
if uimode == UI_NONE:
|
||||
RNS.log("Starting Nomad Network daemon...", RNS.LOG_INFO)
|
||||
else:
|
||||
RNS.log("Starting user interface...", RNS.LOG_INFO)
|
||||
|
||||
if uimode == UI_MENU:
|
||||
from .MenuUI import MenuUI
|
||||
return MenuUI()
|
||||
@ -29,8 +33,11 @@ def spawn(uimode):
|
||||
elif uimode == UI_WEB:
|
||||
from .WebUI import WebUI
|
||||
return WebUI()
|
||||
elif uimode == UI_NONE:
|
||||
from .NoneUI import NoneUI
|
||||
return NoneUI()
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
RNS.log("Invalid UI mode", RNS.LOG_ERROR)
|
||||
RNS.log("Invalid UI mode", RNS.LOG_ERROR, _override_destination=True)
|
||||
nomadnet.panic()
|
@ -563,7 +563,7 @@ class KnownNodes(urwid.WidgetWrap):
|
||||
self.pile = urwid.Pile([urwid.Text(("warning_text", g["info"]+"\n"), align="center"), SelectText(("warning_text", "Currently, no nodes are known\n\n"), align="center")])
|
||||
self.display_widget = urwid.Filler(self.pile, valign="top", height="pack")
|
||||
|
||||
urwid.WidgetWrap.__init__(self, urwid.AttrMap(urwid.LineBox(self.display_widget, title="Known Nodes"), widget_style))
|
||||
urwid.WidgetWrap.__init__(self, urwid.AttrMap(urwid.LineBox(self.display_widget, title="Saved Nodes"), widget_style))
|
||||
|
||||
def keypress(self, size, key):
|
||||
if key == "up" and (self.no_content or self.ilb.first_item_is_selected()):
|
||||
|
Loading…
x
Reference in New Issue
Block a user