diff --git a/src/cfgnet/launcher.py b/src/cfgnet/launcher.py index ee47f9f..a3e4b7a 100644 --- a/src/cfgnet/launcher.py +++ b/src/cfgnet/launcher.py @@ -52,6 +52,7 @@ def main(verbose: bool): @click.option("-b", "--enable-static-blacklist", is_flag=True) @click.option("-i", "--enable-internal-links", is_flag=True) @click.option("-c", "--enable-all-conflicts", is_flag=True) +@click.option("-s", "--system_level", is_flag=False) @click.option("-f", "--config-files", multiple=True) @add_project_root_argument @add_enable_linker_option @@ -60,6 +61,7 @@ def init( enable_static_blacklist: bool, enable_internal_links: bool, enable_all_conflicts: bool, + system_level: bool, project_root: str, enable_linker: List[str], disable_linker: List[str], @@ -76,6 +78,7 @@ def init( enable_internal_links=enable_internal_links, enabled_linkers=list(set(enable_linker) - set(disable_linker)), enable_all_conflicts=enable_all_conflicts, + system_level=system_level, ) LinkerManager.set_enabled_linkers(network_configuration.enabled_linkers) logger.configure_repo_logger(network_configuration.logfile_path()) @@ -135,6 +138,7 @@ def validate(project_root: str): @click.option("-i", "--enable-internal-links", is_flag=True) @click.option("-c", "--enable-all-conflicts", is_flag=True) @click.option("-f", "--config-files", multiple=True) +@click.option("-s", "--system_level", multiple=True) @add_project_root_argument @add_enable_linker_option @add_disable_linker_option @@ -146,6 +150,7 @@ def analyze( enable_linker: List[str], disable_linker: List[str], config_files: List, + system_level: bool, ): """Run self-evaluating analysis of commit history.""" project_name = os.path.basename(project_root) @@ -159,6 +164,7 @@ def analyze( enable_internal_links=enable_internal_links, enabled_linkers=list(set(enable_linker) - set(disable_linker)), enable_all_conflicts=enable_all_conflicts, + system_level=system_level, ) LinkerManager.set_enabled_linkers(network_configuration.enabled_linkers) logger.configure_repo_logger(network_configuration.logfile_path()) @@ -223,11 +229,10 @@ def export( @main.command() @click.option("-f", "--config-files", multiple=True) @click.option("-o", "--output", required=True) +@click.option("-f", "--system_level", is_flag=False) @add_project_root_argument def extract( - project_root: str, - config_files: List, - output: str, + project_root: str, config_files: List, output: str, system_level: bool ): """Extract key-value pairs.""" project_name = os.path.basename(project_root) @@ -239,6 +244,7 @@ def extract( enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=False, + system_level=system_level, ) start = time.time() diff --git a/src/cfgnet/network/network.py b/src/cfgnet/network/network.py index 2e3f9e9..ef917b2 100644 --- a/src/cfgnet/network/network.py +++ b/src/cfgnet/network/network.py @@ -37,7 +37,7 @@ ) from cfgnet.network.network_configuration import NetworkConfiguration from cfgnet.exporter.exporter import DotExporter, JSONExporter -from cfgnet.utility.util import is_test_file +from cfgnet.utility.util import is_test_file, get_system_files class Network: @@ -291,6 +291,10 @@ def init_network(cfg: NetworkConfiguration) -> Network: if cfg.config_files: tracked_files.update(cfg.config_files) + if cfg.system_level: + system_files = get_system_files() + tracked_files.update(system_files) + project_name = cfg.project_name() root = ProjectNode(name=project_name, root_dir=cfg.project_root_abs) network = Network(project_name=project_name, root=root, cfg=cfg) @@ -308,6 +312,7 @@ def init_network(cfg: NetworkConfiguration) -> Network: plugins, abs_file_path ) if plugin: + print("File to parse: ", abs_file_path) try: plugin.parse_file( abs_file_path=abs_file_path, diff --git a/src/cfgnet/network/network_configuration.py b/src/cfgnet/network/network_configuration.py index 186be02..bf927f3 100644 --- a/src/cfgnet/network/network_configuration.py +++ b/src/cfgnet/network/network_configuration.py @@ -11,6 +11,7 @@ class NetworkConfiguration: enable_static_blacklist: bool enable_internal_links: bool enable_all_conflicts: bool + system_level: bool # Path to CfgNet data directory relative to project_root cfgnet_path_rel: str = ".cfgnet" # List of names of enabled linkers diff --git a/src/cfgnet/utility/util.py b/src/cfgnet/utility/util.py index cd99a75..b7058cb 100644 --- a/src/cfgnet/utility/util.py +++ b/src/cfgnet/utility/util.py @@ -1,3 +1,50 @@ +import os +import platform +import logging +from typing import Set, Optional + + def is_test_file(abs_file_path) -> bool: + """ + Check if a given file is a test file. + + :return: True if test file else False + """ test_indicators = ["/tests", "test", "tests"] return any(indicator in abs_file_path for indicator in test_indicators) + + +def get_system_config_dir() -> Optional[str]: + """ + Determine the system configuration directory based on the operating system. + + :return: Path to the system configuration directory + """ + os_type = platform.system() + + print("OS: ", os_type) + + if os_type == "Linux": + # Common Linux config directories + return "/etc" + + if os_type == "Windows": + # Windows config directory (use environment variables for system paths) + return os.getenv("ProgramData", "C:\\ProgramData") + + logging.error("System config directory not defined for OS %s. ", os_type) + return None + + +def get_system_files() -> Set: + config_dir = get_system_config_dir() + system_files = set() + + if config_dir: + for root, _, files in os.walk(config_dir): + for file in files: + print("File: ", file) + abs_file_path = os.path.join(root, file) + system_files.add(abs_file_path) + + return system_files diff --git a/tests/cfgnet/analyze/test_analyzer.py b/tests/cfgnet/analyze/test_analyzer.py index 6c3a792..9ce1fed 100644 --- a/tests/cfgnet/analyze/test_analyzer.py +++ b/tests/cfgnet/analyze/test_analyzer.py @@ -37,6 +37,7 @@ def get_config_(get_repo): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=False, + system_level=False ) return network_configuration @@ -49,6 +50,7 @@ def get_config_all_conflicts_(get_repo): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=True, + system_level=False ) return network_configuration diff --git a/tests/cfgnet/conflicts/test_conflict_detector.py b/tests/cfgnet/conflicts/test_conflict_detector.py index f76639f..0d95c29 100644 --- a/tests/cfgnet/conflicts/test_conflict_detector.py +++ b/tests/cfgnet/conflicts/test_conflict_detector.py @@ -38,6 +38,7 @@ def get_maven_docker_networks(): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=False, + system_level=False ) ref_network = Network.init_network(cfg=network_configuration) @@ -60,6 +61,7 @@ def get_docker_networks(): enable_static_blacklist=False, enable_internal_links=True, enable_all_conflicts=False, + system_level=False ) ref_network = Network.init_network(cfg=network_configuration) @@ -82,6 +84,7 @@ def get_port_db_networks(): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=False, + system_level=False ) ref_network = Network.init_network(cfg=network_configuration) @@ -104,6 +107,7 @@ def get_nodejs_networks(): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=True, + system_level=False ) ref_network = Network.init_network(cfg=network_configuration) @@ -126,6 +130,7 @@ def get_networks_equally_changed(): enable_static_blacklist=False, enable_internal_links=False, enable_all_conflicts=False, + system_level=False ) ref_network = Network.init_network(cfg=network_configuration) diff --git a/tests/cfgnet/exporter/test_exporter.py b/tests/cfgnet/exporter/test_exporter.py index d6a26fb..1df8c31 100644 --- a/tests/cfgnet/exporter/test_exporter.py +++ b/tests/cfgnet/exporter/test_exporter.py @@ -41,7 +41,8 @@ def get_config_(get_repo): project_root_abs=os.path.abspath(get_repo.root), enable_static_blacklist=False, enable_internal_links=False, - enable_all_conflicts=False + enable_all_conflicts=False, + system_level=False ) yield network_configuration diff --git a/tests/cfgnet/network/test_ignorefile.py b/tests/cfgnet/network/test_ignorefile.py index f2af043..2bd9e08 100644 --- a/tests/cfgnet/network/test_ignorefile.py +++ b/tests/cfgnet/network/test_ignorefile.py @@ -35,7 +35,8 @@ def test_ignorefile(repo): project_root_abs=os.path.abspath(repo.root), enable_static_blacklist=False, enable_internal_links=False, - enable_all_conflicts=False + enable_all_conflicts=False, + system_level=False ) network = Network.init_network(cfg) diff --git a/tests/cfgnet/network/test_network.py b/tests/cfgnet/network/test_network.py index d5ba0c0..f7e6f5c 100644 --- a/tests/cfgnet/network/test_network.py +++ b/tests/cfgnet/network/test_network.py @@ -43,7 +43,8 @@ def get_config_(get_repo): project_root_abs=os.path.abspath(get_repo.root), enable_static_blacklist=False, enable_internal_links=False, - enable_all_conflicts=False + enable_all_conflicts=False, + system_level=False ) return network_configuration