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.read_config(user_config=None, cli_options=None)[source]

Read configuration data.

Parameters
Return type

ConfigParser

Returns

Parsed configuration data

rdial.utils.write_current(__fun)[source]

Decorator to write .current file on function exit.

Parameters

__fun (Callable) – Function to wrap

Return type

Callable

Returns

Wrapped function

rdial.utils.remove_current(__fun)[source]

Decorator to remove .current file on function exit.

Parameters

__fun (Callable) – Function to wrap

Return type

Callable

Returns

Wrapped function

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

Return type

bool

Returns

True if __fname is newer than __reference

Generate a terminal hyperlink.

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

Parameters
  • __target (str) – Hyperlink target

  • name (Optional[str]) – Target name

Return type

str

Returns

Formatted hyperlink for terminal output

Time handling

rdial.utils.iso_week_to_date(__year, __week)[source]

Generate date range for a given ISO-8601 week.

ISO-8601 defines a week as Monday to Sunday, with the first week of a year being the first week containing a Thursday.

Parameters
  • __year (int) – Year to process

  • __week (int) – Week number to process

Return type

Tuple[date, date]

Returns

Date range objects for given week

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

Return type

datetime

Returns

Parsed datetime object

Development tools

rdial.utils.maybe_profile()[source]

Profile the wrapped code block.

When RDIAL_PROFILE is set execute the enclosed block under bprofile. The envvar’s value should be the name of the output file to generate.

When RDIAL_PROFILE is unset, this is just a no-op.

Return type

AbstractContextManager[+T_co]

Examples

Time handling

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

Development tools

 >>> with maybe_profile():
 ...     time.sleep(10)