Skip to content

utils

pyslurm.utils

pyslurm utility functions

pyslurm.utils.timestr_to_secs(timestr) method descriptor

Convert Slurm Timestring to seconds

Parameters:

Name Type Description Default
timestr str

A Timestring compatible with Slurms time functions.

required

Returns:

Type Description
int

Amount of time in seconds

pyslurm.utils.timestr_to_mins(timestr) method descriptor

Convert Slurm Timestring to minutes

Parameters:

Name Type Description Default
timestr str

A Timestring compatible with Slurms time functions.

required

Returns:

Type Description
int

Amount of time in minutes

pyslurm.utils.secs_to_timestr(secs, default=None) method descriptor

Parse time in seconds to Slurm Timestring

Parameters:

Name Type Description Default
secs int

Amount of seconds to convert

required

Returns:

Type Description
str

A Slurm timestring

pyslurm.utils.mins_to_timestr(mins, default=None) method descriptor

Parse time in minutes to Slurm Timestring

Parameters:

Name Type Description Default
mins int

Amount of minutes to convert

required

Returns:

Type Description
str

A Slurm timestring

pyslurm.utils.date_to_timestamp(date, on_nodate=0) method descriptor

Parse Date to Unix timestamp

Parameters:

Name Type Description Default
date Union[str, int, datetime.datetime]

A date to convert to a Unix timestamp.

required

Returns:

Type Description
int

A unix timestamp

pyslurm.utils.timestamp_to_date(timestamp) method descriptor

Parse Unix timestamp to Slurm Date-string

Parameters:

Name Type Description Default
timestamp int

A Unix timestamp that should be converted.

required

Returns:

Type Description
str

A Slurm date timestring

pyslurm.utils.expand_range_str(range_str) method descriptor

Expand a ranged string of numbers to a list of unique values.

Parameters:

Name Type Description Default
range_str str

A range string, which can for example look like this: "1,2,3-10,11,15-20"

required

Returns:

Type Description
list

List of unique values

pyslurm.utils.humanize(num, decimals=1) method descriptor

Humanize a number.

This will convert the number to a string and add appropriate suffixes like M,G,T,P,...

Parameters:

Name Type Description Default
num int

Number to humanize

required
decimals int

Amount of decimals the humanized string should have.

1

Returns:

Type Description
str

Humanized number with appropriate suffix.

pyslurm.utils.dehumanize(humanized_str, target='M', decimals=0) method descriptor

Dehumanize a previously humanized value.

Parameters:

Name Type Description Default
humanized_str str

A humanized str, for example "5M" or "10T"

required
target str

Target unit. The default is "M" (Mebibytes). Allowed values are K,M,G,T,P,E,Z

'M'
decimals int

Amount of decimal places the result should have. Default is 0

0

Returns:

Type Description
int

Dehumanized value

pyslurm.utils.nodelist_from_range_str(nodelist) method descriptor

Convert a bracketed nodelist str with ranges to a list.

Parameters:

Name Type Description Default
nodelist Union[str, list]

Comma-seperated str or list with potentially bracketed hostnames and ranges.

required

Returns:

Type Description
list

List of all nodenames or None on failure

pyslurm.utils.nodelist_to_range_str(nodelist) method descriptor

Convert a list of nodes to a bracketed str with ranges.

Parameters:

Name Type Description Default
nodelist Union[str, list]

Comma-seperated str or list with unique, unbracketed nodenames.

required

Returns:

Type Description
str

Bracketed, ranged nodelist or None on failure.