added configuration button
This commit is contained in:
@@ -4,7 +4,11 @@ import sys
|
||||
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.commands import btn_light
|
||||
from tools.cfg_util.cfg_util_qt.configure import generate_config_ui, btn_import
|
||||
from tools.cfg_util.cfg_util_qt.configure import (
|
||||
generate_config_ui,
|
||||
btn_import,
|
||||
btn_config,
|
||||
)
|
||||
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.tables import TableManager
|
||||
@@ -50,7 +54,7 @@ async def main():
|
||||
_table = "scan_table"
|
||||
asyncio.create_task(btn_refresh(_table, value[_table]))
|
||||
if event == "btn_scan":
|
||||
await btn_scan(value["scan_ip"])
|
||||
asyncio.create_task(btn_scan(value["scan_ip"]))
|
||||
|
||||
# pools tab
|
||||
if event == "pools_all":
|
||||
@@ -74,7 +78,17 @@ async def main():
|
||||
await generate_config_ui()
|
||||
if event == "cfg_import":
|
||||
_table = "cfg_table"
|
||||
await btn_import(_table, value[_table])
|
||||
asyncio.create_task(btn_import(_table, value[_table]))
|
||||
if event == "cfg_config":
|
||||
_table = "cfg_table"
|
||||
asyncio.create_task(
|
||||
btn_config(
|
||||
_table,
|
||||
value[_table],
|
||||
value["cfg_config_txt"],
|
||||
value["cfg_append_ip"],
|
||||
)
|
||||
)
|
||||
|
||||
# commands tab
|
||||
if event == "cmd_all":
|
||||
@@ -84,7 +98,7 @@ async def main():
|
||||
if event == "cmd_light":
|
||||
_table = "cmd_table"
|
||||
_ips = value[_table]
|
||||
await btn_light(_ips)
|
||||
asyncio.create_task(btn_light(_ips))
|
||||
|
||||
if event == "__TIMEOUT__":
|
||||
await asyncio.sleep(0)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import PySimpleGUI as sg
|
||||
from config.bos import bos_config_convert
|
||||
import time
|
||||
from tools.cfg_util.cfg_util_qt.layout import window
|
||||
from tools.cfg_util.cfg_util_qt.layout import window, update_prog_bar
|
||||
from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
|
||||
from miners.miner_factory import MinerFactory
|
||||
import asyncio
|
||||
from settings import CFG_UTIL_CONFIG_THREADS as CONFIG_THREADS
|
||||
from tools.cfg_util.cfg_util_qt.general import update_miners_data
|
||||
|
||||
|
||||
progress_bar_len = 0
|
||||
|
||||
|
||||
@disable_buttons
|
||||
@@ -17,6 +23,50 @@ async def btn_import(table, selected):
|
||||
window["cfg_config_txt"].update(config)
|
||||
|
||||
|
||||
@disable_buttons
|
||||
async def btn_config(table, selected, config: str, last_oct_ip: bool):
|
||||
ips = [window[table].Values[row][0] for row in selected]
|
||||
await send_config(ips, config, last_oct_ip)
|
||||
|
||||
|
||||
async def send_config(ips: list, config: str, last_octet_ip: bool):
|
||||
global progress_bar_len
|
||||
progress_bar_len = 0
|
||||
await update_prog_bar(progress_bar_len, max=(2 * len(ips)))
|
||||
get_miner_genenerator = MinerFactory().get_miner_generator(ips)
|
||||
all_miners = []
|
||||
async for miner in get_miner_genenerator:
|
||||
all_miners.append(miner)
|
||||
progress_bar_len += 1
|
||||
await update_prog_bar(progress_bar_len)
|
||||
|
||||
config_sender_generator = send_config_generator(
|
||||
all_miners, config, last_octet_ip_user=last_octet_ip
|
||||
)
|
||||
async for _config_sender in config_sender_generator:
|
||||
progress_bar_len += 1
|
||||
await update_prog_bar(progress_bar_len)
|
||||
await asyncio.sleep(3)
|
||||
await update_miners_data(ips)
|
||||
|
||||
|
||||
async def send_config_generator(miners: list, config, last_octet_ip_user: bool):
|
||||
loop = asyncio.get_event_loop()
|
||||
config_tasks = []
|
||||
for miner in miners:
|
||||
if len(config_tasks) >= CONFIG_THREADS:
|
||||
configured = asyncio.as_completed(config_tasks)
|
||||
config_tasks = []
|
||||
for sent_config in configured:
|
||||
yield await sent_config
|
||||
config_tasks.append(
|
||||
loop.create_task(miner.send_config(config, ip_user=last_octet_ip_user))
|
||||
)
|
||||
configured = asyncio.as_completed(config_tasks)
|
||||
for sent_config in configured:
|
||||
yield await sent_config
|
||||
|
||||
|
||||
def generate_config(username: str, workername: str, v2_allowed: bool):
|
||||
if username and workername:
|
||||
user = f"{username}.{workername}"
|
||||
|
||||
@@ -54,10 +54,10 @@ async def btn_refresh(table, selected):
|
||||
if not len(selected) > 0:
|
||||
ips = [window[table].Values[row][0] for row in range(len(window[table].Values))]
|
||||
|
||||
await _get_miners_data(ips)
|
||||
await update_miners_data(ips)
|
||||
|
||||
|
||||
async def _get_miners_data(miners: list):
|
||||
async def update_miners_data(miners: list):
|
||||
data = []
|
||||
for miner in miners:
|
||||
_data = {}
|
||||
|
||||
@@ -82,11 +82,13 @@ TABLE_TOTAL_WIDTH = sum(SCAN_COL_WIDTHS)
|
||||
async def update_prog_bar(count: int, max: int = None):
|
||||
bar = window["progress_bar"]
|
||||
bar.update_bar(count, max=max)
|
||||
if max:
|
||||
bar.maxlen = max
|
||||
if not hasattr(bar, "maxlen"):
|
||||
if not max:
|
||||
max = 100
|
||||
if max:
|
||||
bar.maxlen = max
|
||||
|
||||
percent_done = 100 * (count / bar.maxlen)
|
||||
window["progress_percent"].Update(f"{round(percent_done, 2)} %")
|
||||
if percent_done == 100:
|
||||
|
||||
Reference in New Issue
Block a user