From 07afbbc04007c6195633ed9599eb04691cc53adc Mon Sep 17 00:00:00 2001 From: dingsheng Date: Fri, 16 Aug 2024 07:49:17 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BE=9D=E8=B5=96=E8=A7=A3?= =?UTF-8?q?=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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 src/utils/depparse.py diff --git a/src/utils/depparse.py b/src/utils/depparse.py new file mode 100755 index 0000000..2dbaf73 --- /dev/null +++ b/src/utils/depparse.py @@ -0,0 +1,37 @@ +#-*- coding:utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. +# [kyclassifier] licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# ********************************************************************************** +""" + +from collections import defaultdict + +class DepParse(object): + def __init__(self): + self.dep_dict = defaultdict(list) + self.dep_by_dict = defaultdict(list) + self.all_pkgs = set() + + def get_pkg_all_deps(self,pkg_name): + dep_set = set() + dep_pkgs_dict = self.dep_dict + to_process = {pkg_name} + while to_process: + package = to_process.pop() + dep_set.add(package) + for dep in dep_pkgs_dict.get(package,set()): + if dep not in dep_set: + to_process.add(dep) + dep_set.add(dep) + dep_set.remove(pkg_name) + return dep_set + -- Gitee