From 247362ca75e4231209b8f6841d9ca309c3e398d9 Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Wed, 15 Dec 2021 10:56:02 -0700 Subject: [PATCH] added export IPlist --- cfg_util/func/__init__.py | 17 +++++++++++++++++ cfg_util/layout.py | 2 +- cfg_util/ui.py | 4 +++- tests.py | 1 - 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cfg_util/func/__init__.py b/cfg_util/func/__init__.py index 3349954a..0be976b5 100644 --- a/cfg_util/func/__init__.py +++ b/cfg_util/func/__init__.py @@ -76,6 +76,23 @@ async def import_iplist(file_location): await update_ui_with_data("status", "") +async def export_iplist(file_location, ip_list_selected): + await update_ui_with_data("status", "Exporting") + if not os.path.exists(file_location): + return + else: + if ip_list_selected is not None and not ip_list_selected == []: + async with aiofiles.open(file_location, mode='w') as file: + for item in ip_list_selected: + await file.write(str(item) + "\n") + else: + async with aiofiles.open(file_location, mode='w') as file: + for item in window['ip_list'].Values: + await file.write(str(item) + "\n") + await update_ui_with_data("status", "") + + + async def send_config(ips: list, config): await update_ui_with_data("status", "Configuring") tasks = [] diff --git a/cfg_util/layout.py b/cfg_util/layout.py index 34d1c515..8b23d24c 100644 --- a/cfg_util/layout.py +++ b/cfg_util/layout.py @@ -6,7 +6,7 @@ layout = [ sg.Button('Scan', key='scan'), sg.Text("", key="status")], [sg.Text('IP List File: '), sg.Input(key="file_iplist", do_not_clear=True, size=(110, 1)), sg.FileBrowse(), - sg.Button('Import', key="import_iplist")], + sg.Button('Import', key="import_iplist"), sg.Button('Export', key="export_iplist")], [sg.Text('Config File: '), sg.Input(key="file_config", do_not_clear=True, size=(110, 1)), sg.FileBrowse(), sg.Button('Import', key="import_file_config"), sg.Button('Export', key="export_file_config")], [ diff --git a/cfg_util/ui.py b/cfg_util/ui.py index a37e5853..429dbc16 100644 --- a/cfg_util/ui.py +++ b/cfg_util/ui.py @@ -3,7 +3,7 @@ import sys from cfg_util.layout import window from cfg_util.func import scan_network, sort_data, send_config, miner_light, get_data, export_config_file, \ - generate_config, import_config, import_iplist, import_config_file + generate_config, import_config, import_iplist, import_config_file, export_iplist from network import MinerNetwork @@ -32,6 +32,8 @@ async def ui(): asyncio.create_task(miner_light(value['ip_list'])) if event == "import_iplist": asyncio.create_task(import_iplist(value["file_iplist"])) + if event == "export_iplist": + asyncio.create_task(export_iplist(value["file_iplist"], value['ip_list'])) if event == "send_config": asyncio.create_task(send_config(value['ip_list'], value['config'])) if event == "import_file_config": diff --git a/tests.py b/tests.py index 0b6a26db..b3237561 100644 --- a/tests.py +++ b/tests.py @@ -4,7 +4,6 @@ import asyncio from API.bosminer import BOSMinerAPI from API.cgminer import CGMinerAPI import sys -from cfg_util.func.data import safe_parse_api_data # Fix bug with some whatsminers and asyncio because of a socket not being shut down: