From 4b8ceb7a8d3e79168eab2178b23e05a73c287590 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:37:40 +0530 Subject: [PATCH] creat #cache function --- blackbox/Functions.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/blackbox/Functions.py b/blackbox/Functions.py index 10ec4f0..5c63d32 100644 --- a/blackbox/Functions.py +++ b/blackbox/Functions.py @@ -1225,3 +1225,45 @@ def query_pkg(package): return False except Exception as e: logger.error("Exception in LOC1206: %s " % e) + +def cache(package, path_dir_cache): + try: + pkg = package.strip() + query_str = [ + "pacman", + "-Si", + pkg, + " --noconfirm", + ] + process = subprocess.Popen( + query_str, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + out, err = process.communicate() + if process.returncode == 0: + # out, err = process.communicate() + + output = out.decode("utf-8") + + if len(output) > 0: + split = output.splitlines() + desc = str(split[3]) # Ref: LOC:963 + description = desc[18:] # Ref: LOC:964 + filename = path_dir_cache + pkg + + file = open(filename, "w") + file.write(description) + file.close() + + return description + + if process.returncode != 0: + exceptions = [ + "cached-package-goes-here" + ] + if pkg in exceptions: + description = file_lookup(pkg, path_dir_cache + "corrections/") + return description + return "No Description Found" + + except Exception as e: + logger.error("Exception in cache(): %s " % e)