From b30210d2193aceaafa7d668627e7dca170b36795 Mon Sep 17 00:00:00 2001 From: Artur Date: Thu, 30 Oct 2025 14:30:46 +0300 Subject: [PATCH] rename vars --- packer/make.py | 57 +++++++++++++++++++++++--------------------------- packer/pack.py | 17 ++++++++------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/packer/make.py b/packer/make.py index 111c3251..9183e2ea 100644 --- a/packer/make.py +++ b/packer/make.py @@ -5,28 +5,22 @@ import shutil import time import zipfile -def is_exist(path): - return os.path.exists(path) - -def delete_dir(path, max_retries=3): - if not os.path.exists(path): - return - - for attempt in range(max_retries): - try: - shutil.rmtree(path) - break - except PermissionError as e: - if attempt < max_retries - 1: - print(f"Attempt {attempt + 1}: File in use... {path}") - time.sleep(1) # Wait before retry (1 second) - else: - print(f"Failed to delete {path}: {e}") - # Try alternative method - try: - os.system(f'rmdir /S /Q "{path}"') # For Windows - except: - pass +def delete_dir(path, max_retries=3, delay=1): + if not os.path.exists(path): + return + + for attempt in range(max_retries): + try: + shutil.rmtree(path) + return True + except PermissionError: + if attempt < max_retries - 1: + print(f"Attempt {attempt + 1}: File in use... {path}") + time.sleep(delay) + else: + print(f"Failed to delete {path}") + return False + return False def copy_dir(src, dst): if os.path.exists(dst): @@ -76,25 +70,26 @@ def pack_plugins(): if not os.path.isdir(plugin_path): continue - plugin_deploy_path = os.path.join(plugin_path, "deploy") - plugin_deploy_src_path = os.path.join(plugin_deploy_path, plugin_name) + destination_path = os.path.join(plugin_path, "deploy") + zip_file = os.path.join(destination_path, f"{plugin_name}") + # Remove old deploy folder - if os.path.exists(plugin_deploy_path): - delete_dir(plugin_deploy_path) + if os.path.exists(destination_path): + delete_dir(destination_path) - copy_dir(plugin_path, plugin_deploy_src_path) + copy_dir(plugin_path, zip_file) # Create .zip - zip_file_path = os.path.join(plugin_deploy_path, f"{plugin_name}.zip") - archive_folder(plugin_deploy_src_path + "/*", zip_file_path) + zip_file_path = os.path.join(destination_path, f"{plugin_name}.zip") + archive_folder(zip_file + "/*", zip_file_path) # Rename to .plugin - plugin_file_path = os.path.join(plugin_deploy_path, f"{plugin_name}.plugin") + plugin_file_path = os.path.join(destination_path, f"{plugin_name}.plugin") move_file(zip_file_path, plugin_file_path) # Remove temp folder - delete_dir(plugin_deploy_src_path) + delete_dir(zip_file) print(f"Processed plugin: {plugin_name}") diff --git a/packer/pack.py b/packer/pack.py index e2f83d1f..0272d601 100644 --- a/packer/pack.py +++ b/packer/pack.py @@ -26,7 +26,7 @@ def safe_rename(src, dst, max_retries=3, delay=1): return False return False -def safe_rmtree(path, max_retries=3, delay=1): +def delete_dir(path, max_retries=3, delay=1): if not os.path.exists(path): return @@ -36,10 +36,10 @@ def safe_rmtree(path, max_retries=3, delay=1): return True except PermissionError: if attempt < max_retries - 1: - print(f" Directory busy, retrying in {delay} second(s)...") + print(f"Attempt {attempt + 1}: File in use... {path}") time.sleep(delay) else: - print(f" Failed to remove directory after {max_retries} attempts: {path}") + print(f"Failed to delete {path}") return False return False @@ -50,12 +50,15 @@ def pack_plugins(): print(f"Content directory {content_dir} does not exist") return - artifacts_dir = f"artifacts" - os.makedirs(artifacts_dir, exist_ok=True) + destination_path = f"artifacts" + os.makedirs(destination_path, exist_ok=True) for plugin_name in os.listdir(content_dir): plugin_path = os.path.join(content_dir, plugin_name) + if not os.path.isdir(plugin_path): + continue + # Load exclusion configuration for this specific plugin plugin_config_path = os.path.join(plugin_path, ".dev", "config.json") excludes = [] @@ -99,9 +102,9 @@ def pack_plugins(): print(f"[{plugin_name}] Error: {e}") finally: # Clean up temporary directory - safe_rmtree(temp_dir) + delete_dir(temp_dir) else: - zip_file = os.path.join(artifacts_dir, f"{plugin_name}") + zip_file = os.path.join(destination_path, f"{plugin_name}") # Create zip zip_path = shutil.make_archive(zip_file, 'zip', plugin_path)