common: Modify package checking code to use 'which' 21/310221/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Fri, 19 Apr 2024 10:30:58 +0000 (19:30 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Wed, 24 Apr 2024 06:59:16 +0000 (15:59 +0900)
Since apt is not a default package of python, shutil.which is used to
increase portability.

Change-Id: I1745f065f0772bffdafd90ea50daf4d67d6338af
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
mk_delta/common/bin/CreatePatch.py

index f9d9058..6443038 100755 (executable)
@@ -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')