diff --git a/src/rpmquery/rpmcheck.py b/src/rpmquery/rpmcheck.py index 437476fab9398cb4f18d6114402ea198dd81449f..7737e999192e3bc419ad7f5fa05bec0ba9953361 100644 --- a/src/rpmquery/rpmcheck.py +++ b/src/rpmquery/rpmcheck.py @@ -14,6 +14,8 @@ """ import os from src.utils.config import BaseConfig +import subprocess + class RpmCheck(object): """ @@ -28,6 +30,20 @@ class RpmCheck(object): 检查软件包存在性 """ return os.path.exists(self.path) + + def check_formate(self): + try: + # 使用rpm命令查询RPM文件信息 + result = subprocess.run(['rpm', '-qip', self.path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # 检查命令是否成功执行 + if result.returncode != 0: + print(f"Error querying RPM file {self.path}: {result.stderr}") + return False + return True + except Exception as e: + print(f"Error querying RPM file {self.path}: {e}") + return False @classmethod def check(cls,rpm_path): @@ -43,5 +59,8 @@ class RpmCheck(object): if not obj.check_exist(): print(BaseConfig.RPM_CHECK_ERROR_INFO.get(1001,'')) return False + if not obj.check_formate(): + print(BaseConfig.RPM_CHECK_ERROR_INFO.get(1002,'')) + return False return True diff --git a/src/utils/config.py b/src/utils/config.py index 5d5a3d087e6ce1de8bd4c6ba493f46928d705387..99043b1fd55d23313724f374257eb13a1fd403ba 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -37,6 +37,7 @@ class BaseConfig(): RPM_CHECK_ERROR_INFO={ 1001:"The RPM path does not exist. Please check if the entered RPM path is correct.", + 1002:"The compliance check for the RPM file failed. Please check if the RPM file is normal.", } # util