add generate command and change config converters to non async
This commit is contained in:
@@ -3,7 +3,7 @@ import yaml
|
|||||||
import toml
|
import toml
|
||||||
|
|
||||||
|
|
||||||
async def bos_config_convert(config: dict):
|
def bos_config_convert(config: dict):
|
||||||
out_config = {}
|
out_config = {}
|
||||||
for opt in config:
|
for opt in config:
|
||||||
if opt == "format":
|
if opt == "format":
|
||||||
@@ -110,7 +110,7 @@ async def bos_config_convert(config: dict):
|
|||||||
return yaml.dump(out_config, sort_keys=False)
|
return yaml.dump(out_config, sort_keys=False)
|
||||||
|
|
||||||
|
|
||||||
async def general_config_convert_bos(yaml_config, user_suffix: str = None):
|
def general_config_convert_bos(yaml_config, user_suffix: str = None):
|
||||||
config = yaml.load(yaml_config, Loader=yaml.SafeLoader)
|
config = yaml.load(yaml_config, Loader=yaml.SafeLoader)
|
||||||
out_config = {}
|
out_config = {}
|
||||||
for opt in config:
|
for opt in config:
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class BOSMiner(BaseMiner):
|
|||||||
async with sftp.open("/etc/bosminer.toml") as file:
|
async with sftp.open("/etc/bosminer.toml") as file:
|
||||||
toml_data = toml.loads(await file.read())
|
toml_data = toml.loads(await file.read())
|
||||||
logging.debug(f"{self}: Converting config file.")
|
logging.debug(f"{self}: Converting config file.")
|
||||||
cfg = await bos_config_convert(toml_data)
|
cfg = bos_config_convert(toml_data)
|
||||||
self.config = cfg
|
self.config = cfg
|
||||||
|
|
||||||
async def get_hostname(self) -> str:
|
async def get_hostname(self) -> str:
|
||||||
@@ -170,10 +170,10 @@ class BOSMiner(BaseMiner):
|
|||||||
if ip_user:
|
if ip_user:
|
||||||
suffix = str(self.ip).split(".")[-1]
|
suffix = str(self.ip).split(".")[-1]
|
||||||
toml_conf = toml.dumps(
|
toml_conf = toml.dumps(
|
||||||
await general_config_convert_bos(yaml_config, user_suffix=suffix)
|
general_config_convert_bos(yaml_config, user_suffix=suffix)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
toml_conf = toml.dumps(await general_config_convert_bos(yaml_config))
|
toml_conf = toml.dumps(general_config_convert_bos(yaml_config))
|
||||||
async with (await self._get_ssh_connection()) as conn:
|
async with (await self._get_ssh_connection()) as conn:
|
||||||
logging.debug(f"{self}: Opening SFTP connection.")
|
logging.debug(f"{self}: Opening SFTP connection.")
|
||||||
async with conn.start_sftp_client() as sftp:
|
async with conn.start_sftp_client() as sftp:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import sys
|
|||||||
from tools.cfg_util.cfg_util_qt.imgs import FAULT_LIGHT, TkImages
|
from tools.cfg_util.cfg_util_qt.imgs import FAULT_LIGHT, TkImages
|
||||||
from tools.cfg_util.cfg_util_qt.scan import btn_scan
|
from tools.cfg_util.cfg_util_qt.scan import btn_scan
|
||||||
from tools.cfg_util.cfg_util_qt.commands import btn_light
|
from tools.cfg_util.cfg_util_qt.commands import btn_light
|
||||||
|
from tools.cfg_util.cfg_util_qt.configure import generate_config_ui
|
||||||
from tools.cfg_util.cfg_util_qt.layout import window
|
from tools.cfg_util.cfg_util_qt.layout import window
|
||||||
from tools.cfg_util.cfg_util_qt.general import btn_all, btn_web, btn_refresh
|
from tools.cfg_util.cfg_util_qt.general import btn_all, btn_web, btn_refresh
|
||||||
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
||||||
@@ -69,6 +70,8 @@ async def main():
|
|||||||
if event == "cfg_web":
|
if event == "cfg_web":
|
||||||
_table = "cfg_table"
|
_table = "cfg_table"
|
||||||
btn_web(_table, value[_table])
|
btn_web(_table, value[_table])
|
||||||
|
if event == "cfg_generate":
|
||||||
|
await generate_config_ui()
|
||||||
|
|
||||||
# commands tab
|
# commands tab
|
||||||
if event == "cmd_all":
|
if event == "cmd_all":
|
||||||
|
|||||||
97
tools/cfg_util/cfg_util_qt/configure/__init__.py
Normal file
97
tools/cfg_util/cfg_util_qt/configure/__init__.py
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import PySimpleGUI as sg
|
||||||
|
from config.bos import bos_config_convert
|
||||||
|
import time
|
||||||
|
from tools.cfg_util.cfg_util_qt.layout import window
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config(username: str, workername: str, v2_allowed: bool):
|
||||||
|
if username and workername:
|
||||||
|
user = f"{username}.{workername}"
|
||||||
|
elif username and not workername:
|
||||||
|
user = username
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
if v2_allowed:
|
||||||
|
url_1 = "stratum2+tcp://v2.us-east.stratum.slushpool.com/u95GEReVMjK6k5YqiSFNqqTnKU4ypU2Wm8awa6tmbmDmk1bWt"
|
||||||
|
url_2 = "stratum2+tcp://v2.stratum.slushpool.com/u95GEReVMjK6k5YqiSFNqqTnKU4ypU2Wm8awa6tmbmDmk1bWt"
|
||||||
|
url_3 = "stratum+tcp://stratum.slushpool.com:3333"
|
||||||
|
else:
|
||||||
|
url_1 = "stratum+tcp://ca.stratum.slushpool.com:3333"
|
||||||
|
url_2 = "stratum+tcp://us-east.stratum.slushpool.com:3333"
|
||||||
|
url_3 = "stratum+tcp://stratum.slushpool.com:3333"
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"group": [
|
||||||
|
{
|
||||||
|
"name": "group",
|
||||||
|
"quota": 1,
|
||||||
|
"pool": [
|
||||||
|
{"url": url_1, "user": user, "password": "123"},
|
||||||
|
{"url": url_2, "user": user, "password": "123"},
|
||||||
|
{"url": url_3, "user": user, "password": "123"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"format": {
|
||||||
|
"version": "1.2+",
|
||||||
|
"model": "Antminer S9",
|
||||||
|
"generator": "upstream_config_util",
|
||||||
|
"timestamp": int(time.time()),
|
||||||
|
},
|
||||||
|
"temp_control": {
|
||||||
|
"target_temp": 80.0,
|
||||||
|
"hot_temp": 90.0,
|
||||||
|
"dangerous_temp": 120.0,
|
||||||
|
},
|
||||||
|
"autotuning": {"enabled": True, "psu_power_limit": 900},
|
||||||
|
}
|
||||||
|
window["cfg_config_txt"].update(bos_config_convert(config))
|
||||||
|
|
||||||
|
|
||||||
|
async def generate_config_ui():
|
||||||
|
generate_config_window = sg.Window(
|
||||||
|
"Generate Config", generate_config_layout(), modal=True
|
||||||
|
)
|
||||||
|
while True:
|
||||||
|
event, values = generate_config_window.read()
|
||||||
|
if event in (None, "Close", sg.WIN_CLOSED):
|
||||||
|
break
|
||||||
|
if event == "generate_config_window_generate":
|
||||||
|
if values["generate_config_window_username"]:
|
||||||
|
generate_config(
|
||||||
|
values["generate_config_window_username"],
|
||||||
|
values["generate_config_window_workername"],
|
||||||
|
values["generate_config_window_allow_v2"],
|
||||||
|
)
|
||||||
|
generate_config_window.close()
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config_layout():
|
||||||
|
config_layout = [
|
||||||
|
[
|
||||||
|
sg.Text(
|
||||||
|
"Enter your pool username and password below to generate a config for SlushPool."
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[sg.Text("")],
|
||||||
|
[
|
||||||
|
sg.Text("Username:", size=(19, 1)),
|
||||||
|
sg.InputText(
|
||||||
|
key="generate_config_window_username", do_not_clear=True, size=(45, 1)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Text("Worker Name (OPT):", size=(19, 1)),
|
||||||
|
sg.InputText(
|
||||||
|
key="generate_config_window_workername", do_not_clear=True, size=(45, 1)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Text("Allow Stratum V2?:", size=(19, 1)),
|
||||||
|
sg.Checkbox("", key="generate_config_window_allow_v2", default=True),
|
||||||
|
],
|
||||||
|
[sg.Button("Generate", key="generate_config_window_generate")],
|
||||||
|
]
|
||||||
|
return config_layout
|
||||||
@@ -269,7 +269,7 @@ def get_config_layout():
|
|||||||
expand_x=True,
|
expand_x=True,
|
||||||
enable_click_events=True,
|
enable_click_events=True,
|
||||||
),
|
),
|
||||||
sg.Multiline(size=(40, TABLE_HEIGHT + 1)),
|
sg.Multiline(size=(40, TABLE_HEIGHT + 1), key="cfg_config_txt"),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
return config_layout
|
return config_layout
|
||||||
|
|||||||
@@ -80,13 +80,13 @@ async def import_config_file(file_location):
|
|||||||
else:
|
else:
|
||||||
async with aiofiles.open(file_location, mode="r") as file:
|
async with aiofiles.open(file_location, mode="r") as file:
|
||||||
config = await file.read()
|
config = await file.read()
|
||||||
await update_ui_with_data("config", await bos_config_convert(toml.loads(config)))
|
await update_ui_with_data("config", bos_config_convert(toml.loads(config)))
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
|
|
||||||
|
|
||||||
async def export_config_file(file_location, config):
|
async def export_config_file(file_location, config):
|
||||||
await update_ui_with_data("status", "Exporting")
|
await update_ui_with_data("status", "Exporting")
|
||||||
config = toml.dumps(await general_config_convert_bos(config))
|
config = toml.dumps(general_config_convert_bos(config))
|
||||||
config = toml.loads(config)
|
config = toml.loads(config)
|
||||||
config["format"]["generator"] = "upstream_config_util"
|
config["format"]["generator"] = "upstream_config_util"
|
||||||
config["format"]["timestamp"] = int(time.time())
|
config["format"]["timestamp"] = int(time.time())
|
||||||
|
|||||||
@@ -580,4 +580,4 @@ async def generate_config(username, workername, v2_allowed):
|
|||||||
},
|
},
|
||||||
"autotuning": {"enabled": True, "psu_power_limit": 900},
|
"autotuning": {"enabled": True, "psu_power_limit": 900},
|
||||||
}
|
}
|
||||||
window["config"].update(await bos_config_convert(config))
|
window["config"].update(bos_config_convert(config))
|
||||||
|
|||||||
Reference in New Issue
Block a user