From 79f5b1e41020cb757d471d8f51c34c5c665be589 Mon Sep 17 00:00:00 2001 From: Eike Waldt Date: Mon, 10 Mar 2025 16:03:13 +0100 Subject: [PATCH 1/2] add git module --- src/python_gardenlinux_lib/git/__init__.py | 3 +++ src/python_gardenlinux_lib/git/git.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/python_gardenlinux_lib/git/__init__.py create mode 100755 src/python_gardenlinux_lib/git/git.py diff --git a/src/python_gardenlinux_lib/git/__init__.py b/src/python_gardenlinux_lib/git/__init__.py new file mode 100644 index 00000000..327c3114 --- /dev/null +++ b/src/python_gardenlinux_lib/git/__init__.py @@ -0,0 +1,3 @@ +from .git import get_git_root + +__all__ = ['get_git_root'] \ No newline at end of file diff --git a/src/python_gardenlinux_lib/git/git.py b/src/python_gardenlinux_lib/git/git.py new file mode 100755 index 00000000..9f99d30b --- /dev/null +++ b/src/python_gardenlinux_lib/git/git.py @@ -0,0 +1,22 @@ +import subprocess +from pathlib import Path +import sys + +from ..logging import Logger + +def get_git_root(logger=None): + """Get the root directory of the current Git repository. + + Args: + logger: Optional logger instance. If not provided, will use module's logger. + """ + log = logger or Logger.get_logger("gardenlinux.git") + + try: + root_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip() + log.debug(f"Git root directory: {root_dir}") + return Path(root_dir) + except subprocess.CalledProcessError as e: + log.error("Not a git repository or unable to determine root directory.") + log.debug(f"Git command failed with: {e}") + sys.exit(1) \ No newline at end of file From 54d2df09418fa1a68a0aa3da916ddfaae95f51b4 Mon Sep 17 00:00:00 2001 From: Eike Waldt Date: Mon, 10 Mar 2025 22:04:08 +0100 Subject: [PATCH 2/2] add get_features_list --- .../features/parse_features.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/python_gardenlinux_lib/features/parse_features.py b/src/python_gardenlinux_lib/features/parse_features.py index 5c6239cc..4ab8dcff 100644 --- a/src/python_gardenlinux_lib/features/parse_features.py +++ b/src/python_gardenlinux_lib/features/parse_features.py @@ -138,7 +138,20 @@ def get_features_dict(cname: str, gardenlinux_root: str) -> dict: if __get_node_type(graph.nodes[feature]) == type ] return features_by_type + +def get_features_list(cname: str, gardenlinux_root: str) -> list: + """ + :param str cname: the target cname to get the feature dict for + :param str gardenlinux_root: path of garden linux src root + :return: list of features for a given cname + """ + feature_base_dir = f"{gardenlinux_root}/features" + input_features = __reverse_cname_base(cname) + feature_graph = read_feature_files(feature_base_dir) + graph = filter_graph(feature_graph, input_features) + features = __reverse_sort_nodes(graph) + return features def get_features(cname: str, gardenlinux_root: str) -> str: """