From 7100fe6501d2b017d952ad005575c42c1888e501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E4=BA=91=E7=9A=93?= Date: Fri, 6 Dec 2024 14:33:35 +0800 Subject: [PATCH] Add check_fransform function to the rpmcheck module --- src/rpmquery/rpmcheck.py | 19 +++++++++++++++++++ src/utils/config.py | 1 + 2 files changed, 20 insertions(+) diff --git a/src/rpmquery/rpmcheck.py b/src/rpmquery/rpmcheck.py index 437476f..7737e99 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 5d5a3d0..99043b1 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 -- Gitee