From c7e0b6c1b2e2a6f16dfe79407bf2da8f900d2545 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 13 Sep 2020 03:26:02 +0000 Subject: [PATCH] Removed batch files, added WIP run wrapper script --- run-onionr-node.py | 75 +++++++++++++++++++++++++++++++++++++++++++++ run-windows-dev.bat | 7 ----- run-windows.bat | 4 --- 3 files changed, 75 insertions(+), 11 deletions(-) create mode 100755 run-onionr-node.py delete mode 100755 run-windows-dev.bat delete mode 100755 run-windows.bat diff --git a/run-onionr-node.py b/run-onionr-node.py new file mode 100755 index 00000000..b08550db --- /dev/null +++ b/run-onionr-node.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +import argparse +import os +from threading import Thread +from time import sleep +from subprocess import PIPE + +import ujson +from psutil import Popen +from psutil import Process +import psutil + +import sys + +script_dir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(script_dir + '/src/') + +from etc import onionrvalues + + +sub_script = script_dir + '/' + onionrvalues.SCRIPT_NAME + +def show_info(p: Process): + while True: + threads = p.num_threads() + open_files = len(p.open_files()) + for proc in p.children(recursive=True): + threads += proc.num_threads() + try: + open_files += len(proc.open_files()) + except psutil.AccessDenied: + pass + print(f'Approximate thread count: {threads}') + print(f'Approximate open files: {open_files}') + sleep(1) + + +parser = argparse.ArgumentParser() + +parser.add_argument( + "--skip-onboarding", help="Skip Onionr onboarding", + type=bool, default=False) +parser.add_argument( + '--open-ui', help='Open onionr web ui after started' , + type=bool, default=True) +args = parser.parse_args() + +p = Popen([sub_script, 'version']) +p.wait() +from filepaths import config_file + + + +with open(config_file, 'r') as cf: + config = ujson.loads(cf.read()) + +if args.skip_onboarding: + config['onboarding']['done'] = True + print('Disabling onboarding') + + +with open(config_file, 'w') as cf: + cf.write(ujson.dumps(config)) + +if args.open_ui: + p = Popen([sub_script, 'start']) + sleep(2) + Popen([sub_script, 'openhome']) +else: + p = Popen([sub_script, 'start'], stdout=PIPE) + +p = p.children()[0] +Thread(target=show_info, args=[p], daemon=True).start() +p.wait() diff --git a/run-windows-dev.bat b/run-windows-dev.bat deleted file mode 100755 index eeed5e9c..00000000 --- a/run-windows-dev.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off -echo This script is only intended for use in Onionr development, as it uses a random profile. -set ONIONR_HOME=data%random% -echo Using profile: %ONIONR_HOME% -setlocal -chdir src -python __init__.py %* diff --git a/run-windows.bat b/run-windows.bat deleted file mode 100755 index 71afd897..00000000 --- a/run-windows.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -setlocal -chdir src -python __init__.py %*