More python2/3 string handling

This commit is contained in:
Taylor Helsper 2022-01-30 13:58:00 -06:00
parent 2c1cddb1e3
commit bac5fe1f1e
12 changed files with 41 additions and 43 deletions

View File

@ -259,7 +259,7 @@ def get_application_status_special(short_name):
return "Waiting for initialization..." return "Waiting for initialization..."
elif short_name == "dojo": elif short_name == "dojo":
try: try:
dojo_initialized = subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True).strip() dojo_initialized = to_string(subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True).strip())
except: except:
dojo_initialized = "" dojo_initialized = ""
if dojo_initialized != "true": if dojo_initialized != "true":
@ -305,7 +305,7 @@ def get_application_status_color_special(short_name):
return "yellow" return "yellow"
elif short_name == "dojo": elif short_name == "dojo":
try: try:
dojo_initialized = subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True).strip() dojo_initialized = to_string(subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True).strip())
except: except:
dojo_initialized = "" dojo_initialized = ""
if dojo_initialized != "true": if dojo_initialized != "true":
@ -374,7 +374,7 @@ def has_customized_app_versions():
def get_app_version_data(): def get_app_version_data():
try: try:
contents = subprocess.check_output('cat /usr/share/mynode/mynode_app_versions.sh | grep -v "_VERSION_FILE=" | grep "="', shell=True) contents = to_string(subprocess.check_output('cat /usr/share/mynode/mynode_app_versions.sh | grep -v "_VERSION_FILE=" | grep "="', shell=True))
return contents return contents
except Exception as e: except Exception as e:
return "ERROR" return "ERROR"

View File

@ -18,7 +18,7 @@ mynode_bitcoin = Blueprint('mynode_bitcoin',__name__)
def runcmd(cmd): def runcmd(cmd):
cmd = "bitcoin-cli --conf=/home/admin/.bitcoin/bitcoin.conf --datadir=/mnt/hdd/mynode/bitcoin "+cmd+"; exit 0" cmd = "bitcoin-cli --conf=/home/admin/.bitcoin/bitcoin.conf --datadir=/mnt/hdd/mynode/bitcoin "+cmd+"; exit 0"
try: try:
results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) results = to_string(subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True))
except Exception as e: except Exception as e:
results = str(e) results = str(e)
return results return results

View File

@ -260,12 +260,12 @@ def is_device_from_reseller():
# Device Info # Device Info
#================================== #==================================
def get_system_uptime(): def get_system_uptime():
uptime = subprocess.check_output('awk \'{print int($1/86400)" days "int($1%86400/3600)" hour(s) "int(($1%3600)/60)" minute(s) "int($1%60)" seconds(s)"}\' /proc/uptime', shell=True) uptime = to_string(subprocess.check_output('awk \'{print int($1/86400)" days "int($1%86400/3600)" hour(s) "int(($1%3600)/60)" minute(s) "int($1%60)" seconds(s)"}\' /proc/uptime', shell=True))
uptime = to_string(uptime.strip()) uptime = uptime.strip()
return uptime return uptime
def get_system_uptime_in_seconds(): def get_system_uptime_in_seconds():
uptime = subprocess.check_output('awk \'{print $1}\' /proc/uptime', shell=True) uptime = to_string(subprocess.check_output('awk \'{print $1}\' /proc/uptime', shell=True))
uptime = int(float(uptime.strip())) uptime = int(float(uptime.strip()))
return uptime return uptime
@ -273,8 +273,8 @@ def get_system_time_in_ms():
return int(round(time.time() * 1000)) return int(round(time.time() * 1000))
def get_system_date(): def get_system_date():
date = subprocess.check_output('date', shell=True) date = to_string(subprocess.check_output('date', shell=True))
date = to_string(date.strip()) date = date.strip()
return date return date
def get_device_serial(): def get_device_serial():
@ -282,8 +282,8 @@ def get_device_serial():
if "serial" in cached_data: if "serial" in cached_data:
return cached_data["serial"] return cached_data["serial"]
serial = subprocess.check_output("mynode-get-device-serial", shell=True) serial = to_string(subprocess.check_output("mynode-get-device-serial", shell=True))
serial = to_string(serial.strip()) serial = serial.strip()
cached_data["serial"] = serial cached_data["serial"] = serial
return serial return serial
@ -318,19 +318,19 @@ def get_device_ram():
def get_local_ip(): def get_local_ip():
local_ip = "unknown" local_ip = "unknown"
try: try:
local_ip = subprocess.check_output('/usr/bin/get_local_ip.py', shell=True).strip() local_ip = to_string(subprocess.check_output('/usr/bin/get_local_ip.py', shell=True).strip())
except: except:
local_ip = "error" local_ip = "error"
return to_string(local_ip) return local_ip
def get_device_changelog(): def get_device_changelog():
changelog = "" changelog = ""
try: try:
changelog = subprocess.check_output(["cat", "/usr/share/mynode/changelog"]) changelog = to_string(subprocess.check_output(["cat", "/usr/share/mynode/changelog"]))
except: except:
changelog = "ERROR" changelog = "ERROR"
return to_string(changelog) return changelog
def has_changed_password(): def has_changed_password():
try: try:
@ -444,7 +444,7 @@ def get_drive_info(drive):
data = {} data = {}
data["name"] = "NOT_FOUND" data["name"] = "NOT_FOUND"
try: try:
lsblk_output = subprocess.check_output("lsblk -io KNAME,TYPE,SIZE,MODEL,VENDOR /dev/{} | grep disk".format(drive), shell=True).decode("utf-8") lsblk_output = to_string(subprocess.check_output("lsblk -io KNAME,TYPE,SIZE,MODEL,VENDOR /dev/{} | grep disk".format(drive), shell=True).decode("utf-8"))
parts = lsblk_output.split() parts = lsblk_output.split()
data["name"] = parts[0] data["name"] = parts[0]
data["size"] = parts[2] data["size"] = parts[2]
@ -670,7 +670,7 @@ def get_quicksync_log():
log = "UNKNOWN" log = "UNKNOWN"
if is_quicksync_enabled(): if is_quicksync_enabled():
try: try:
log = subprocess.check_output(["mynode-get-quicksync-status"]).decode("utf8") log = to_string(subprocess.check_output(["mynode-get-quicksync-status"]).decode("utf8"))
except: except:
log = "ERROR" log = "ERROR"
else: else:
@ -1150,7 +1150,7 @@ def reload_firewall():
def get_firewall_rules(): def get_firewall_rules():
try: try:
rules = subprocess.check_output("ufw status", shell=True).decode("utf8") rules = to_string(subprocess.check_output("ufw status", shell=True).decode("utf8"))
except: except:
rules = "ERROR" rules = "ERROR"
return rules return rules

View File

@ -6,6 +6,7 @@ from enable_disable_functions import *
from bitcoin_info import get_mynode_block_height from bitcoin_info import get_mynode_block_height
from electrum_info import get_electrs_status, is_electrs_active from electrum_info import get_electrs_status, is_electrs_active
from application_info import * from application_info import *
from utilities import *
import subprocess import subprocess
import re import re
import os import os
@ -15,7 +16,7 @@ mynode_dojo = Blueprint('mynode_dojo',__name__)
## Status and color ## Status and color
def is_dojo_initialized(): def is_dojo_initialized():
try: try:
dojo_initialized = subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True) dojo_initialized = to_string(subprocess.check_output("docker inspect --format={{.State.Running}} db", shell=True))
dojo_initialized = dojo_initialized.strip() dojo_initialized = dojo_initialized.strip()
except: except:
dojo_initialized = "" dojo_initialized = ""
@ -55,7 +56,7 @@ def get_dojo_status():
def get_dojo_tracker_status(): def get_dojo_tracker_status():
try: try:
tracker_log = subprocess.check_output("docker logs --tail 100 nodejs", shell=True) tracker_log = to_string(subprocess.check_output("docker logs --tail 100 nodejs", shell=True))
except: except:
return "error" return "error"
@ -86,7 +87,7 @@ def get_dojo_tracker_status():
def get_dojo_version(): def get_dojo_version():
version = "Unknown" version = "Unknown"
try: try:
version = subprocess.check_output("cat /mnt/hdd/mynode/dojo/docker/my-dojo/.env | grep -i DOJO_VERSION_TAG", shell=True) version = to_string(subprocess.check_output("cat /mnt/hdd/mynode/dojo/docker/my-dojo/.env | grep -i DOJO_VERSION_TAG", shell=True))
version = version.split("=")[1] version = version.split("=")[1]
version = version.strip() version = version.strip()
except: except:
@ -96,7 +97,7 @@ def get_dojo_version():
def get_dojo_admin_key(): def get_dojo_admin_key():
key = 'Not found' key = 'Not found'
try: try:
key = subprocess.check_output("cat /mnt/hdd/mynode/dojo/docker/my-dojo/conf/docker-node.conf | grep -i NODE_ADMIN_KEY= | cut -c 16-", shell=True) key = to_string(subprocess.check_output("cat /mnt/hdd/mynode/dojo/docker/my-dojo/conf/docker-node.conf | grep -i NODE_ADMIN_KEY= | cut -c 16-", shell=True))
key = key.strip() key = key.strip()
except: except:
key = 'error' key = 'error'
@ -105,7 +106,7 @@ def get_dojo_admin_key():
def get_dojo_addr(): def get_dojo_addr():
addr = 'Not found' addr = 'Not found'
try: try:
addr = subprocess.check_output("docker exec tor cat /var/lib/tor/hsv3dojo/hostname", shell=True) addr = to_string(subprocess.check_output("docker exec tor cat /var/lib/tor/hsv3dojo/hostname", shell=True))
page = '/admin' page = '/admin'
addr = addr.strip() + page addr = addr.strip() + page
except: except:

View File

@ -54,7 +54,7 @@ def get_electrs_status():
bitcoin_block_height = get_bitcoin_block_height() bitcoin_block_height = get_bitcoin_block_height()
log = "" log = ""
try: try:
log += subprocess.check_output("journalctl --unit=electrs --no-pager | tail -n 100", shell=True) log += to_string(subprocess.check_output("journalctl --unit=electrs --no-pager | tail -n 100", shell=True))
except: except:
log += "" log += ""
lines = log.splitlines() lines = log.splitlines()
@ -107,10 +107,10 @@ def get_electrs_db_size(is_testnet=False):
folder = "/mnt/hdd/mynode/electrs/bitcoin" folder = "/mnt/hdd/mynode/electrs/bitcoin"
if is_testnet: if is_testnet:
folder = "/mnt/hdd/mynode/electrs/testnet" folder = "/mnt/hdd/mynode/electrs/testnet"
size = subprocess.check_output("du -h "+folder+" | head -n1 | awk '{print $1;}'", shell=True) size = to_string(subprocess.check_output("du -h "+folder+" | head -n1 | awk '{print $1;}'", shell=True))
except Exception as e: except Exception as e:
size = "Error" size = "Error"
return to_string( size ) return size
def get_from_electrum(method, params=[]): def get_from_electrum(method, params=[]):
params = [params] if type(params) is not list else params params = [params] if type(params) is not list else params

View File

@ -391,7 +391,7 @@ def lnd_get_v2(path, timeout=10):
return r.json() return r.json()
def gen_new_wallet_seed(): def gen_new_wallet_seed():
seed = subprocess.check_output("python3 /usr/bin/gen_seed.py", shell=True) seed = to_string(subprocess.check_output("python3 /usr/bin/gen_seed.py", shell=True))
return seed return seed
def get_lnd_lit_password(): def get_lnd_lit_password():
@ -423,7 +423,7 @@ def get_lightning_macaroon_file():
return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon" return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon"
def get_macaroon(): def get_macaroon():
m = subprocess.check_output("xxd -ps -u -c 1000 " + get_lightning_macaroon_file(), shell=True) m = to_string(subprocess.check_output("xxd -ps -u -c 1000 " + get_lightning_macaroon_file(), shell=True))
return m.strip() return m.strip()
def lnd_wallet_exists(): def lnd_wallet_exists():
@ -466,8 +466,7 @@ def lnd_get_channel_db_size():
path = "testnet" path = "testnet"
size = "???" size = "???"
try: try:
s = subprocess.check_output("ls -lsah /mnt/hdd/mynode/lnd/data/graph/"+path+"/channel.db | awk '{print $6}'", shell=True) size = to_string(subprocess.check_output("ls -lsah /mnt/hdd/mynode/lnd/data/graph/"+path+"/channel.db | awk '{print $6}'", shell=True))
size = to_string( s )
except: except:
size = "ERR" size = "ERR"
return size return size

View File

@ -136,7 +136,7 @@ def index():
if is_uploader(): if is_uploader():
status="" status=""
try: try:
status = subprocess.check_output(["mynode-get-quicksync-status"]) status = to_string(subprocess.check_output(["mynode-get-quicksync-status"]))
except: except:
status = "Waiting on quicksync to start..." status = "Waiting on quicksync to start..."
@ -352,8 +352,8 @@ def index():
return redirect("/product-key") return redirect("/product-key")
elif status == STATE_QUICKSYNC_COPY: elif status == STATE_QUICKSYNC_COPY:
try: try:
current = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/bitcoin/"]).split()[0] current = to_string(subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/bitcoin/"]).split()[0])
total = subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/quicksync/"]).split()[0] total = to_string(subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/quicksync/"]).split()[0])
except: except:
current = 0.0 current = 0.0
total = 100.0 total = 100.0

View File

@ -37,7 +37,7 @@ def update_price_info():
if get_ui_setting("price_ticker"): if get_ui_setting("price_ticker"):
price = "N/A" price = "N/A"
try: try:
price_json_string = subprocess.check_output("torify curl https://api.coindesk.com/v1/bpi/currentprice.json", shell=True) price_json_string = to_string(subprocess.check_output("torify curl https://api.coindesk.com/v1/bpi/currentprice.json", shell=True))
data = json.loads(price_json_string) data = json.loads(price_json_string)
price = data["bpi"]["USD"]["rate_float"] price = data["bpi"]["USD"]["rate_float"]

View File

@ -47,7 +47,7 @@ def get_service_status_color(service_name):
def get_journalctl_log(service_name): def get_journalctl_log(service_name):
try: try:
log = subprocess.check_output("journalctl -r --unit={} --no-pager | head -n 300".format(service_name), shell=True).decode("utf8") log = to_string(subprocess.check_output("journalctl -r --unit={} --no-pager | head -n 300".format(service_name), shell=True).decode("utf8"))
except: except:
log = "ERROR" log = "ERROR"
return log return log

View File

@ -64,14 +64,12 @@ def update_device_info():
reload_throttled_data() reload_throttled_data()
# Get drive actual usage # Get drive actual usage
#results = subprocess.check_output(["du","-sh","/mnt/hdd/mynode/"]) #results = to_string(subprocess.check_output(["du","-sh","/mnt/hdd/mynode/"]))
#drive_usage = results.split()[0] #drive_usage = results.split()[0]
# Get drive percent usage # Get drive percent usage
results = subprocess.check_output("df -h /mnt/hdd | grep /dev | awk '{print $5}'", shell=True) data_drive_usage = to_string(subprocess.check_output("df -h /mnt/hdd | grep /dev | awk '{print $5}'", shell=True))
data_drive_usage = to_string(results) os_drive_usage = to_string(subprocess.check_output("df -h / | grep /dev | awk '{print $5}'", shell=True))
results = subprocess.check_output("df -h / | grep /dev | awk '{print $5}'", shell=True)
os_drive_usage = to_string(results)
# Get RAM usage # Get RAM usage
ram_info = psutil.virtual_memory() ram_info = psutil.virtual_memory()
@ -86,7 +84,7 @@ def update_device_info():
cpu_usage = "{:.1f}%".format(100.0 - cpu_info.idle) cpu_usage = "{:.1f}%".format(100.0 - cpu_info.idle)
# Get device temp # Get device temp
results = subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp", shell=True) results = to_string(subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp", shell=True))
temp = int(results) / 1000 temp = int(results) / 1000
device_temp = "{:.1f}".format(temp) device_temp = "{:.1f}".format(temp)

View File

@ -110,7 +110,7 @@ def get_file_log(file_path):
return "MISSING FILE" return "MISSING FILE"
try: try:
status_log = subprocess.check_output(["tail","-n","200",file_path]).decode("utf8") status_log = to_string(subprocess.check_output(["tail","-n","250",file_path]).decode("utf8"))
lines = status_log.split('\n') lines = status_log.split('\n')
lines.reverse() lines.reverse()
status_log = '\n'.join(lines) status_log = '\n'.join(lines)

View File

@ -21,7 +21,7 @@ def whirlpool_page():
whirlpool_api_key = 'Not found' whirlpool_api_key = 'Not found'
try: try:
whirlpool_api_key = subprocess.check_output("cat /mnt/hdd/mynode/whirlpool/whirlpool-cli-config* | grep -i cli.Apikey= | cut -c 12-", shell=True) whirlpool_api_key = to_string(subprocess.check_output("cat /mnt/hdd/mynode/whirlpool/whirlpool-cli-config* | grep -i cli.Apikey= | cut -c 12-", shell=True))
except: except:
whirlpool_api_key = 'error' whirlpool_api_key = 'error'