slurm-cli 1.0.2__tar.gz → 1.0.5__tar.gz
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.
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/PKG-INFO +20 -1
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/README.md +18 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/pyproject.toml +1 -1
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/cli.py +10 -10
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/accounts.py +4 -5
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/associations.py +4 -5
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/jobs.py +3 -3
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/nodes.py +5 -7
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/partitions.py +5 -7
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/prefix_utils.py +3 -3
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/profiles.py +47 -10
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/qos.py +3 -6
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/reservations.py +7 -6
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/LICENSE +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/__init__.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/py.typed +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/__init__.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/autocomplete_helpers.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/base_resource.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/config.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/coordinators.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/events.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/job_filter.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/node_filter.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/resources.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/slurm_config.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/users.py +0 -0
- {slurm_cli-1.0.2 → slurm_cli-1.0.5}/src/slurm_cli/utils/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: slurm-cli
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.5
|
|
4
4
|
Summary: A CLI tool for Slurm cluster management with autocomplete functionality
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -24,6 +24,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
24
24
|
Classifier: Programming Language :: Python :: 3.12
|
|
25
25
|
Classifier: Programming Language :: Python :: 3.13
|
|
26
26
|
Classifier: Programming Language :: Python :: 3.14
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
27
28
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
29
|
Classifier: Topic :: System :: Clustering
|
|
29
30
|
Classifier: Topic :: System :: Systems Administration
|
|
@@ -121,6 +122,24 @@ _CLICK_COMPLETE=bash_source slurm-cli > \
|
|
|
121
122
|
~/.local/share/bash-completion/completions/slurm-cli
|
|
122
123
|
```
|
|
123
124
|
|
|
125
|
+
## Claude Code Skill
|
|
126
|
+
|
|
127
|
+
slurm-cli ships a [Claude Code](https://claude.com/claude-code) skill (`slurm-cli-skill.md`) that teaches Claude how to construct correct `slurm-cli` commands — verbs/resources, filter syntax, output formats, and caching flags.
|
|
128
|
+
|
|
129
|
+
Install it by copying the file into a skills directory:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Project-local
|
|
133
|
+
mkdir -p .claude/skills
|
|
134
|
+
cp slurm-cli-skill.md .claude/skills/slurm-cli.md
|
|
135
|
+
|
|
136
|
+
# User-wide (all projects)
|
|
137
|
+
mkdir -p ~/.claude/skills
|
|
138
|
+
cp slurm-cli-skill.md ~/.claude/skills/slurm-cli.md
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Then just ask Claude things like "show running jobs for user john" or "drain the gpu partition except reserved nodes" — it will invoke the skill to build the right command. See [docs/user-guide/claude-skill.md](docs/user-guide/claude-skill.md) for details.
|
|
142
|
+
|
|
124
143
|
## Development
|
|
125
144
|
|
|
126
145
|
### Autocomplete
|
|
@@ -80,6 +80,24 @@ _CLICK_COMPLETE=bash_source slurm-cli > \
|
|
|
80
80
|
~/.local/share/bash-completion/completions/slurm-cli
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
## Claude Code Skill
|
|
84
|
+
|
|
85
|
+
slurm-cli ships a [Claude Code](https://claude.com/claude-code) skill (`slurm-cli-skill.md`) that teaches Claude how to construct correct `slurm-cli` commands — verbs/resources, filter syntax, output formats, and caching flags.
|
|
86
|
+
|
|
87
|
+
Install it by copying the file into a skills directory:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Project-local
|
|
91
|
+
mkdir -p .claude/skills
|
|
92
|
+
cp slurm-cli-skill.md .claude/skills/slurm-cli.md
|
|
93
|
+
|
|
94
|
+
# User-wide (all projects)
|
|
95
|
+
mkdir -p ~/.claude/skills
|
|
96
|
+
cp slurm-cli-skill.md ~/.claude/skills/slurm-cli.md
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then just ask Claude things like "show running jobs for user john" or "drain the gpu partition except reserved nodes" — it will invoke the skill to build the right command. See [docs/user-guide/claude-skill.md](docs/user-guide/claude-skill.md) for details.
|
|
100
|
+
|
|
83
101
|
## Development
|
|
84
102
|
|
|
85
103
|
### Autocomplete
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "slurm-cli"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.5"
|
|
4
4
|
description = "A CLI tool for Slurm cluster management with autocomplete functionality"
|
|
5
5
|
authors = ["Sergey Zhumatiy <szhumatiy@gmail.com>"]
|
|
6
6
|
maintainers = ["Sergey Zhumatiy <szhumatiy@gmail.com>"]
|
|
@@ -21,7 +21,6 @@ Note: This requires Click's completion support
|
|
|
21
21
|
which is available in Click 8.0+.
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
import importlib.metadata
|
|
25
24
|
import json
|
|
26
25
|
import os
|
|
27
26
|
import subprocess
|
|
@@ -33,6 +32,7 @@ from fast_autocomplete import AutoComplete # pyright: ignore
|
|
|
33
32
|
from rich.box import SIMPLE_HEAVY # pyright: ignore[reportMissingImports]
|
|
34
33
|
from rich.table import Table # pyright: ignore[reportMissingImports]
|
|
35
34
|
|
|
35
|
+
from . import __version__
|
|
36
36
|
from .utils.accounts import Account
|
|
37
37
|
from .utils.associations import Association
|
|
38
38
|
from .utils.autocomplete_helpers import get_common_autocomplete_functions
|
|
@@ -932,7 +932,7 @@ def register_commands() -> None:
|
|
|
932
932
|
main.add_command(update, name="update")
|
|
933
933
|
main.add_command(create, name="create")
|
|
934
934
|
main.add_command(delete, name="delete")
|
|
935
|
-
main.add_command(list_resources, name="
|
|
935
|
+
main.add_command(list_resources, name="resources")
|
|
936
936
|
main.add_command(autocomplete, name="autocomplete")
|
|
937
937
|
main.add_command(help, name="help")
|
|
938
938
|
main.add_command(version, name="version")
|
|
@@ -963,11 +963,11 @@ def register_commands() -> None:
|
|
|
963
963
|
main.add_command(suspend, name="suspend")
|
|
964
964
|
|
|
965
965
|
# Modify help text to show aliases inline
|
|
966
|
-
show.help = "Show information about Slurm resources (aliases: get)"
|
|
966
|
+
show.help = "Show information about Slurm resources (aliases: get, list, ls)"
|
|
967
967
|
update.help = "Update Slurm resource fields " "(aliases: edit, change, modify)"
|
|
968
968
|
create.help = "Create Slurm resources (aliases: new, add)"
|
|
969
969
|
delete.help = "Delete Slurm resources (aliases: remove, rm)"
|
|
970
|
-
list_resources.help = "List available Slurm
|
|
970
|
+
list_resources.help = "List available Slurm resource types"
|
|
971
971
|
version.help = "Show slurm-cli and slurmctld version (aliases: ver)"
|
|
972
972
|
reconfigure.help = "Reconfigure slurmctld (aliases: reconf, confreload)"
|
|
973
973
|
ping.help = "Ping slurmctld"
|
|
@@ -1099,7 +1099,7 @@ def show(
|
|
|
1099
1099
|
if not canonical_resource:
|
|
1100
1100
|
console.print(
|
|
1101
1101
|
f"[red]Unknown resource: {resource}[/red]\n"
|
|
1102
|
-
"Use 'slurm-cli
|
|
1102
|
+
"Use 'slurm-cli resources' to see available resources."
|
|
1103
1103
|
)
|
|
1104
1104
|
return
|
|
1105
1105
|
# Check for --profile-str=help
|
|
@@ -2819,7 +2819,7 @@ _slurm_cli_initialize_autocomplete() {{
|
|
|
2819
2819
|
COMPREPLY=($(compgen -W "--dry-run -v --verbose -h --help" -- "$cur"))
|
|
2820
2820
|
return
|
|
2821
2821
|
;;
|
|
2822
|
-
autocomplete|help|
|
|
2822
|
+
autocomplete|help|resources)
|
|
2823
2823
|
# These commands take -h/--help option
|
|
2824
2824
|
COMPREPLY=($(compgen -W "-h --help" -- "$cur"))
|
|
2825
2825
|
return
|
|
@@ -2987,7 +2987,7 @@ complete -o default -o bashdefault -o nosort -F _slurm_cli_initialize_autocomple
|
|
|
2987
2987
|
return
|
|
2988
2988
|
|
|
2989
2989
|
|
|
2990
|
-
#
|
|
2990
|
+
# resources command
|
|
2991
2991
|
@click.command(context_settings=CONTEXT_SETTINGS)
|
|
2992
2992
|
@common_options
|
|
2993
2993
|
@click.pass_context
|
|
@@ -3002,7 +3002,7 @@ def list_resources(
|
|
|
3002
3002
|
**kwargs,
|
|
3003
3003
|
) -> None:
|
|
3004
3004
|
"""List all available resource types and their fields
|
|
3005
|
-
|
|
3005
|
+
."""
|
|
3006
3006
|
zebra = get_zebra(ctx, zebra)
|
|
3007
3007
|
table = Table(
|
|
3008
3008
|
title="Available Slurm Resources",
|
|
@@ -3050,7 +3050,7 @@ def list_resources(
|
|
|
3050
3050
|
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
|
|
3051
3051
|
def version(verbose: bool = False) -> None:
|
|
3052
3052
|
"""Show version information."""
|
|
3053
|
-
_version =
|
|
3053
|
+
_version = __version__
|
|
3054
3054
|
console.print(f"[bold blue]slurm-cli:[/] Slurm CLI v{_version}")
|
|
3055
3055
|
console.print("A CLI tool for Slurm cluster management")
|
|
3056
3056
|
|
|
@@ -3984,7 +3984,7 @@ def assoc_mgr(
|
|
|
3984
3984
|
slurm-cli assoc_mgr qos=normal,high flags=qos
|
|
3985
3985
|
"""
|
|
3986
3986
|
dry_run = get_dry_run(ctx) or dry_run
|
|
3987
|
-
args = ["scontrol", "assoc_mgr"]
|
|
3987
|
+
args = ["scontrol", "show", "assoc_mgr"]
|
|
3988
3988
|
|
|
3989
3989
|
# Parse options
|
|
3990
3990
|
for opt in options:
|
|
@@ -9,7 +9,7 @@ from rich.table import Table
|
|
|
9
9
|
|
|
10
10
|
from .base_resource import BaseSlurmResource
|
|
11
11
|
from .profiles import (
|
|
12
|
-
|
|
12
|
+
format_rows,
|
|
13
13
|
get_profile_config,
|
|
14
14
|
sort_data,
|
|
15
15
|
sort_hierarchical_data,
|
|
@@ -461,10 +461,9 @@ _slurm_cli_accounts_autocomplete() {{
|
|
|
461
461
|
else: # pretty style
|
|
462
462
|
# If template is specified, use template-based output
|
|
463
463
|
if template:
|
|
464
|
-
for
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
)
|
|
464
|
+
for output in format_rows(
|
|
465
|
+
template, accounts, resource="accounts"
|
|
466
|
+
):
|
|
468
467
|
console.print(output)
|
|
469
468
|
else:
|
|
470
469
|
# Create a rich table
|
|
@@ -11,7 +11,7 @@ from rich.table import Table
|
|
|
11
11
|
|
|
12
12
|
from .base_resource import BaseSlurmResource
|
|
13
13
|
from .profiles import (
|
|
14
|
-
|
|
14
|
+
format_rows,
|
|
15
15
|
get_profile_config,
|
|
16
16
|
sort_data,
|
|
17
17
|
sort_hierarchical_data,
|
|
@@ -619,10 +619,9 @@ _slurm_cli_associations_autocomplete() {{
|
|
|
619
619
|
else: # pretty style
|
|
620
620
|
# If template is specified, use template-based output
|
|
621
621
|
if template:
|
|
622
|
-
for
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
)
|
|
622
|
+
for output in format_rows(
|
|
623
|
+
template, associations, resource="associations"
|
|
624
|
+
):
|
|
626
625
|
console.print(output)
|
|
627
626
|
else:
|
|
628
627
|
# Create a rich table
|
|
@@ -9,7 +9,7 @@ from rich.box import SIMPLE_HEAVY
|
|
|
9
9
|
from rich.table import Table
|
|
10
10
|
|
|
11
11
|
from .base_resource import BaseSlurmResource
|
|
12
|
-
from .profiles import
|
|
12
|
+
from .profiles import format_rows, get_profile_config, sort_data
|
|
13
13
|
from .utils import console
|
|
14
14
|
|
|
15
15
|
|
|
@@ -546,8 +546,8 @@ class Job(BaseSlurmResource):
|
|
|
546
546
|
print(delimiter.join(row))
|
|
547
547
|
elif template:
|
|
548
548
|
# Template-based output
|
|
549
|
-
for
|
|
550
|
-
console.print(
|
|
549
|
+
for output in format_rows(template, jobs):
|
|
550
|
+
console.print(output)
|
|
551
551
|
else:
|
|
552
552
|
# Pretty table output
|
|
553
553
|
table = Table(
|
|
@@ -9,7 +9,7 @@ from rich.markup import escape
|
|
|
9
9
|
from rich.table import Table
|
|
10
10
|
|
|
11
11
|
from .base_resource import BaseSlurmResource
|
|
12
|
-
from .profiles import
|
|
12
|
+
from .profiles import format_rows, get_profile_config, sort_data
|
|
13
13
|
from .utils import console
|
|
14
14
|
|
|
15
15
|
|
|
@@ -416,12 +416,10 @@ _slurm_cli_nodes_autocomplete() {{
|
|
|
416
416
|
elif template_cfg and style == "pretty":
|
|
417
417
|
# Use template-based output (e.g., oneline profile)
|
|
418
418
|
nodes_to_show = {name: data[name]} if name and name in data else data
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
template_cfg, prepared, resource="nodes"
|
|
424
|
-
)
|
|
419
|
+
prepared = [
|
|
420
|
+
{"name": n, **d} for n, d in sorted(nodes_to_show.items())
|
|
421
|
+
]
|
|
422
|
+
for output in format_rows(template_cfg, prepared, resource="nodes"):
|
|
425
423
|
console.print(output)
|
|
426
424
|
elif columns_cfg and columns_cfg != "*" and style == "pretty":
|
|
427
425
|
# Use column-based table output (e.g., compact, minimal)
|
|
@@ -9,7 +9,7 @@ from rich.markup import escape
|
|
|
9
9
|
from rich.table import Table
|
|
10
10
|
|
|
11
11
|
from .base_resource import BaseSlurmResource
|
|
12
|
-
from .profiles import
|
|
12
|
+
from .profiles import format_rows, get_profile_config, sort_data
|
|
13
13
|
|
|
14
14
|
# from .resources import Resource, ResourceType
|
|
15
15
|
from .utils import console
|
|
@@ -453,12 +453,10 @@ class Partition(BaseSlurmResource):
|
|
|
453
453
|
elif template_cfg and style == "pretty":
|
|
454
454
|
# Use template-based output (e.g., oneline profile)
|
|
455
455
|
partitions_to_show = {name: data[name]} if name and name in data else data
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
template_cfg, prepared, resource="partitions"
|
|
461
|
-
)
|
|
456
|
+
prepared = [
|
|
457
|
+
{"PartitionName": n, **d} for n, d in sorted(partitions_to_show.items())
|
|
458
|
+
]
|
|
459
|
+
for output in format_rows(template_cfg, prepared, resource="partitions"):
|
|
462
460
|
console.print(output)
|
|
463
461
|
elif columns_cfg and columns_cfg != "*" and style == "pretty":
|
|
464
462
|
# Use column-based table output (e.g., compact, minimal)
|
|
@@ -231,7 +231,7 @@ class PrefixMatcher:
|
|
|
231
231
|
|
|
232
232
|
# Pre-defined command configuration
|
|
233
233
|
COMMANDS = {
|
|
234
|
-
"show": {"aliases": ["get"], "description": "Show/list resources"},
|
|
234
|
+
"show": {"aliases": ["get", "list", "ls"], "description": "Show/list resources"},
|
|
235
235
|
"create": {
|
|
236
236
|
"aliases": ["new", "add"],
|
|
237
237
|
"description": "Create new resources",
|
|
@@ -244,8 +244,8 @@ COMMANDS = {
|
|
|
244
244
|
"aliases": ["remove", "rm"],
|
|
245
245
|
"description": "Delete resources",
|
|
246
246
|
},
|
|
247
|
-
"
|
|
248
|
-
"aliases": [
|
|
247
|
+
"resources": {
|
|
248
|
+
"aliases": [],
|
|
249
249
|
"description": "List available resources",
|
|
250
250
|
},
|
|
251
251
|
"autocomplete": {
|
|
@@ -39,7 +39,7 @@ Template syntax:
|
|
|
39
39
|
import os
|
|
40
40
|
import re
|
|
41
41
|
from pathlib import Path
|
|
42
|
-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
42
|
+
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
|
|
43
43
|
|
|
44
44
|
# Profile file locations (in order of precedence, later overrides earlier)
|
|
45
45
|
PROFILE_FILES = [
|
|
@@ -951,11 +951,16 @@ def is_field_empty(
|
|
|
951
951
|
return False
|
|
952
952
|
|
|
953
953
|
|
|
954
|
+
# {field} or {field:[-+=]N[!][+]}
|
|
955
|
+
FIELD_PATTERN = re.compile(r"\{(\w+)(?::([-+=]?)(\d+)(!?)(\+?))?\}")
|
|
956
|
+
|
|
957
|
+
|
|
954
958
|
def format_with_template(
|
|
955
959
|
template: str,
|
|
956
960
|
data: Dict[str, Any],
|
|
957
961
|
value_formatter: Optional[Callable[[str, Any], str]] = None,
|
|
958
962
|
resource: Optional[str] = None,
|
|
963
|
+
min_widths: Optional[Dict[str, int]] = None,
|
|
959
964
|
) -> str:
|
|
960
965
|
"""Format data using a template string.
|
|
961
966
|
|
|
@@ -967,6 +972,11 @@ def format_with_template(
|
|
|
967
972
|
|
|
968
973
|
Template syntax:
|
|
969
974
|
{field} - replaced with field value
|
|
975
|
+
{field:WIDTH} - padded to WIDTH; WIDTH = [-|+|=]N[!][+]
|
|
976
|
+
'-' left (default), '+' right, '=' center;
|
|
977
|
+
'!' truncates longer values;
|
|
978
|
+
'+' postfix: N is a minimum, the actual width is
|
|
979
|
+
the max over all rows (see format_rows)
|
|
970
980
|
{?field TEXT} - show TEXT only if field is not empty
|
|
971
981
|
TEXT can contain {field} placeholders
|
|
972
982
|
|
|
@@ -996,10 +1006,7 @@ def format_with_template(
|
|
|
996
1006
|
result = conditional_pattern.sub(replace_conditional, result)
|
|
997
1007
|
|
|
998
1008
|
# Now process regular {field} placeholders
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
def replace_field(match: re.Match) -> str:
|
|
1002
|
-
field = match.group(1)
|
|
1009
|
+
def render(field: str) -> str:
|
|
1003
1010
|
value = data.get(field)
|
|
1004
1011
|
|
|
1005
1012
|
if value is None:
|
|
@@ -1022,7 +1029,34 @@ def format_with_template(
|
|
|
1022
1029
|
|
|
1023
1030
|
return str(value) if value != "" else "-"
|
|
1024
1031
|
|
|
1025
|
-
|
|
1032
|
+
def replace_field(match: re.Match) -> str:
|
|
1033
|
+
text = render(match.group(1))
|
|
1034
|
+
if match.group(3) is None:
|
|
1035
|
+
return text
|
|
1036
|
+
align, width = match.group(2), int(match.group(3))
|
|
1037
|
+
if match.group(5): # minimum width: widest value over all rows
|
|
1038
|
+
if min_widths is not None:
|
|
1039
|
+
key = match.group(0)
|
|
1040
|
+
min_widths[key] = max(min_widths.get(key, width), len(text))
|
|
1041
|
+
width = min_widths[key]
|
|
1042
|
+
width = max(width, len(text))
|
|
1043
|
+
elif match.group(4):
|
|
1044
|
+
text = text[:width]
|
|
1045
|
+
return {"+": text.rjust, "=": text.center}.get(align, text.ljust)(width)
|
|
1046
|
+
|
|
1047
|
+
return FIELD_PATTERN.sub(replace_field, result)
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
def format_rows(template: str, rows: Iterable[Dict[str, Any]], **kwargs) -> List[str]:
|
|
1051
|
+
"""Format every row; '+'-postfix widths ({f:10+}) are shared by all rows."""
|
|
1052
|
+
rows = list(rows)
|
|
1053
|
+
widths: Dict[str, int] = {}
|
|
1054
|
+
for row in rows: # first pass only collects widths
|
|
1055
|
+
format_with_template(template, row, min_widths=widths, **kwargs)
|
|
1056
|
+
return [
|
|
1057
|
+
format_with_template(template, row, min_widths=widths, **kwargs)
|
|
1058
|
+
for row in rows
|
|
1059
|
+
]
|
|
1026
1060
|
|
|
1027
1061
|
|
|
1028
1062
|
def extract_fields_from_template(template: str) -> List[str]:
|
|
@@ -1035,10 +1069,8 @@ def extract_fields_from_template(template: str) -> List[str]:
|
|
|
1035
1069
|
List of field names found in the template
|
|
1036
1070
|
"""
|
|
1037
1071
|
# Match both regular {field} and conditional {?field ...}
|
|
1038
|
-
pattern = re.compile(r"\{(\w+)
|
|
1039
|
-
|
|
1040
|
-
# Flatten and filter empty strings
|
|
1041
|
-
return [m[0] or m[1] for m in matches if m[0] or m[1]]
|
|
1072
|
+
pattern = re.compile(r"\{(\w+)(?::[-+=]?\d+!?\+?)?\}|\{\?(\w+)\s+")
|
|
1073
|
+
return [m[0] or m[1] for m in pattern.findall(template)]
|
|
1042
1074
|
|
|
1043
1075
|
|
|
1044
1076
|
def _get_resource_fields() -> Dict[str, Dict[str, str]]:
|
|
@@ -1130,9 +1162,13 @@ def show_profile_help(resource: str) -> bool:
|
|
|
1130
1162
|
print()
|
|
1131
1163
|
print("Template syntax:")
|
|
1132
1164
|
print(" {field} - Show field value")
|
|
1165
|
+
print(" {field:WIDTH} - Pad field; WIDTH=[-|+|=]N[!][+] (see below)")
|
|
1133
1166
|
print(" {?field TEXT} - Show TEXT only if field is not empty")
|
|
1134
1167
|
print(" [color]...[/] - Rich markup for colors")
|
|
1135
1168
|
print(" \\n - Newline")
|
|
1169
|
+
print("WIDTH: prefix - left (default), + right, = center; N is the width;")
|
|
1170
|
+
print(" postfix ! truncates longer values; postfix + makes N a minimum")
|
|
1171
|
+
print(" (actual width = widest value over all rows). Example: {name:-12+}")
|
|
1136
1172
|
print()
|
|
1137
1173
|
print("Example:")
|
|
1138
1174
|
print(' --profile-str "[cyan]{name}[/] - description"')
|
|
@@ -1165,6 +1201,7 @@ def show_all_profile_fields() -> None:
|
|
|
1165
1201
|
print(" field- - Sort descending by field")
|
|
1166
1202
|
print("\nTemplate syntax:")
|
|
1167
1203
|
print(" {field} - Show field value")
|
|
1204
|
+
print(" {field:WIDTH} - Pad field; WIDTH=[-|+|=]N[!][+]")
|
|
1168
1205
|
print(" {?field TEXT} - Show TEXT only if field is not empty")
|
|
1169
1206
|
print(" [color]...[/] - Rich markup for colors")
|
|
1170
1207
|
print(" \\n - Newline")
|
|
@@ -8,7 +8,7 @@ from rich.box import SIMPLE_HEAVY
|
|
|
8
8
|
from rich.table import Table
|
|
9
9
|
|
|
10
10
|
from .base_resource import BaseSlurmResource
|
|
11
|
-
from .profiles import
|
|
11
|
+
from .profiles import format_rows, get_profile_config, sort_data
|
|
12
12
|
from .utils import console
|
|
13
13
|
|
|
14
14
|
# QoS configuration options (sacctmgr field names)
|
|
@@ -392,11 +392,8 @@ class Qos(BaseSlurmResource):
|
|
|
392
392
|
console.print_json(json.dumps({"qos": qos_list}, indent=2))
|
|
393
393
|
elif template_cfg and style == "pretty":
|
|
394
394
|
# Use template-based output
|
|
395
|
-
for
|
|
396
|
-
|
|
397
|
-
output = format_with_template(
|
|
398
|
-
template_cfg, prepared, resource="qos"
|
|
399
|
-
)
|
|
395
|
+
prepared = [cls._prepare_template_data(q) for q in qos_list]
|
|
396
|
+
for output in format_rows(template_cfg, prepared, resource="qos"):
|
|
400
397
|
console.print(output)
|
|
401
398
|
elif style in ["csv", "pretty"]:
|
|
402
399
|
# Column definitions (used by both CSV and pretty styles)
|
|
@@ -8,7 +8,7 @@ from typing import Any, Dict, Optional, Union
|
|
|
8
8
|
from rich.markup import escape
|
|
9
9
|
|
|
10
10
|
from .base_resource import BaseSlurmResource
|
|
11
|
-
from .profiles import format_with_template, get_profile_config, sort_data
|
|
11
|
+
from .profiles import format_rows, format_with_template, get_profile_config, sort_data
|
|
12
12
|
|
|
13
13
|
# from .resources import Resource
|
|
14
14
|
from .utils import console
|
|
@@ -307,11 +307,12 @@ class Reservation(BaseSlurmResource):
|
|
|
307
307
|
)
|
|
308
308
|
console.print(output)
|
|
309
309
|
else:
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
prepared = [
|
|
311
|
+
cls._prepare_template_data(n, d) for n, d in data.items()
|
|
312
|
+
]
|
|
313
|
+
for output in format_rows(
|
|
314
|
+
template, prepared, resource="reservations"
|
|
315
|
+
):
|
|
315
316
|
console.print(output)
|
|
316
317
|
else: # default pretty style
|
|
317
318
|
if name:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|