timew_addons.utils module¶
Base configuration and app helper functions.
- class timew_addons.utils.FmtYAML(**kwargs)[source]¶
Bases:
YAML
Simple formatted YAML subclass with default indenting. Particularly useful in old RHEL environments with
ruamel.yaml==0.16.6
.
- timew_addons.utils.check_for_timew()[source]¶
Make sure we can find the
timew
binary in the user environment and return a path string.- Returns:
program path string
- Return type:
str
- timew_addons.utils.do_install(cfg)[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 (Dict) – runtime CFG
- Returns:
list of path strings
- Return type:
List[str]
- timew_addons.utils.get_config()[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.
- Returns:
tuple of Munch and Path objs
- Return type:
Tuple[Munch, Path]
- timew_addons.utils.get_delta_limits(ucfg)[source]¶
Return config max/snooze limits as timedeltas. Everything comes from static config values and gets padded with seconds.
- Parameters:
ucfg (Dict) – runtime CFG dict
- Returns:
tuple of 4 timedeltas
- Return type:
Tuple[timedelta, timedelta, timedelta, timedelta]
- timew_addons.utils.get_state_icon(state, cfg)[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 (Dict) – runtime CFG
- Returns:
matching icon name
- Return type:
str
- timew_addons.utils.get_state_str(cmproc, count, cfg)[source]¶
Return timew state message and tracking state, ie, the key for dict with icons.
- Parameters:
cmproc (CompletedProcess[bytes]) – completed timew process obj
count (timedelta) – seat time counter value
cfg (Dict) – runtime CFG
- Returns:
tuple of state msg and state string
- Return type:
Tuple[str, str]
- timew_addons.utils.get_status()[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
- Return type:
CompletedProcess[bytes]
- timew_addons.utils.get_userdirs()[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
- Return type:
Path
- timew_addons.utils.parse_for_tag(text)[source]¶
Parse the output of timew start/stop commands for the tag string.
- Parameters:
text (str) – start or stop output from
timew
(via run_cmd)- Returns:
timew tag string
- Return type:
str
- timew_addons.utils.run_cmd(cfg, action='status', tag=None)[source]¶
Run timew command subject to the given action.
- Parameters:
action (str) – one of <start|stop|status>
cfg (Dict)
tag (str | None)
- Returns:
completed proc obj and result msg
- Raises:
RuntimeError – for timew action error
- Return type:
Tuple[CompletedProcess[bytes], str]