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: """ 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