Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
Signed-off-by: Aryan Rajoria <[email protected]>
  • Loading branch information
aryan-rajoria committed Nov 11, 2024
1 parent 7a7934d commit fad8e19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 55 deletions.
55 changes: 2 additions & 53 deletions blint_db/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 19 additions & 2 deletions blint_db/projects_compiler/vcpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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

0 comments on commit fad8e19

Please sign in to comment.