From c40b8088d383c91f736c31fea211c45c42364737 Mon Sep 17 00:00:00 2001 From: xuezhixin Date: Thu, 13 Jun 2024 15:05:26 +0800 Subject: [PATCH] update check pkgs function --- uos-sysmig/sysmig_agent/centos72openeuler.py | 40 +++++++++----------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/uos-sysmig/sysmig_agent/centos72openeuler.py b/uos-sysmig/sysmig_agent/centos72openeuler.py index eed0d68..ecfb828 100644 --- a/uos-sysmig/sysmig_agent/centos72openeuler.py +++ b/uos-sysmig/sysmig_agent/centos72openeuler.py @@ -37,28 +37,24 @@ def local_disabled_release_repo(): os.remove(fpath) -def run_subprocess(cmd): - try: - process = subprocess.run( - cmd, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=False, # Avoid using shell=True - check=True # Check for non-zero return code and raise exception if found - ) - output = process.stdout - print(output) # Print the output to console - return output, process.returncode - except subprocess.CalledProcessError as e: - print(e.stderr) # Print the error output to console - return e.stderr, e.returncode - - -def check_pkg(rpm): - _, ret = run_subprocess('rpm -q {}'.format(rpm).split()) - if ret: - return - return True +def check_pkg(pkg): + if pkg.split('/')[0] == '': + if os.path.exists(pkg): + return True + else: + return False + + paths = os.environ['PATH'].split(':') + for path in paths: + if not os.path.isdir(path): + continue + for f in os.listdir(path): + if os.path.isfile(os.path.join(path, f)): + if f == pkg: + return True + return False + + def get_disk_info(string): -- Gitee