diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:24:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:24:37 +0000 |
commit | 1022b2cebe73db426241c2f420d4ee9f6f3c1bed (patch) | |
tree | a5c38ccfaa66e8a52767dec01d3598b67a7422a8 /src/ansible_compat/prerun.py | |
parent | Initial commit. (diff) | |
download | python-ansible-compat-1022b2cebe73db426241c2f420d4ee9f6f3c1bed.tar.xz python-ansible-compat-1022b2cebe73db426241c2f420d4ee9f6f3c1bed.zip |
Adding upstream version 4.1.11.upstream/4.1.11
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ansible_compat/prerun.py')
-rw-r--r-- | src/ansible_compat/prerun.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ansible_compat/prerun.py b/src/ansible_compat/prerun.py new file mode 100644 index 0000000..6dfa44f --- /dev/null +++ b/src/ansible_compat/prerun.py @@ -0,0 +1,21 @@ +"""Utilities for configuring ansible runtime environment.""" +import hashlib +import os +from pathlib import Path + + +def get_cache_dir(project_dir: Path) -> Path: + """Compute cache directory to be used based on project path.""" + # we only use the basename instead of the full path in order to ensure that + # we would use the same key regardless the location of the user home + # directory or where the project is clones (as long the project folder uses + # the same name). + basename = project_dir.resolve().name.encode(encoding="utf-8") + # 6 chars of entropy should be enough + cache_key = hashlib.sha256(basename).hexdigest()[:6] + cache_dir = ( + Path(os.getenv("XDG_CACHE_HOME", "~/.cache")).expanduser() + / "ansible-compat" + / cache_key + ) + return cache_dir |