Skip to content

Commit 1f3b306

Browse files
committed
Added job listing command
1 parent 41b5415 commit 1f3b306

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/instrumentman/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from . import protocoltest
1313
from . import inclination
1414
from . import filetransfer
15+
from . import jobs
1516

1617

1718
@extra_group("iman", params=None) # type: ignore[misc]
@@ -76,4 +77,5 @@ def cli_download() -> None:
7677
cli_validate.add_command(setmeasurement.cli_validate)
7778
cli_import.add_command(setup.cli_import)
7879
cli_list.add_command(filetransfer.cli_list)
80+
cli_list.add_command(jobs.cli_list)
7981
cli_download.add_command(filetransfer.cli_download)

src/instrumentman/jobs/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any
2+
3+
from click_extra import extra_command
4+
5+
from ..utils import (
6+
com_option_group,
7+
com_port_argument
8+
)
9+
10+
11+
@extra_command(
12+
"jobs",
13+
params=None,
14+
context_settings={"auto_envvar_prefix": None}
15+
) # type: ignore[misc]
16+
@com_port_argument()
17+
@com_option_group()
18+
def cli_list(**kwargs: Any) -> None:
19+
"""List job files on an instrument."""
20+
from .app import main_list
21+
22+
main_list(**kwargs)

src/instrumentman/jobs/app.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from click_extra import echo
2+
from geocompy.communication import open_serial
3+
from geocompy.geo import GeoCom
4+
from geocompy.geo.gctypes import GeoComCode
5+
6+
from ..utils import echo_red, echo_yellow
7+
8+
9+
def run_listing(tps: GeoCom) -> None:
10+
resp_setup = tps.csv.setup_listing()
11+
if resp_setup.error != GeoComCode.OK:
12+
echo_red(f"Could not set up job listing ({resp_setup.error.name})")
13+
return
14+
15+
resp_list = tps.csv.list()
16+
if resp_list.error != GeoComCode.OK or resp_list.params is None:
17+
echo_red(f"Could not start listing ({resp_list.error.name})")
18+
return
19+
20+
job, file, _, _, _ = resp_list.params
21+
if job == "" or file == "":
22+
echo_yellow("No jobs were found")
23+
return
24+
25+
count = 1
26+
echo(f"{'job name':<50.50s}{'file name':<50.50s}")
27+
echo(f"{'--------':<50.50s}{'---------':<50.50s}")
28+
fmt = "{job:<50.50s}{file:<50.50s}"
29+
echo(
30+
fmt.format_map(
31+
{
32+
"job": job,
33+
"file": file
34+
}
35+
)
36+
)
37+
while True:
38+
resp_list = tps.csv.list()
39+
if resp_list.error != GeoComCode.OK or resp_list.params is None:
40+
break
41+
42+
job, file, _, _, _ = resp_list.params
43+
echo(
44+
fmt.format_map(
45+
{
46+
"job": job,
47+
"file": file
48+
}
49+
)
50+
)
51+
count += 1
52+
53+
echo("-" * 90)
54+
echo(f"total: {count} files")
55+
56+
57+
def main_list(
58+
port: str,
59+
baud: int = 9600,
60+
timeout: int = 15,
61+
retry: int = 1,
62+
sync_after_timeout: bool = False
63+
) -> None:
64+
with open_serial(
65+
port=port,
66+
speed=baud,
67+
timeout=timeout,
68+
retry=retry,
69+
sync_after_timeout=sync_after_timeout
70+
) as com:
71+
tps = GeoCom(com)
72+
run_listing(tps)

0 commit comments

Comments
 (0)