from common.utils import PathManager

class Manager(PathManager):

    @property
    def get_build_envs(self):
        envs = self.get_config_keys(self.RELEASE_JSON)
        for env in envs:
            print(env)

    @property
    def get_install_packages(self):
        header = "%-47s%-39s%-14s" % ("软件包名", "软件包版本号", "运行环境")
        print(header)

        separator = "================================================== ============================================ ============="
        print(separator)

        for package in self.get_config_keys(self.INSTALL_JSON):
            if package == "v10sp1Driver":
                continue
            if package == "dkmsContainer":
                continue
            config = self.get_config_json(self.INSTALL_JSON, package)
            version = config.get("version", "N/A")
            env = config.get("base_env", "N/A")

            line = "%-51s%-45s%-35s" % (package, version, env)
            print(line)

    def get_packages_list(self, package):
        conf = self.get_config_json(self.INSTALL_JSON, package)
        if conf is None:
            print(f"软件包{package}未安装")
            return
        for file in conf.get("file"):
            print(file)
        for file in conf.get("container_file"):
            print(file)

    def search(self, keyword):
        conf = self.get_config_json(self.INSTALL_JSON)
        for package, value in conf.items():
            for file_path in value.get("container_file", []):
                if keyword in file_path:
                    print(f"{package}: {file_path}")
                    continue  
            for file_path in value.get("file", []):
                if keyword in file_path:
                    print(f"{package}: {file_path}")
                    continue  