reformatted all files to use the Black formatting style

This commit is contained in:
UpstreamData
2022-03-31 11:27:57 -06:00
parent e1383f2002
commit c57a523553
54 changed files with 1375 additions and 964 deletions

View File

@@ -4,14 +4,15 @@ import toml
from config.bos import bos_config_convert, general_config_convert_bos
import logging
class BOSMiner(BaseMiner):
def __init__(self, ip: str) -> None:
api = BOSMinerAPI(ip)
super().__init__(ip, api)
self.model = None
self.config = None
self.uname = 'root'
self.pwd = 'admin'
self.uname = "root"
self.pwd = "admin"
self.nominal_chips = 63
def __repr__(self) -> str:
@@ -39,13 +40,13 @@ class BOSMiner(BaseMiner):
async def fault_light_on(self) -> None:
"""Sends command to turn on fault light on the miner."""
logging.debug(f"{self}: Sending fault_light on command.")
await self.send_ssh_command('miner fault_light on')
await self.send_ssh_command("miner fault_light on")
logging.debug(f"{self}: fault_light on command completed.")
async def fault_light_off(self) -> None:
"""Sends command to turn off fault light on the miner."""
logging.debug(f"{self}: Sending fault_light off command.")
await self.send_ssh_command('miner fault_light off')
await self.send_ssh_command("miner fault_light off")
logging.debug(f"{self}: fault_light off command completed.")
async def restart_backend(self):
@@ -54,7 +55,7 @@ class BOSMiner(BaseMiner):
async def restart_bosminer(self) -> None:
"""Restart bosminer hashing process."""
logging.debug(f"{self}: Sending bosminer restart command.")
await self.send_ssh_command('/etc/init.d/bosminer restart')
await self.send_ssh_command("/etc/init.d/bosminer restart")
logging.debug(f"{self}: bosminer restart command completed.")
async def reboot(self) -> None:
@@ -69,7 +70,7 @@ class BOSMiner(BaseMiner):
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Reading config file.")
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())
logging.debug(f"{self}: Converting config file.")
cfg = await bos_config_convert(toml_data)
@@ -80,7 +81,7 @@ class BOSMiner(BaseMiner):
try:
async with (await self._get_ssh_connection()) as conn:
if conn is not None:
data = await conn.run('cat /proc/sys/kernel/hostname')
data = await conn.run("cat /proc/sys/kernel/hostname")
host = data.stdout.strip()
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
@@ -98,7 +99,9 @@ class BOSMiner(BaseMiner):
version_data = await self.api.devdetails()
if version_data:
if not version_data["DEVDETAILS"] == []:
self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "")
self.model = version_data["DEVDETAILS"][0]["Model"].replace(
"Antminer ", ""
)
logging.debug(f"Found model for {self.ip}: {self.model} (BOS)")
return self.model + " (BOS)"
logging.warning(f"Failed to get model for miner: {self}")
@@ -112,7 +115,7 @@ class BOSMiner(BaseMiner):
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Opening config file.")
async with sftp.open('/etc/bosminer.toml', 'w+') as file:
async with sftp.open("/etc/bosminer.toml", "w+") as file:
await file.write(toml_conf)
logging.debug(f"{self}: Restarting BOSMiner")
await conn.run("/etc/init.d/bosminer restart")
@@ -124,21 +127,23 @@ class BOSMiner(BaseMiner):
if not devdetails.get("DEVDETAILS"):
print("devdetails error", devdetails)
return {0: [], 1: [], 2: []}
devs = devdetails['DEVDETAILS']
devs = devdetails["DEVDETAILS"]
boards = {}
offset = devs[0]["ID"]
for board in devs:
boards[board["ID"] - offset] = []
if not board['Chips'] == self.nominal_chips:
if not board["Chips"] == self.nominal_chips:
nominal = False
else:
nominal = True
boards[board["ID"] - offset].append({
"chain": board["ID"] - offset,
"chip_count": board['Chips'],
"chip_status": "o" * board['Chips'],
"nominal": nominal
})
boards[board["ID"] - offset].append(
{
"chain": board["ID"] - offset,
"chip_count": board["Chips"],
"chip_status": "o" * board["Chips"],
"nominal": nominal,
}
)
logging.debug(f"Found board data for {self}: {boards}")
return boards
@@ -158,9 +163,9 @@ class BOSMiner(BaseMiner):
"""Checks for and provides list for working boards."""
devs = await self.api.devdetails()
bad = 0
chains = devs['DEVDETAILS']
chains = devs["DEVDETAILS"]
for chain in chains:
if chain['Chips'] == 0:
if chain["Chips"] == 0:
bad += 1
if not bad > 0:
return str(self.ip)