From 196d02a75125273e90a75f50e133195cb32769e7 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 10 Sep 2020 21:44:30 +0000 Subject: [PATCH] Sped up + fixed statistics table command using psutil, removed checkcommunicator as a result --- src/filepaths/__init__.py | 2 -- src/onionrcommands/daemonlaunch/__init__.py | 5 --- src/onionrcommands/onionrstatistics.py | 24 +++++++++---- src/onionrutils/checkcommunicator.py | 39 --------------------- 4 files changed, 17 insertions(+), 53 deletions(-) delete mode 100644 src/onionrutils/checkcommunicator.py diff --git a/src/filepaths/__init__.py b/src/filepaths/__init__.py index a929518d..ba205383 100644 --- a/src/filepaths/__init__.py +++ b/src/filepaths/__init__.py @@ -25,8 +25,6 @@ site_cache = home + 'onionr-sites.txt' tor_hs_loc = home + 'hs/' tor_hs_address_file = home + 'hs/hostname' -run_check_file = home + '.runcheck' - data_nonce_file = home + 'block-nonces.dat' keys_file = home + 'keys.txt' diff --git a/src/onionrcommands/daemonlaunch/__init__.py b/src/onionrcommands/daemonlaunch/__init__.py index c3b5a89d..383f57d2 100755 --- a/src/onionrcommands/daemonlaunch/__init__.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -134,11 +134,6 @@ def daemon(): logger.error("Tor is not present in system path or Onionr directory", terminal=True) - # remove runcheck if it exists - if os.path.isfile(filepaths.run_check_file): - logger.debug('Runcheck file found on daemon start, deleting.') - os.remove(filepaths.run_check_file) - # Create shared objects shared_state = toomanyobjs.TooMany() diff --git a/src/onionrcommands/onionrstatistics.py b/src/onionrcommands/onionrstatistics.py index af9afbce..78ad638d 100755 --- a/src/onionrcommands/onionrstatistics.py +++ b/src/onionrcommands/onionrstatistics.py @@ -4,17 +4,16 @@ This module defines commands to show stats/details about the local node """ import os import logger -from onionrblocks import onionrblockapi from onionrblocks import onionrblacklist -from onionrutils import checkcommunicator, mnemonickeys +from onionrutils import mnemonickeys from utils import sizeutils, gethostname, getconsolewidth, identifyhome from coredb import blockmetadb, keydb import onionrcrypto import config from etc import onionrvalues +from filepaths import lock_file -check_communicator = checkcommunicator.is_communicator_running - +import psutil """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +30,15 @@ check_communicator = checkcommunicator.is_communicator_running """ +def _is_running(): + script = onionrvalues.SCRIPT_NAME + if os.path.isfile(lock_file): + for process in psutil.process_iter(): + if process.name() == script: + return True + return False + + def show_stats(): """Print/log statistic info about our Onionr install.""" try: @@ -41,10 +49,12 @@ def show_stats(): messages = { # info about local client + + # This line is inaccurate if dev mode is enabled 'Onionr Daemon Status': - ((logger.colors.fg.green + 'Online') - if check_communicator(timeout=9) - else logger.colors.fg.red + 'Offline'), + ((logger.colors.fg.green + 'Online') \ + if _is_running() \ + else logger.colors.fg.red + 'Offline'), # file and folder size stats 'div1': True, # this creates a solid line across the screen, a div diff --git a/src/onionrutils/checkcommunicator.py b/src/onionrutils/checkcommunicator.py deleted file mode 100644 index 7fc69904..00000000 --- a/src/onionrutils/checkcommunicator.py +++ /dev/null @@ -1,39 +0,0 @@ -''' - Onionr - Private P2P Communication - - Check if the communicator is running -''' -''' - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -''' -import time, os -import filepaths -def is_communicator_running(timeout = 5, interval = 0.1): - try: - runcheck_file = filepaths.run_check_file - - if not os.path.isfile(runcheck_file): - open(runcheck_file, 'w+').close() - - starttime = time.time() - - while True: - time.sleep(interval) - - if not os.path.isfile(runcheck_file): - return True - elif time.time() - starttime >= timeout: - return False - except: - return False