Skip to content

Commit

Permalink
walk loop now exists if archive is already in database and logging fi…
Browse files Browse the repository at this point in the history
…les only in debug mode
  • Loading branch information
Ati1707 committed Dec 9, 2024
1 parent a3a604f commit a4aa133
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions content_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import threading
from pathlib import Path

from helper.config_operations import get_library_path

from helper.config_operations import get_library_path, get_debug_mode

lock = threading.Lock()

Expand Down Expand Up @@ -101,7 +100,8 @@ def delete_archive(archive_name: str) -> None:
try:
if file_path.exists():
file_path.unlink()
logging.info(f"Deleted file: {file_path}")
if get_debug_mode():
logging.info(f"Deleted file: {file_path}")
except Exception as e:
logging.error(f"Error deleting file {file_path}: {e}")

Expand Down
14 changes: 14 additions & 0 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
# Create a threading lock
lock = threading.Lock()

archive_exists = False


def get_relative_path(full_path: str) -> str:
"""
Expand Down Expand Up @@ -100,6 +102,8 @@ def add_to_database(root_path: pathlib.Path, item: pathlib.Path) -> bool:

if content_database.does_archive_exist(archive_name, file_list):
logger.info(f"Archive '{archive_name}' already exists in the database.")
global archive_exists
archive_exists = True
return True
else:
logger.info(f"Adding archive '{archive_name}' with {len(file_list)} files to the database.")
Expand Down Expand Up @@ -145,13 +149,16 @@ def process_manifest_and_target_folders(root_path, dirs, files, progressbar, cur
if manifest_exists and folder.lower().startswith("content"):
content_path = root_path / folder
clean_folder(content_path)
progressbar.set(progressbar.get() + 0.1)
if add_to_database(content_path, current_item):
progressbar.set(progressbar.get() + 0.1)
return False
shutil.copytree(content_path, get_library_path(), dirs_exist_ok=True)
return True

if any(target.lower() == folder.lower() for target in TARGET_FOLDERS):
clean_folder(root_path)
progressbar.set(progressbar.get() + 0.1)
if add_to_database(root_path, current_item):
return False
shutil.copytree(root_path, get_library_path(), dirs_exist_ok=True)
Expand All @@ -165,10 +172,17 @@ def traverse_directory(folder_path: pathlib.Path, current_item: pathlib.Path, pr
"""
for root, dirs, files in folder_path.walk():
root_path = pathlib.Path(root)

if handle_nested_archives(root_path, files, is_debug_mode):
progressbar.set(progressbar.get() + 0.1)
return traverse_directory(folder_path, current_item, progressbar, is_debug_mode)
if process_manifest_and_target_folders(root_path, dirs, files, progressbar, current_item):
progressbar.set(progressbar.get() + 0.1)
return True
if archive_exists:
return False
progressbar.set(progressbar.get() + 0.1)

return False


Expand Down

0 comments on commit a4aa133

Please sign in to comment.