timew_status.utils module

Base configuration and app helper functions.

timew_status.utils.check_for_timew() str[source]

Make sure we can find the timew binary in the user environment and return a path string.

Return timew_path:

program path strings

Rtype str:

path to program if found, else None

timew_status.utils.do_install(cfg: Dict) List[str][source]

Install report extensions to timew extensions directory. The default src paths are preconfigured and should probably not be changed unless you know what you are doing, since they are created during install or setup. You should, however, adjust the destination path in extensions_dir if needed for your platform. Returns the destination path string for each installed extension script.

Parameters:

cfg – runtime CFG dict

Return files:

list of strings

timew_status.utils.get_config(file_encoding: str = 'utf-8') Tuple[Munch, Path][source]

Load configuration file and munchify the data. If local file is not found in config directory, the default will be loaded and saved to XDG config directory. Return a Munch cfg obj and corresponding Path obj.

Parameters:

file_encoding (str) – file encoding of config file

Returns:

tuple of Munch and Path objs

timew_status.utils.get_delta_limits(ucfg: Dict) Tuple[timedelta, timedelta, timedelta, timedelta][source]

Return config max/snooze limits as timedeltas. Everything comes from static config values and gets padded with seconds.

Parameters:

ucfg – runtime CFG dict

Returns:

tuple of 4 timedeltas

timew_status.utils.get_state_icon(state: str, cfg: Dict) str[source]

Look up the state msg and return the icon name. Use builtin symbolic icons as fallback.

Parameters:
  • state (str) – name of state key

  • cfg – runtime CFG (dict)

Returns:

matching icon name (str)

timew_status.utils.get_state_str(cmproc: CompletedProcess[bytes], count: TimeDelta, cfg: Dict) Tuple[str, str][source]

Return timew state message and tracking state, ie, the key for dict with icons.

Parameters:
  • cmproc (CompletedProcess) – completed timew process obj

  • count (timedelta) – seat time counter value

  • cfg (Dict) – runtime CFG

Returns:

tuple of state msg and state string

timew_status.utils.get_status() CompletedProcess[bytes][source]

Return timew tracking status (output of timew with no arguments).

Parameters:

None

Returns:

timew output str or None

Raises:

RuntimeError – for timew not found error

timew_status.utils.get_userdirs() Path[source]

Get XDG user configuration path defined as XDG_CONFIG_HOME plus application name. This may grow if needed.

Parameters:

None

Returns:

XDG Path obj

timew_status.utils.parse_for_tag(text: str) str[source]

Parse the output of timew start/stop commands for the tag string.

Parameters:

text – start or stop output from timew (via run_cmd)

Returns:

timew tag string

timew_status.utils.run_cmd(cfg: Dict, action: str = 'status', tag: str | None = None) Tuple[CompletedProcess[bytes], str][source]

Run timew command subject to the given action.

Parameters:

action – one of <start|stop|status>

Returns:

completed proc obj and result msg

Raises:

RuntimeError – for timew action error

timew_status.utils.to_td(hms: str) timedelta[source]

Convert a time string in HH:MM:SS format to a timedelta object.

Parameters:

hms – time string

Returns:

timedelta