From: SangYoun Kwak Date: Fri, 19 Apr 2024 10:30:58 +0000 (+0900) Subject: common: Modify package checking code to use 'which' X-Git-Tag: accepted/tizen/unified/20240502.044710~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f524d4b331bbf89657b91a3d3543cc6019bfcafd;p=platform%2Fcore%2Fsystem%2Fupgrade-tools.git common: Modify package checking code to use 'which' Since apt is not a default package of python, shutil.which is used to increase portability. Change-Id: I1745f065f0772bffdafd90ea50daf4d67d6338af Signed-off-by: SangYoun Kwak --- diff --git a/mk_delta/common/bin/CreatePatch.py b/mk_delta/common/bin/CreatePatch.py index f9d9058..6443038 100755 --- a/mk_delta/common/bin/CreatePatch.py +++ b/mk_delta/common/bin/CreatePatch.py @@ -9,7 +9,7 @@ import re import datetime import hashlib import logging -import apt +import shutil import stat import argparse @@ -879,14 +879,12 @@ def main(): print("Attribute files do not exist -- ABORT", file=sys.stderr) sys.exit(1) - # TODO verify if other linux distributions support APT library - cache = apt.Cache() - package_names = ['brotli', 'attr', 'tar'] - missing_package_names = [package for package in package_names if package not in cache or not cache[package].is_installed] - - if missing_package_names: - missing_package_names = ", ".join(missing_package_names) - print(f"Missing packages: {missing_package_names} -- ABORT", file=sys.stderr) + # May checking commands is not sufficient for checking requirements + required_commands = ['brotli', 'attr', 'tar'] + missing_commands = list(filter(lambda cmd: shutil.which(cmd) == None, required_commands)) + if missing_commands != []: + missing_commands = ", ".join(missing_commands) + print(f"Missing commands: {missing_commands} -- ABORT", file=sys.stderr) sys.exit(1) logging.info('Basic utils installed')