Add slurm sinfo parser from file
This commit is contained in:
parent
52b96548c2
commit
b0f8e336bc
2 changed files with 25 additions and 4 deletions
|
@ -6,6 +6,7 @@ import subprocess
|
|||
from dataclasses import dataclass, field
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -94,6 +95,12 @@ def sinfo_filter(resources: list, with_states=('idle', 'mixed')) -> dict:
|
|||
return {key: values for key, values in resources.items() if values}
|
||||
|
||||
|
||||
def sinfo_from_file(fname, with_states=('idle', 'mixed')) -> dict:
|
||||
"""SLURM SINFO resources available from a given file."""
|
||||
content = Path(fname).read_text()
|
||||
return sinfo_filter(sinfo_reader(content), with_states=with_states)
|
||||
|
||||
|
||||
def sinfo(username: str = None, with_states=('idle', 'mixed')) -> dict:
|
||||
"""SLURM SINFO resources available for a given user."""
|
||||
return sinfo_filter(sinfo_reader(sinfo_run(username=username)), with_states=with_states)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue