diracx-cli 0.0.1a14__py3-none-any.whl → 0.0.1a16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diracx/cli/jobs.py +48 -10
- diracx/cli/utils.py +9 -1
- {diracx_cli-0.0.1a14.dist-info → diracx_cli-0.0.1a16.dist-info}/METADATA +1 -1
- {diracx_cli-0.0.1a14.dist-info → diracx_cli-0.0.1a16.dist-info}/RECORD +7 -7
- {diracx_cli-0.0.1a14.dist-info → diracx_cli-0.0.1a16.dist-info}/WHEEL +0 -0
- {diracx_cli-0.0.1a14.dist-info → diracx_cli-0.0.1a16.dist-info}/entry_points.txt +0 -0
- {diracx_cli-0.0.1a14.dist-info → diracx_cli-0.0.1a16.dist-info}/top_level.txt +0 -0
diracx/cli/jobs.py
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
__all__ = ("app",)
|
|
5
5
|
|
|
6
6
|
import json
|
|
7
|
-
|
|
7
|
+
import re
|
|
8
|
+
from typing import Annotated, cast
|
|
8
9
|
|
|
9
10
|
from rich.console import Console
|
|
10
11
|
from rich.table import Table
|
|
@@ -52,29 +53,66 @@ async def search(
|
|
|
52
53
|
],
|
|
53
54
|
condition: Annotated[list[SearchSpec], Option(parser=parse_condition)] = [],
|
|
54
55
|
all: bool = False,
|
|
56
|
+
page: int = 1,
|
|
57
|
+
per_page: int = 10,
|
|
55
58
|
):
|
|
56
59
|
async with DiracClient() as api:
|
|
57
|
-
jobs = await api.jobs.search(
|
|
60
|
+
jobs, content_range = await api.jobs.search(
|
|
58
61
|
parameters=None if all else parameter,
|
|
59
62
|
search=condition if condition else None,
|
|
63
|
+
page=page,
|
|
64
|
+
per_page=per_page,
|
|
65
|
+
cls=lambda _, jobs, headers: (
|
|
66
|
+
jobs,
|
|
67
|
+
ContentRange(headers.get("Content-Range", "jobs")),
|
|
68
|
+
),
|
|
60
69
|
)
|
|
61
|
-
display(jobs, "jobs")
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
display(jobs, cast(ContentRange, content_range))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ContentRange:
|
|
75
|
+
unit: str | None = None
|
|
76
|
+
start: int | None = None
|
|
77
|
+
end: int | None = None
|
|
78
|
+
total: int | None = None
|
|
79
|
+
|
|
80
|
+
def __init__(self, header: str):
|
|
81
|
+
if match := re.fullmatch(r"(\w+) (\d+-\d+|\*)/(\d+|\*)", header):
|
|
82
|
+
self.unit, range, total = match.groups()
|
|
83
|
+
self.total = int(total)
|
|
84
|
+
if range != "*":
|
|
85
|
+
self.start, self.end = map(int, range.split("-"))
|
|
86
|
+
elif match := re.fullmatch(r"\w+", header):
|
|
87
|
+
self.unit = match.group()
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def caption(self):
|
|
91
|
+
if self.start is None and self.end is None:
|
|
92
|
+
range_str = "all"
|
|
93
|
+
else:
|
|
94
|
+
range_str = (
|
|
95
|
+
f"{self.start if self.start is not None else 'unknown'}-"
|
|
96
|
+
f"{self.end if self.end is not None else 'unknown'} "
|
|
97
|
+
f"of {self.total or 'unknown'}"
|
|
98
|
+
)
|
|
99
|
+
return f"Showing {range_str} {self.unit}"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def display(data, content_range: ContentRange):
|
|
65
103
|
output_format = get_diracx_preferences().output_format
|
|
66
104
|
match output_format:
|
|
67
105
|
case OutputFormats.JSON:
|
|
68
106
|
print(json.dumps(data, indent=2))
|
|
69
107
|
case OutputFormats.RICH:
|
|
70
|
-
display_rich(data,
|
|
108
|
+
display_rich(data, content_range)
|
|
71
109
|
case _:
|
|
72
110
|
raise NotImplementedError(output_format)
|
|
73
111
|
|
|
74
112
|
|
|
75
|
-
def display_rich(data,
|
|
113
|
+
def display_rich(data, content_range: ContentRange) -> None:
|
|
76
114
|
if not data:
|
|
77
|
-
print(f"No {unit} found")
|
|
115
|
+
print(f"No {content_range.unit} found")
|
|
78
116
|
return
|
|
79
117
|
|
|
80
118
|
console = Console()
|
|
@@ -83,7 +121,7 @@ def display_rich(data, unit: str) -> None:
|
|
|
83
121
|
table = Table(
|
|
84
122
|
"Parameter",
|
|
85
123
|
"Value",
|
|
86
|
-
caption=
|
|
124
|
+
caption=content_range.caption,
|
|
87
125
|
caption_justify="right",
|
|
88
126
|
)
|
|
89
127
|
for job in data:
|
|
@@ -93,7 +131,7 @@ def display_rich(data, unit: str) -> None:
|
|
|
93
131
|
else:
|
|
94
132
|
table = Table(
|
|
95
133
|
*columns,
|
|
96
|
-
caption=
|
|
134
|
+
caption=content_range.caption,
|
|
97
135
|
caption_justify="right",
|
|
98
136
|
)
|
|
99
137
|
for job in data:
|
diracx/cli/utils.py
CHANGED
|
@@ -6,6 +6,8 @@ from asyncio import run
|
|
|
6
6
|
from functools import wraps
|
|
7
7
|
|
|
8
8
|
import typer
|
|
9
|
+
from azure.core.exceptions import ClientAuthenticationError
|
|
10
|
+
from rich import print
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
class AsyncTyper(typer.Typer):
|
|
@@ -13,7 +15,13 @@ class AsyncTyper(typer.Typer):
|
|
|
13
15
|
def decorator(async_func):
|
|
14
16
|
@wraps(async_func)
|
|
15
17
|
def sync_func(*_args, **_kwargs):
|
|
16
|
-
|
|
18
|
+
try:
|
|
19
|
+
return run(async_func(*_args, **_kwargs))
|
|
20
|
+
except ClientAuthenticationError:
|
|
21
|
+
print(
|
|
22
|
+
":x: [bold red]You are not authenticated. Log in with:[/bold red] "
|
|
23
|
+
"[bold] dirac login [OPTIONS] [VO] [/bold]"
|
|
24
|
+
)
|
|
17
25
|
|
|
18
26
|
self.command(*args, **kwargs)(sync_func)
|
|
19
27
|
return async_func
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
diracx/cli/__init__.py,sha256=HI6-8S6JFU4hjX7DHy9c4jwUp7PVKwCxflcJCqqtu3M,4059
|
|
2
2
|
diracx/cli/__main__.py,sha256=SM9tEc-fiW7cDHTKQRwgKobe5FfijHLYiAWfWaIM_zg,56
|
|
3
3
|
diracx/cli/config.py,sha256=r5Lq_SN-1t3IzGAeS57ZzS-ukLhP6PMnmTXNld2pZXU,818
|
|
4
|
-
diracx/cli/jobs.py,sha256=
|
|
4
|
+
diracx/cli/jobs.py,sha256=H1aQGFjaVLG2BShZO0cU3103QiuD1DR81cpm7drQ5Fs,4419
|
|
5
5
|
diracx/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
diracx/cli/utils.py,sha256=
|
|
6
|
+
diracx/cli/utils.py,sha256=NwhMMHwveKOdW2aoSqpnLnfOKhPnjmPPLpX69naPAzc,855
|
|
7
7
|
diracx/cli/internal/__init__.py,sha256=17PDFFNhppYPPq6KPmMxnOG3N6sP3apewpk8VjjHTYY,6041
|
|
8
8
|
diracx/cli/internal/legacy.py,sha256=qiO73vIh2LPM6jma6G2RcLINwX6ZP5i1rhYBVMMYOuE,10849
|
|
9
|
-
diracx_cli-0.0.
|
|
10
|
-
diracx_cli-0.0.
|
|
11
|
-
diracx_cli-0.0.
|
|
12
|
-
diracx_cli-0.0.
|
|
13
|
-
diracx_cli-0.0.
|
|
9
|
+
diracx_cli-0.0.1a16.dist-info/METADATA,sha256=T-3BwwSBhj85cqTxaHIkyC3bS9VATqkIxGkdZ2Ae09w,792
|
|
10
|
+
diracx_cli-0.0.1a16.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
11
|
+
diracx_cli-0.0.1a16.dist-info/entry_points.txt,sha256=pKKS950WHHoO6teZZXkWztX2XZFZSH6uh9BKY1PA-jg,41
|
|
12
|
+
diracx_cli-0.0.1a16.dist-info/top_level.txt,sha256=vJx10tdRlBX3rF2Psgk5jlwVGZNcL3m_7iQWwgPXt-U,7
|
|
13
|
+
diracx_cli-0.0.1a16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|