Utilities

Note

The documentation in this section is aimed at people wishing to contribute to rdial, and can be skipped if you are simply using the tool from the command line.

Convenience functions and classes

rdial.utils.write_current(fun)[source]

Decorator to write .current file on function exit.

Parameters

fun (types.FunctionType) – Function to add hidden attribute to

Returns

Wrapped function

Return type

types.FunctionType

rdial.utils.remove_current(fun)[source]

Decorator to remove .current file on function exit.

Parameters

fun (types.FunctionType) – Function to add hidden attribute to

Returns

Wrapped function

Return type

types.FunctionType

rdial.utils.newer(fname, reference)[source]

Check whether given file is newer than reference file.

Parameters
  • fname (str) – File to check

  • reference (str) – file to test against

Returns

True if fname is newer than reference

Return type

bool

Generate a terminal hyperlink

See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.

Parameters
  • target (str) – Hyperlink target

  • name (str) – Target name

Returns

Formatted hyperlink for terminal output

Return type

str

Time handling

rdial.utils.parse_datetime_user(string)[source]

Parse datetime string from user.

We accept the normal ISO-8601 formats, but kick through to the formats supported by the system’s date command if parsing fails.

Parameters

string (str) – Datetime string to parse

Returns

Parsed datetime object

Return type

datetime.datetime

Examples

Time handling

 >>> parse_datetime_user('40 minutes ago')
 datetime.datetime(2012, 2, 15, 18, 59, 18)