More python2/3 string handling
This commit is contained in:
parent
2c1cddb1e3
commit
bac5fe1f1e
|
@ -259,7 +259,7 @@ def get_application_status_special(short_name):
|
|||
return "Waiting for initialization..."
|
||||
elif short_name == "dojo":
|
||||
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:
|
||||
dojo_initialized = ""
|
||||
if dojo_initialized != "true":
|
||||
|
@ -305,7 +305,7 @@ def get_application_status_color_special(short_name):
|
|||
return "yellow"
|
||||
elif short_name == "dojo":
|
||||
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:
|
||||
dojo_initialized = ""
|
||||
if dojo_initialized != "true":
|
||||
|
@ -374,7 +374,7 @@ def has_customized_app_versions():
|
|||
|
||||
def get_app_version_data():
|
||||
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
|
||||
except Exception as e:
|
||||
return "ERROR"
|
||||
|
|
|
@ -18,7 +18,7 @@ mynode_bitcoin = Blueprint('mynode_bitcoin',__name__)
|
|||
def runcmd(cmd):
|
||||
cmd = "bitcoin-cli --conf=/home/admin/.bitcoin/bitcoin.conf --datadir=/mnt/hdd/mynode/bitcoin "+cmd+"; exit 0"
|
||||
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:
|
||||
results = str(e)
|
||||
return results
|
||||
|
|
|
@ -260,12 +260,12 @@ def is_device_from_reseller():
|
|||
# Device Info
|
||||
#==================================
|
||||
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(uptime.strip())
|
||||
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 = uptime.strip()
|
||||
return uptime
|
||||
|
||||
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()))
|
||||
return uptime
|
||||
|
||||
|
@ -273,8 +273,8 @@ def get_system_time_in_ms():
|
|||
return int(round(time.time() * 1000))
|
||||
|
||||
def get_system_date():
|
||||
date = subprocess.check_output('date', shell=True)
|
||||
date = to_string(date.strip())
|
||||
date = to_string(subprocess.check_output('date', shell=True))
|
||||
date = date.strip()
|
||||
return date
|
||||
|
||||
def get_device_serial():
|
||||
|
@ -282,8 +282,8 @@ def get_device_serial():
|
|||
if "serial" in cached_data:
|
||||
return cached_data["serial"]
|
||||
|
||||
serial = subprocess.check_output("mynode-get-device-serial", shell=True)
|
||||
serial = to_string(serial.strip())
|
||||
serial = to_string(subprocess.check_output("mynode-get-device-serial", shell=True))
|
||||
serial = serial.strip()
|
||||
|
||||
cached_data["serial"] = serial
|
||||
return serial
|
||||
|
@ -318,19 +318,19 @@ def get_device_ram():
|
|||
def get_local_ip():
|
||||
local_ip = "unknown"
|
||||
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:
|
||||
local_ip = "error"
|
||||
|
||||
return to_string(local_ip)
|
||||
return local_ip
|
||||
|
||||
def get_device_changelog():
|
||||
changelog = ""
|
||||
try:
|
||||
changelog = subprocess.check_output(["cat", "/usr/share/mynode/changelog"])
|
||||
changelog = to_string(subprocess.check_output(["cat", "/usr/share/mynode/changelog"]))
|
||||
except:
|
||||
changelog = "ERROR"
|
||||
return to_string(changelog)
|
||||
return changelog
|
||||
|
||||
def has_changed_password():
|
||||
try:
|
||||
|
@ -444,7 +444,7 @@ def get_drive_info(drive):
|
|||
data = {}
|
||||
data["name"] = "NOT_FOUND"
|
||||
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()
|
||||
data["name"] = parts[0]
|
||||
data["size"] = parts[2]
|
||||
|
@ -670,7 +670,7 @@ def get_quicksync_log():
|
|||
log = "UNKNOWN"
|
||||
if is_quicksync_enabled():
|
||||
try:
|
||||
log = subprocess.check_output(["mynode-get-quicksync-status"]).decode("utf8")
|
||||
log = to_string(subprocess.check_output(["mynode-get-quicksync-status"]).decode("utf8"))
|
||||
except:
|
||||
log = "ERROR"
|
||||
else:
|
||||
|
@ -1150,7 +1150,7 @@ def reload_firewall():
|
|||
|
||||
def get_firewall_rules():
|
||||
try:
|
||||
rules = subprocess.check_output("ufw status", shell=True).decode("utf8")
|
||||
rules = to_string(subprocess.check_output("ufw status", shell=True).decode("utf8"))
|
||||
except:
|
||||
rules = "ERROR"
|
||||
return rules
|
||||
|
|
|
@ -6,6 +6,7 @@ from enable_disable_functions import *
|
|||
from bitcoin_info import get_mynode_block_height
|
||||
from electrum_info import get_electrs_status, is_electrs_active
|
||||
from application_info import *
|
||||
from utilities import *
|
||||
import subprocess
|
||||
import re
|
||||
import os
|
||||
|
@ -15,7 +16,7 @@ mynode_dojo = Blueprint('mynode_dojo',__name__)
|
|||
## Status and color
|
||||
def is_dojo_initialized():
|
||||
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()
|
||||
except:
|
||||
dojo_initialized = ""
|
||||
|
@ -55,7 +56,7 @@ def get_dojo_status():
|
|||
|
||||
def get_dojo_tracker_status():
|
||||
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:
|
||||
return "error"
|
||||
|
||||
|
@ -86,7 +87,7 @@ def get_dojo_tracker_status():
|
|||
def get_dojo_version():
|
||||
version = "Unknown"
|
||||
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.strip()
|
||||
except:
|
||||
|
@ -96,7 +97,7 @@ def get_dojo_version():
|
|||
def get_dojo_admin_key():
|
||||
key = 'Not found'
|
||||
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()
|
||||
except:
|
||||
key = 'error'
|
||||
|
@ -105,7 +106,7 @@ def get_dojo_admin_key():
|
|||
def get_dojo_addr():
|
||||
addr = 'Not found'
|
||||
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'
|
||||
addr = addr.strip() + page
|
||||
except:
|
||||
|
|
|
@ -54,7 +54,7 @@ def get_electrs_status():
|
|||
bitcoin_block_height = get_bitcoin_block_height()
|
||||
log = ""
|
||||
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:
|
||||
log += ""
|
||||
lines = log.splitlines()
|
||||
|
@ -107,10 +107,10 @@ def get_electrs_db_size(is_testnet=False):
|
|||
folder = "/mnt/hdd/mynode/electrs/bitcoin"
|
||||
if is_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:
|
||||
size = "Error"
|
||||
return to_string( size )
|
||||
return size
|
||||
|
||||
def get_from_electrum(method, params=[]):
|
||||
params = [params] if type(params) is not list else params
|
||||
|
|
|
@ -391,7 +391,7 @@ def lnd_get_v2(path, timeout=10):
|
|||
return r.json()
|
||||
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
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()
|
||||
|
||||
def lnd_wallet_exists():
|
||||
|
@ -466,8 +466,7 @@ def lnd_get_channel_db_size():
|
|||
path = "testnet"
|
||||
size = "???"
|
||||
try:
|
||||
s = subprocess.check_output("ls -lsah /mnt/hdd/mynode/lnd/data/graph/"+path+"/channel.db | awk '{print $6}'", shell=True)
|
||||
size = to_string( s )
|
||||
size = to_string(subprocess.check_output("ls -lsah /mnt/hdd/mynode/lnd/data/graph/"+path+"/channel.db | awk '{print $6}'", shell=True))
|
||||
except:
|
||||
size = "ERR"
|
||||
return size
|
||||
|
|
|
@ -136,7 +136,7 @@ def index():
|
|||
if is_uploader():
|
||||
status=""
|
||||
try:
|
||||
status = subprocess.check_output(["mynode-get-quicksync-status"])
|
||||
status = to_string(subprocess.check_output(["mynode-get-quicksync-status"]))
|
||||
except:
|
||||
status = "Waiting on quicksync to start..."
|
||||
|
||||
|
@ -352,8 +352,8 @@ def index():
|
|||
return redirect("/product-key")
|
||||
elif status == STATE_QUICKSYNC_COPY:
|
||||
try:
|
||||
current = 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]
|
||||
current = to_string(subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/bitcoin/"]).split()[0])
|
||||
total = to_string(subprocess.check_output(["du","-m","--max-depth=0","/mnt/hdd/mynode/quicksync/"]).split()[0])
|
||||
except:
|
||||
current = 0.0
|
||||
total = 100.0
|
||||
|
|
|
@ -37,7 +37,7 @@ def update_price_info():
|
|||
if get_ui_setting("price_ticker"):
|
||||
price = "N/A"
|
||||
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)
|
||||
price = data["bpi"]["USD"]["rate_float"]
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ def get_service_status_color(service_name):
|
|||
|
||||
def get_journalctl_log(service_name):
|
||||
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:
|
||||
log = "ERROR"
|
||||
return log
|
||||
|
|
|
@ -64,14 +64,12 @@ def update_device_info():
|
|||
reload_throttled_data()
|
||||
|
||||
# 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]
|
||||
|
||||
# Get drive percent usage
|
||||
results = subprocess.check_output("df -h /mnt/hdd | grep /dev | awk '{print $5}'", shell=True)
|
||||
data_drive_usage = to_string(results)
|
||||
results = subprocess.check_output("df -h / | grep /dev | awk '{print $5}'", shell=True)
|
||||
os_drive_usage = to_string(results)
|
||||
data_drive_usage = to_string(subprocess.check_output("df -h /mnt/hdd | grep /dev | awk '{print $5}'", shell=True))
|
||||
os_drive_usage = to_string(subprocess.check_output("df -h / | grep /dev | awk '{print $5}'", shell=True))
|
||||
|
||||
# Get RAM usage
|
||||
ram_info = psutil.virtual_memory()
|
||||
|
@ -86,7 +84,7 @@ def update_device_info():
|
|||
cpu_usage = "{:.1f}%".format(100.0 - cpu_info.idle)
|
||||
|
||||
# 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
|
||||
device_temp = "{:.1f}".format(temp)
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ def get_file_log(file_path):
|
|||
return "MISSING FILE"
|
||||
|
||||
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.reverse()
|
||||
status_log = '\n'.join(lines)
|
||||
|
|
|
@ -21,7 +21,7 @@ def whirlpool_page():
|
|||
|
||||
whirlpool_api_key = 'Not found'
|
||||
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:
|
||||
whirlpool_api_key = 'error'
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user