mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2024-11-20 18:22:01 +01:00
refactor for BlitzPy
This commit is contained in:
parent
590f5e8b43
commit
8b0f9b6417
@ -1,8 +1,8 @@
|
||||
""" Store the version here so:
|
||||
# 1) we don't load dependencies by storing it in __init__.py
|
||||
# 2) we can import it in setup.py for the same reason
|
||||
# 3) we can import it into your module module
|
||||
"""
|
||||
|
||||
__version_info__ = ('0', '2', '0')
|
||||
__version__ = '.'.join(__version_info__)
|
||||
""" Store the version here so:
|
||||
# 1) we don't load dependencies by storing it in __init__.py
|
||||
# 2) we can import it in setup.py for the same reason
|
||||
# 3) we can import it into your module module
|
||||
"""
|
||||
|
||||
__version_info__ = ('0', '2', '0')
|
||||
__version__ = '.'.join(__version_info__)
|
||||
|
@ -5,8 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.47.0] - 2020-05-23
|
||||
### Removed
|
||||
- remove config.py has been moved to dedicated ackage BlitzPy
|
||||
|
||||
## [0.46.1] - 2020-04-17
|
||||
### Added
|
||||
### Removed
|
||||
- remove LND config check
|
||||
|
||||
## [0.45.0] - 2020-01-25
|
||||
|
@ -1,195 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
from configparser import ConfigParser, DEFAULTSECT
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LndConfig(object):
|
||||
def __init__(self, abs_path="/mnt/hdd/lnd/lnd.conf"):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for LND Configuration
|
||||
self.rpc_listen = ""
|
||||
|
||||
@property
|
||||
def rpc_listen_host(self):
|
||||
return self.rpc_listen.split(":")[0]
|
||||
|
||||
@property
|
||||
def rpc_listen_port(self):
|
||||
try:
|
||||
return int(self.rpc_listen.split(":")[1])
|
||||
except (IndexError, TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string(f.read())
|
||||
|
||||
app_options = parser["Application Options"]
|
||||
|
||||
self.rpc_listen = get_str_clean(app_options, "rpclisten", self.rpc_listen)
|
||||
|
||||
|
||||
class RaspiBlitzConfig(object):
|
||||
def __init__(self, abs_path="/mnt/hdd/raspiblitz.conf"):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for RaspiBlitz Configuration
|
||||
self.auto_nat_discovery = False
|
||||
self.auto_pilot = False
|
||||
self.auto_unlock = False
|
||||
self.chain = ""
|
||||
self.dynDomain = ""
|
||||
self.dyn_update_url = ""
|
||||
self.hostname = ""
|
||||
self.invoice_allow_donations = False
|
||||
self.invoice_default_amount = 402
|
||||
self.lcd_rotate = False
|
||||
self.lnd_address = ""
|
||||
self.lnd_port = ""
|
||||
self.network = ""
|
||||
self.public_ip = ""
|
||||
self.rtl_web_interface = False
|
||||
self.run_behind_tor = False
|
||||
self.ssh_tunnel = ""
|
||||
self.touchscreen = False
|
||||
self.version = ""
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
|
||||
|
||||
default_s = parser[DEFAULTSECT]
|
||||
|
||||
self.auto_nat_discovery = default_s.getboolean("autoNatDiscovery", self.auto_nat_discovery)
|
||||
self.auto_pilot = default_s.getboolean("autoPilot", self.auto_pilot)
|
||||
self.auto_unlock = default_s.getboolean("autoUnlock", self.auto_unlock)
|
||||
self.chain = get_str_clean(default_s, "chain", self.chain)
|
||||
self.dynDomain = get_str_clean(default_s, "dynDomain", self.dynDomain)
|
||||
self.dyn_update_url = get_str_clean(default_s, "dynUpdateUrl", self.dyn_update_url)
|
||||
self.hostname = get_str_clean(default_s, "hostname", self.hostname)
|
||||
self.invoice_allow_donations = default_s.getboolean("invoiceAllowDonations", self.invoice_allow_donations)
|
||||
self.invoice_default_amount = get_int_safe(default_s, "invoiceDefaultAmount", self.invoice_default_amount)
|
||||
self.lcd_rotate = default_s.getboolean("lcdrotate", self.lcd_rotate)
|
||||
self.lnd_address = get_str_clean(default_s, "lndAddress", self.lnd_address)
|
||||
self.lnd_port = get_str_clean(default_s, "lndPort", self.lnd_port)
|
||||
self.network = get_str_clean(default_s, "network", self.network)
|
||||
self.public_ip = get_str_clean(default_s, "publicIP", self.public_ip)
|
||||
self.rtl_web_interface = default_s.getboolean("rtlWebinterface", self.rtl_web_interface)
|
||||
self.run_behind_tor = default_s.getboolean("runBehindTor", self.run_behind_tor)
|
||||
self.ssh_tunnel = get_str_clean(default_s, "sshtunnel", self.ssh_tunnel)
|
||||
self.touchscreen = default_s.getboolean("touchscreen", self.touchscreen)
|
||||
self.version = get_str_clean(default_s, "raspiBlitzVersion", self.version)
|
||||
|
||||
|
||||
class RaspiBlitzInfo(object):
|
||||
def __init__(self, abs_path="/home/admin/raspiblitz.info"):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for RaspiBlitz Info
|
||||
self.base_image = ""
|
||||
self.chain = ""
|
||||
self.message = ""
|
||||
self.network = ""
|
||||
self.setup_step = 0
|
||||
self.state = ""
|
||||
self.undervoltage_reports = 0
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading RaspiBlitzInfo config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
|
||||
|
||||
default_s = parser[DEFAULTSECT]
|
||||
|
||||
self.base_image = get_str_clean(default_s, "baseimage", self.base_image)
|
||||
self.chain = get_str_clean(default_s, "chain", self.chain)
|
||||
self.message = get_str_clean(default_s, "message", self.message)
|
||||
self.network = get_str_clean(default_s, "network", self.network)
|
||||
self.setup_step = get_int_safe(default_s, "setupStep", self.setup_step)
|
||||
self.state = get_str_clean(default_s, "state", self.state)
|
||||
self.undervoltage_reports = get_int_safe(default_s, "undervoltageReports", self.undervoltage_reports)
|
||||
|
||||
|
||||
def get_int_safe(cp_section, key, default_value):
|
||||
"""take a ConfigParser section, get key that might be string encoded int and return int"""
|
||||
try:
|
||||
value = cp_section.getint(key, default_value)
|
||||
except ValueError:
|
||||
_value = cp_section.get(key)
|
||||
value = int(_value.strip("'").strip('"')) # this will raise an Exception if int() fails!
|
||||
return value
|
||||
|
||||
|
||||
def get_str_clean(cp_section, key, default_value):
|
||||
"""take a ConfigParser section, get key and strip leading and trailing \' and \" chars"""
|
||||
value = cp_section.get(key, default_value)
|
||||
if not value:
|
||||
return ""
|
||||
|
||||
return value.lstrip('"').lstrip("'").rstrip('"').rstrip("'")
|
||||
|
||||
|
||||
def main():
|
||||
lnd_cfg = LndConfig()
|
||||
if os.path.exists(lnd_cfg.abs_path):
|
||||
lnd_cfg.reload()
|
||||
|
||||
print("=======\n= LND =\n=======")
|
||||
print("rpc_list: \t\t{}".format(lnd_cfg.rpc_listen))
|
||||
print("rpc_list_host: \t\t{}".format(lnd_cfg.rpc_listen_host))
|
||||
print("rpc_list_port: \t\t{}".format(lnd_cfg.rpc_listen_port))
|
||||
print("")
|
||||
|
||||
rb_cfg = RaspiBlitzConfig()
|
||||
if os.path.exists(rb_cfg.abs_path):
|
||||
rb_cfg.reload()
|
||||
|
||||
print("====================\n= RaspiBlitzConfig =\n====================")
|
||||
print("auto_nat_discovery: \t\t{}".format(rb_cfg.auto_nat_discovery))
|
||||
print("auto_pilot: \t\t\t{}".format(rb_cfg.auto_pilot))
|
||||
print("auto_unlock: \t\t\t{}".format(rb_cfg.auto_unlock))
|
||||
print("chain: \t\t\t\t{}".format(rb_cfg.chain))
|
||||
print("dynDomain: \t\t\t{}".format(rb_cfg.dynDomain))
|
||||
print("dyn_update_url: \t\t{}".format(rb_cfg.dyn_update_url))
|
||||
print("hostname: \t\t\t{}".format(rb_cfg.hostname))
|
||||
print("invoice_allow_donations: \t{}".format(rb_cfg.invoice_allow_donations))
|
||||
print("invoice_default_amount: \t{}".format(rb_cfg.invoice_default_amount))
|
||||
print("lcd_rotate: \t\t\t{}".format(rb_cfg.lcd_rotate))
|
||||
print("lnd_address: \t\t\t{}".format(rb_cfg.lnd_address))
|
||||
print("lnd_port: \t\t\t{}".format(rb_cfg.lnd_port))
|
||||
print("network: \t\t\t{}".format(rb_cfg.network))
|
||||
print("public_ip: \t\t\t{}".format(rb_cfg.public_ip))
|
||||
print("rtl_web_interface: \t\t{}".format(rb_cfg.rtl_web_interface))
|
||||
print("run_behind_tor: \t\t{}".format(rb_cfg.run_behind_tor))
|
||||
print("ssh_tunnel: \t\t\t{}".format(rb_cfg.ssh_tunnel))
|
||||
print("touchscreen: \t\t\t{}".format(rb_cfg.touchscreen))
|
||||
print("version: \t\t\t{}".format(rb_cfg.version))
|
||||
print("")
|
||||
|
||||
rb_info = RaspiBlitzInfo()
|
||||
if os.path.exists(rb_info.abs_path):
|
||||
rb_info.reload()
|
||||
|
||||
print("==================\n= RaspiBlitzInfo =\n==================")
|
||||
print("state: \t\t{}".format(rb_info.state))
|
||||
print("")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -17,12 +17,12 @@ import qrcode
|
||||
from PyQt5.QtCore import Qt, QProcess, QThread, pyqtSignal, QCoreApplication, QTimer, QEventLoop
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QDialog, QDialogButtonBox
|
||||
from blitztpy import RaspiBlitzConfig, RaspiBlitzInfo
|
||||
from blitztui.file_logger import setup_logging
|
||||
from blitztui.client import ReadOnlyStub, InvoiceStub
|
||||
from blitztui.client import check_lnd, check_lnd_channels
|
||||
from blitztui.client import check_invoice_paid, create_invoice, get_node_uri
|
||||
from blitztui.client import convert_r_hash_hex_bytes
|
||||
from blitztui.config import LndConfig, RaspiBlitzConfig, RaspiBlitzInfo
|
||||
from blitztui.file_watcher import FileWatcherThread
|
||||
from blitztui.memo import adjective_noun_pair
|
||||
from blitztui.version import __version__
|
||||
|
@ -4,5 +4,5 @@
|
||||
# 3) we can import it into your module module
|
||||
"""
|
||||
|
||||
__version_info__ = ('0', '46', '1')
|
||||
__version_info__ = ('0', '47', '0')
|
||||
__version__ = '.'.join(__version_info__)
|
||||
|
@ -83,6 +83,7 @@ else
|
||||
fi
|
||||
|
||||
origin=$(git remote -v | grep 'origin' | tail -n1)
|
||||
checkSumBlitzPyBefore=$(find /home/admin/raspiblitz/home.admin/BlitzPy -type f -exec md5sum {} \; | md5sum)
|
||||
checkSumBlitzTUIBefore=$(find /home/admin/raspiblitz/home.admin/BlitzTUI -type f -exec md5sum {} \; | md5sum)
|
||||
|
||||
echo "# *** SYNCING SHELL SCRIPTS WITH GITHUB ***"
|
||||
@ -121,6 +122,19 @@ sudo -u admin chmod +x /home/admin/config.scripts/*.sh
|
||||
echo "# .."
|
||||
sudo -u admin chmod +x /home/admin/config.scripts/*.py
|
||||
echo "# ******************************************"
|
||||
|
||||
checkSumBlitzPyAfter=$(find /home/admin/raspiblitz/home.admin/BlitzPy -type f -exec md5sum {} \; | md5sum)
|
||||
echo "# checkSumBlitzPyBefore = ${checkSumBlitzPyBefore}"
|
||||
echo "# checkSumBlitzPyAfter = ${checkSumBlitzPyAfter}"
|
||||
if [ "${checkSumBlitzPyBefore}" = "${checkSumBlitzPyAfter}" ]; then
|
||||
echo "# BlitzPy did not changed."
|
||||
else
|
||||
blitzpy_wheel=$(ls -trR /home/admin/raspiblitz/home.admin/BlitzPy/dist | grep -E "*any.whl" | tail -n 1)
|
||||
blitzpy_version=$(echo ${blitzpy_wheel} | grep -oE "([0-9]\.[0-9]\.[0-9])")
|
||||
echo "# BlitzPy changed --> UPDATING to Version ${blitzpy_version}"
|
||||
sudo -H /usr/bin/python -m pip install "/home/admin/raspiblitz/home.admin/BlitzPy/dist/${blitzpy_wheel}" >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ "${touchscreen}" = "1" ]; then
|
||||
echo "# Checking if the content of BlitzTUI changed .."
|
||||
checkSumBlitzTUIAfter=$(find /home/admin/raspiblitz/home.admin/BlitzTUI -type f -exec md5sum {} \; | md5sum)
|
||||
@ -135,4 +149,4 @@ if [ "${touchscreen}" = "1" ]; then
|
||||
fi
|
||||
echo "# ******************************************"
|
||||
echo "# OK - shell scripts and assests are synced"
|
||||
echo "# Reboot recommended"
|
||||
echo "# Reboot recommended"
|
||||
|
@ -7,152 +7,14 @@ import signal
|
||||
import sys
|
||||
from argparse import RawTextHelpFormatter
|
||||
from configparser import ConfigParser, DEFAULTSECT
|
||||
from blitzpy import RaspiBlitzConfig, RaspiBlitzInfo
|
||||
|
||||
LND_CONF = "/mnt/hdd/lnd/lnd.conf"
|
||||
RB_CONF = "/mnt/hdd/raspiblitz.conf"
|
||||
RB_INFO = "/home/admin/raspiblitz.info"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LndConfig(object):
|
||||
def __init__(self, abs_path=LND_CONF):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for LND Configuration
|
||||
self.rpc_listen = ""
|
||||
|
||||
@property
|
||||
def rpc_listen_host(self):
|
||||
return self.rpc_listen.split(":")[0]
|
||||
|
||||
@property
|
||||
def rpc_listen_port(self):
|
||||
try:
|
||||
return int(self.rpc_listen.split(":")[1])
|
||||
except (IndexError, TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string(f.read())
|
||||
|
||||
app_options = parser["Application Options"]
|
||||
|
||||
self.rpc_listen = get_str_clean(app_options, "rpclisten", self.rpc_listen)
|
||||
|
||||
|
||||
class RaspiBlitzConfig(object):
|
||||
def __init__(self, abs_path=RB_CONF):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for RaspiBlitz Configuration
|
||||
self.auto_nat_discovery = False
|
||||
self.auto_pilot = False
|
||||
self.auto_unlock = False
|
||||
self.chain = ""
|
||||
self.dynDomain = ""
|
||||
self.dyn_update_url = ""
|
||||
self.hostname = ""
|
||||
self.invoice_allow_donations = False
|
||||
self.invoice_default_amount = 402
|
||||
self.lcd_rotate = False
|
||||
self.lnd_address = ""
|
||||
self.lnd_port = ""
|
||||
self.network = ""
|
||||
self.public_ip = ""
|
||||
self.rtl_web_interface = False
|
||||
self.run_behind_tor = False
|
||||
self.ssh_tunnel = ""
|
||||
self.touchscreen = False
|
||||
self.version = ""
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
|
||||
|
||||
default_s = parser[DEFAULTSECT]
|
||||
|
||||
self.auto_nat_discovery = default_s.getboolean("autoNatDiscovery", self.auto_nat_discovery)
|
||||
self.auto_pilot = default_s.getboolean("autoPilot", self.auto_pilot)
|
||||
self.auto_unlock = default_s.getboolean("autoUnlock", self.auto_unlock)
|
||||
self.chain = get_str_clean(default_s, "chain", self.chain)
|
||||
self.dynDomain = get_str_clean(default_s, "dynDomain", self.dynDomain)
|
||||
self.dyn_update_url = get_str_clean(default_s, "dynUpdateUrl", self.dyn_update_url)
|
||||
self.hostname = get_str_clean(default_s, "hostname", self.hostname)
|
||||
self.invoice_allow_donations = default_s.getboolean("invoiceAllowDonations", self.invoice_allow_donations)
|
||||
self.invoice_default_amount = get_int_safe(default_s, "invoiceDefaultAmount", self.invoice_default_amount)
|
||||
self.lcd_rotate = default_s.getboolean("lcdrotate", self.lcd_rotate)
|
||||
self.lnd_address = get_str_clean(default_s, "lndAddress", self.lnd_address)
|
||||
self.lnd_port = get_str_clean(default_s, "lndPort", self.lnd_port)
|
||||
self.network = get_str_clean(default_s, "network", self.network)
|
||||
self.public_ip = get_str_clean(default_s, "publicIP", self.public_ip)
|
||||
self.rtl_web_interface = default_s.getboolean("rtlWebinterface", self.rtl_web_interface)
|
||||
self.run_behind_tor = default_s.getboolean("runBehindTor", self.run_behind_tor)
|
||||
self.ssh_tunnel = get_str_clean(default_s, "sshtunnel", self.ssh_tunnel)
|
||||
self.touchscreen = default_s.getboolean("touchscreen", self.touchscreen)
|
||||
self.version = get_str_clean(default_s, "raspiBlitzVersion", self.version)
|
||||
|
||||
|
||||
class RaspiBlitzInfo(object):
|
||||
def __init__(self, abs_path=RB_INFO):
|
||||
self.abs_path = abs_path
|
||||
|
||||
# default values for RaspiBlitz Info
|
||||
self.base_image = ""
|
||||
self.chain = ""
|
||||
self.message = ""
|
||||
self.network = ""
|
||||
self.setup_step = 0
|
||||
self.state = ""
|
||||
self.undervoltage_reports = 0
|
||||
|
||||
def reload(self):
|
||||
"""load config from file"""
|
||||
parser = ConfigParser()
|
||||
|
||||
log.debug("loading config from file: {}".format(self.abs_path))
|
||||
with open(self.abs_path) as f:
|
||||
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
|
||||
|
||||
default_s = parser[DEFAULTSECT]
|
||||
|
||||
self.base_image = get_str_clean(default_s, "baseimage", self.base_image)
|
||||
self.chain = get_str_clean(default_s, "chain", self.chain)
|
||||
self.message = get_str_clean(default_s, "message", self.message)
|
||||
self.network = get_str_clean(default_s, "network", self.network)
|
||||
self.setup_step = get_int_safe(default_s, "setupStep", self.setup_step)
|
||||
self.state = get_str_clean(default_s, "state", self.state)
|
||||
self.undervoltage_reports = get_int_safe(default_s, "undervoltageReports", self.undervoltage_reports)
|
||||
|
||||
|
||||
def get_int_safe(cp_section, key, default_value):
|
||||
"""take a ConfigParser section, get key that might be string encoded int and return int"""
|
||||
try:
|
||||
value = cp_section.getint(key, default_value)
|
||||
except ValueError:
|
||||
_value = cp_section.get(key)
|
||||
value = int(_value.strip("'").strip('"')) # this will raise an Exception if int() fails!
|
||||
return value
|
||||
|
||||
|
||||
def get_str_clean(cp_section, key, default_value):
|
||||
"""take a ConfigParser section, get key and strip leading and trailing \' and \" chars"""
|
||||
value = cp_section.get(key, default_value)
|
||||
if not value:
|
||||
return ""
|
||||
|
||||
return value.lstrip('"').lstrip("'").rstrip('"').rstrip("'")
|
||||
|
||||
|
||||
def main():
|
||||
# make sure CTRL+C works
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
Loading…
Reference in New Issue
Block a user