Skip to content

Commit 993259f

Browse files
committed
- improve debug logging
- fix issues encountered with PR #11 - fix readme file
1 parent b764a8d commit 993259f

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ Please, use the format:
1515

1616
## [Unreleased]
1717

18-
- beta-builder: automatically publish beta packages into pypi from main branch
18+
- beta-builder: automatically publish beta packages into pypi from main branch
19+
- improve debug logging
20+
- fix issues encountered with PR #11

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# LuxOS Tools Repository
22

3-
> **WARNING** There are references into the PR luxos-code-refactoring
4-
53
This repository contains scripts we built to operate and troubleshoot miners running LuxOS.
64

75
## Install
@@ -11,14 +9,14 @@ There are few ways to install the luxos package:
119
1. Using pip (suggested for end-users):
1210
```shell
1311
pip install luxos
14-
pip install git+https://github.com/LuxorLabs/luxos-tooling.git@pr/luxos-code-refactoring
12+
pip install git+https://github.com/LuxorLabs/luxos-tooling.git
1513
```
1614
Using pip gives you access to the cli commands `luxos` and `health-checker` as well
1715
the ability to import in python the `import luxos.api` api for luxos.
1816

1917
2. A single drop in file (for support):
2018
```shell
21-
curl -LO https://github.com/LuxorLabs/luxos-tooling/raw/pr/luxos-code-refactoring/luxos.pyz
19+
curl -LO https://github.com/LuxorLabs/luxos-tooling/raw/luxos.pyz
2220
```
2321
These are two standalone [zipapp](https://docs.python.org/3/library/zipapp.html) files, you can use
2422
from the command line as `python luxos.pyz`, no dependencies beside a recent-*ish* python

make.pyz

22.1 KB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "luxos"
7-
version = "0.0.0"
7+
version = "0.0.1"
88
description = "The all encompassing LuxOS python library."
99
readme = "README.md"
1010
license = { text = "MIT" } # TODO I don't think this is a MIT??

src/luxos/asyncops.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def somcode(host: str, port: int, ...):
3030
e.address
3131
raise MyNewExecption() from e <- this will re-raise
3232
"""
33+
3334
@functools.wraps(function)
3435
async def _function(host: str, port: int, *args, **kwargs):
3536
try:
@@ -43,6 +44,7 @@ async def _function(host: str, port: int, *args, **kwargs):
4344
# we augment any other exception with (host, port) info
4445
log.exception("internal error")
4546
raise exceptions.MinerConnectionError(host, port, "internal error") from e
47+
4648
return _function
4749

4850

@@ -75,6 +77,7 @@ async def _roundtrip(
7577

7678
return response.decode()
7779

80+
7881
# TODO add annotations
7982
async def roundtrip(
8083
host: str,
@@ -131,7 +134,9 @@ def validate_message(
131134
for key in ["STATUS", "id", *([extrakey] if extrakey else [])]:
132135
if key in res:
133136
continue
134-
raise exceptions.MinerCommandMalformedMessageError(host, port, f"missing {key} from logon message", res)
137+
raise exceptions.MinerCommandMalformedMessageError(
138+
host, port, f"missing {key} from logon message", res
139+
)
135140

136141
if not extrakey or not (minfields or maxfields):
137142
return res
@@ -157,13 +162,17 @@ async def logon(host: str, port: int, timeout: float | None = 3) -> str:
157162
# on subsequent logon, we receive a
158163
# [STATUS][Msg] == "Another session is active" ([STATUS][Code] 402)
159164
if "SESSION" not in res and res.get("STATUS", [{}])[0].get("Code") == 402:
160-
raise exceptions.MinerCommandSessionAlreadyActive(host, port, "connection active", res)
165+
raise exceptions.MinerCommandSessionAlreadyActive(
166+
host, port, "connection active", res
167+
)
161168
sessions = validate_message(host, port, res, "SESSION", 1, 1)
162169

163170
session = sessions[0] # type: ignore
164171

165172
if "SessionID" not in session:
166-
raise exceptions.MinerCommandSessionAlreadyActive(host, port, "no SessionID in data", res)
173+
raise exceptions.MinerCommandSessionAlreadyActive(
174+
host, port, "no SessionID in data", res
175+
)
167176
return str(session["SessionID"])
168177

169178

@@ -184,7 +193,7 @@ async def execute_command(
184193
parameters: list[str] | None = None,
185194
verbose: bool = False,
186195
asjson: bool | None = True,
187-
add_address: bool = False
196+
add_address: bool = False,
188197
) -> tuple[tuple[str, int], dict[str, Any]] | dict[str, Any]:
189198
timeout = TIMEOUT if timeout_sec is None else timeout_sec
190199
parameters = parameters or []
@@ -195,13 +204,21 @@ async def execute_command(
195204
parameters = [sid, *parameters]
196205
log.info("session id requested & obtained for %s:%i (%s)", host, port, sid)
197206
else:
198-
log.debug("no logon required for command %s on %s:%i", cmd, host, port)
207+
log.debug("no logon required for command '%s' on %s:%i", cmd, host, port)
199208

200209
try:
201210
packet = {"command": cmd}
202211
if parameters:
203212
packet["parameter"] = ",".join(parameters)
213+
log.debug(
214+
"executing command '%s' on '%s:%i' with parameters: %s",
215+
cmd,
216+
host,
217+
port,
218+
packet.get("parameter", ""),
219+
)
204220
ret = await roundtrip(host, port, packet, timeout, asjson=asjson)
221+
log.debug("received from %s:%s: %s", host, port, str(ret))
205222
return ((host, port), ret) if add_address else ret
206223
finally:
207224
if sid:

src/luxos/scripts/async_luxos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
async def run(
10-
ip_list: list[str],
10+
ipaddresses: list[str],
1111
port: int,
1212
cmd: str,
1313
params: list[str],
@@ -20,7 +20,7 @@ async def run(
2020
batchsize = max(batchsize, 2)
2121

2222
for grupid, addresses in enumerate(
23-
misc.batched([(ip, port) for ip in ip_list], n=batchsize)
23+
misc.batched([(ip, port) for ip in ipaddresses], n=batchsize)
2424
):
2525
tasks = []
2626
for host, port in addresses:
@@ -40,7 +40,7 @@ async def run(
4040
failures = [task for task in alltasks if isinstance(task, Exception)]
4141

4242
# print a nice report
43-
print(f"task executed sucessfully: {len(successes)}")
43+
print(f"task executed sucessfully (use -a|--all for details): {len(successes)}")
4444
if details:
4545
for (host, port), task in successes: # type: ignore
4646
print(f" > {host}:{port}")

src/luxos/scripts/luxos.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ def main():
270270
parser.add_argument(
271271
"--port", required=False, default=4028, type=int, help="Port for LuxOS API"
272272
)
273-
parser.add_argument(
274-
"--verbose", required=False, default=False, type=bool, help="Verbose output"
275-
)
273+
parser.add_argument("--verbose", action="store_true", help="Verbose output")
276274
parser.add_argument(
277275
"--batch_delay",
278276
required=False,
@@ -326,7 +324,7 @@ def main():
326324

327325
asyncio.run(
328326
async_luxos.run(
329-
ipaddress=ip_list,
327+
ipaddresses=ip_list,
330328
port=args.port,
331329
cmd=args.cmd,
332330
params=args.params,

0 commit comments

Comments
 (0)