From fad8e19859cd3f0db336cda41719d01f748ed3f8 Mon Sep 17 00:00:00 2001 From: Aryan Rajoria Date: Mon, 11 Nov 2024 09:22:45 +0100 Subject: [PATCH] refactor code Signed-off-by: Aryan Rajoria --- blint_db/cli.py | 55 ++--------------------------- blint_db/projects_compiler/vcpkg.py | 21 +++++++++-- 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/blint_db/cli.py b/blint_db/cli.py index 92ae274..d25acc4 100644 --- a/blint_db/cli.py +++ b/blint_db/cli.py @@ -13,8 +13,8 @@ get_wrapdb_projects from blint_db.handlers.sqlite_handler import (clear_sqlite_database, create_database) -from blint_db.projects_compiler.meson import mt_meson_blint_db_build -from blint_db.projects_compiler.vcpkg import mt_vcpkg_blint_db_build +from blint_db.projects_compiler.meson import mt_meson_blint_db_build, meson_add_blint_bom_process +from blint_db.projects_compiler.vcpkg import mt_vcpkg_blint_db_build, vcpkg_add_blint_bom_process def arguments_parser(): @@ -112,57 +112,6 @@ def reset_and_backup(): COMMON_CONNECTION.execute(f"vacuum main into '{BLINTDB_LOCATION}'") -def meson_add_blint_bom_process(test_mode=False, sel_project: List = None): - projects_list = get_wrapdb_projects() - if test_mode: - projects_list = projects_list[:10] - if sel_project: - projects_list = sel_project - - # build the projects single threaded - # st_meson_blint_db_build(projects_list) - - with futures.ProcessPoolExecutor(max_workers=4) as executor: - for project_name, executables in zip( - projects_list, executor.map(mt_meson_blint_db_build, projects_list) - ): - print(f"Ran complete for {project_name} and we found {len(executables)}") - - -def remove_temp_ar(): - """ - Removes `ar-temp-########` files created by blint extract-ar function, - after we have completed our tasks. - """ - - try: - for dirname in Path("/tmp").glob("ar-temp-*"): - try: - shutil.rmtree(dirname) - except OSError as e: - print(f"Error deleting file {dirname}: {e}") - except Exception as e: - print(f"Error during cleanup: {e}") - - -def vcpkg_add_blint_bom_process(test_mode=False, sel_project: List = None): - projects_list = get_vcpkg_projects() - if test_mode: - projects_list = projects_list[:10] - if sel_project: - projects_list = sel_project - count = 0 - for project_name in projects_list: - executables = mt_vcpkg_blint_db_build(project_name) - print(f"Ran complete for {project_name} and we found {len(executables)}") - remove_vcpkg_project(project_name) - count += 1 - if count == 100: - reset_and_backup() - remove_temp_ar() - count = 0 - - def main(): """ Main entry point for the blint_db application. diff --git a/blint_db/projects_compiler/vcpkg.py b/blint_db/projects_compiler/vcpkg.py index abcc5b9..6faab98 100644 --- a/blint_db/projects_compiler/vcpkg.py +++ b/blint_db/projects_compiler/vcpkg.py @@ -3,6 +3,8 @@ import traceback from sqlite3 import OperationalError from typing import List +from pathlib import Path +import shutil from blint_db import DEBUG_MODE, VCPKG_HASH, VCPKG_LOCATION, VCPKG_URL, logger from blint_db.handlers.blint_handler import get_blint_internal_functions_exe @@ -99,8 +101,22 @@ def mt_vcpkg_blint_db_build(project_name): return [False] return execs +def remove_temp_ar(): + """ + Removes `ar-temp-########` files created by blint extract-ar function, + after we have completed our tasks. + """ + + try: + for dirname in Path("/tmp").glob("ar-temp-*"): + try: + shutil.rmtree(dirname) + except OSError as e: + print(f"Error deleting file {dirname}: {e}") + except Exception as e: + print(f"Error during cleanup: {e}") -def vcpkg_add_blint_bom_process(test_mode=False, sel_project: List=None): +def vcpkg_add_blint_bom_process(test_mode=False, sel_project: List = None): projects_list = get_vcpkg_projects() if test_mode: projects_list = projects_list[:10] @@ -114,4 +130,5 @@ def vcpkg_add_blint_bom_process(test_mode=False, sel_project: List=None): count += 1 if count == 100: reset_and_backup() - count = 0 + remove_temp_ar() + count = 0 \ No newline at end of file