toil.lib.conversions

Conversion utilities for mapping memory, disk, core declarations from strings to numbers and vice versa. Also contains general conversion functions

Module Contents

Functions

bytes_in_unit([unit])

convert_units(num, src_unit[, dst_unit])

Returns a float representing the converted input in dst_units.

parse_memory_string(string)

Given a string representation of some memory (i.e. '1024 Mib'), return the

human2bytes(string)

Given a string representation of some memory (i.e. '1024 Mib'), return the

bytes2human(n)

Return a binary value as a human readable string with units.

b_to_mib(n)

Convert a number from bytes to mibibytes.

mib_to_b(n)

Convert a number from mibibytes to bytes.

hms_duration_to_seconds(hms)

Parses a given time string in hours:minutes:seconds,

strtobool(val)

Make a human-readable string into a bool.

Attributes

BINARY_PREFIXES

DECIMAL_PREFIXES

VALID_PREFIXES

toil.lib.conversions.BINARY_PREFIXES = ['ki', 'mi', 'gi', 'ti', 'pi', 'ei', 'kib', 'mib', 'gib', 'tib', 'pib', 'eib']
toil.lib.conversions.DECIMAL_PREFIXES = ['b', 'k', 'm', 'g', 't', 'p', 'e', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb']
toil.lib.conversions.VALID_PREFIXES
toil.lib.conversions.bytes_in_unit(unit='B')[source]
Parameters:

unit (str)

Return type:

int

toil.lib.conversions.convert_units(num, src_unit, dst_unit='B')[source]

Returns a float representing the converted input in dst_units.

Parameters:
Return type:

float

toil.lib.conversions.parse_memory_string(string)[source]

Given a string representation of some memory (i.e. ‘1024 Mib’), return the number and unit.

Parameters:

string (str)

Return type:

Tuple[float, str]

toil.lib.conversions.human2bytes(string)[source]

Given a string representation of some memory (i.e. ‘1024 Mib’), return the integer number of bytes.

Parameters:

string (str)

Return type:

int

toil.lib.conversions.bytes2human(n)[source]

Return a binary value as a human readable string with units.

Parameters:

n (SupportsInt)

Return type:

str

toil.lib.conversions.b_to_mib(n)[source]

Convert a number from bytes to mibibytes.

Parameters:

n (Union[int, float])

Return type:

float

toil.lib.conversions.mib_to_b(n)[source]

Convert a number from mibibytes to bytes.

Parameters:

n (Union[int, float])

Return type:

float

toil.lib.conversions.hms_duration_to_seconds(hms)[source]

Parses a given time string in hours:minutes:seconds, returns an equivalent total seconds value

Parameters:

hms (str)

Return type:

float

toil.lib.conversions.strtobool(val)[source]

Make a human-readable string into a bool.

Convert a string along the lines of “y”, “1”, “ON”, “TrUe”, or “Yes” to True, and the corresponding false-ish values to False.

Parameters:

val (str)

Return type:

bool