mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
rename vars
This commit is contained in:
@ -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}")
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user