From 402076cfb7663cda6af311160492ac2e59cf22cd Mon Sep 17 00:00:00 2001 From: dingsheng Date: Fri, 27 Sep 2024 09:37:22 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E7=B1=BB=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/algclassify.py | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/algclassify.py b/src/main/algclassify.py index 45a85ee..4ad76d8 100755 --- a/src/main/algclassify.py +++ b/src/main/algclassify.py @@ -13,7 +13,9 @@ # ********************************************************************************** """ import json - +import os +import copy +from itertools import chain class AlgClassify(object): """ @@ -73,4 +75,47 @@ class AlgClassify(object): res.update({name:rpm_group}) else: continue + return res + + @classmethod + def _get_pkg2category_by_jsonf(cls,jsonf): + """ + 通过json文件获取软件包类别 + Args: + jsonf (str): 分类数据json文件 + + Returns: + res: 分类字典 + """ + res = {} + if os.path.exists(jsonf): + try: + res = cls._load_data(jsonf) + except Exception as e: + print('Failed to load classify data file: {} ,skip load classify data.\nERROR: {}'.format(jsonf,e)) + return res + else: + print('File {} not exists,skip load classify data.'.format(jsonf)) + return res + + @classmethod + def _merge_pkg2category_dict(cls,data_obj,*args): + """ + 合并分类数据 + Args: + data_obj: DataParse类对象 + + Returns: + res: 分类字典 + """ + pkgnames = list(cls._get_pkgs(data_obj)) + res = { p:[] for p in pkgnames} + dict_l = [d for d in args] if args else [] + for p in pkgnames: + category_l = [d.get(p,[]) for d in dict_l] + category = list(chain.from_iterable(category_l)) + res[p] = copy.deepcopy(category) + for p,v in res.items(): + if not v : + res[p] = ['其它'] return res \ No newline at end of file -- Gitee