From 30ee8d9144e57527cee029628ad8de1512599438 Mon Sep 17 00:00:00 2001 From: dingsheng Date: Tue, 19 Nov 2024 06:22:35 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=AC=E5=9C=B0=E5=B7=B2?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E8=BD=AF=E4=BB=B6=E5=8C=85=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/depparse.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/utils/depparse.py b/src/utils/depparse.py index dbcdfcd..a17fc5a 100755 --- a/src/utils/depparse.py +++ b/src/utils/depparse.py @@ -209,10 +209,21 @@ class LocalInstalledDepParse(DepParse): 已安装软件包依赖解析模块 """ def __init__(self): - pass + self.dep_dict = self._get_installed_pkgdeps() + self.dep_by_dict = self._get_installed_pkgdeps_by() + self.all_pkgs = self._get_all_pkgs() def _get_all_pkgs(self): - pass + """ + 解析已安装软件包名集合 + Returns: + res_set (set): 本地已安装所有软件包名集合 + """ + if isinstance(self.dep_dict,dict): + res_set = set(self.dep_dict.keys()) + else: + res_set = set() + return res_set def _get_installed_pkgdeps(self): """ @@ -235,4 +246,26 @@ class LocalInstalledDepParse(DepParse): return package_dep_d def _get_installed_pkgdeps_by(self): - pass \ No newline at end of file + """ + 获取已安装软件包的北向依赖 + Returns: + dict: 软件包北向依赖字典 + """ + deps_by_dict = defaultdict(list) + dep_pkgs_dict = copy.deepcopy(self.dep_dict) + for p in dep_pkgs_dict.keys(): + deps_by_dict[p] + for k,v in dep_pkgs_dict.items(): + if not v: + continue + else: + for dep_pkg in v: + tmp_k = dep_pkg + if tmp_k not in list(deps_by_dict.keys()): + deps_by_dict[tmp_k] = [k] + else: + tmp_v = deps_by_dict.get(tmp_k) + tmp_v.append(k) + tmp_v = list(set(tmp_v)) + deps_by_dict[tmp_k] = tmp_v + return deps_by_dict \ No newline at end of file -- Gitee