mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
pack + make in one file
This commit is contained in:
@ -5,6 +5,8 @@ import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
from fnmatch import fnmatch
|
||||
import argparse
|
||||
import zipfile
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description='Pack plugins')
|
||||
@ -154,6 +156,83 @@ def should_exclude(path, base_dir, excludes):
|
||||
|
||||
return False
|
||||
|
||||
def pack_plugins_old():
|
||||
content_dir = "../sdkjs-plugins/content/"
|
||||
|
||||
if not os.path.exists(content_dir):
|
||||
print(f"Directory {content_dir} does not exist")
|
||||
return
|
||||
|
||||
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
|
||||
|
||||
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(destination_path):
|
||||
delete_dir(destination_path)
|
||||
|
||||
copy_dir(plugin_path, zip_file)
|
||||
|
||||
# Create .zip
|
||||
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(destination_path, f"{plugin_name}.plugin")
|
||||
move_file(zip_file_path, plugin_file_path)
|
||||
|
||||
# Remove temp folder
|
||||
delete_dir(zip_file)
|
||||
|
||||
print(f"Processed plugin: {plugin_name}")
|
||||
|
||||
def copy_dir(src, dst):
|
||||
if os.path.exists(dst):
|
||||
delete_dir(dst)
|
||||
shutil.copytree(src, dst)
|
||||
|
||||
def archive_folder(source_pattern, zip_path):
|
||||
source_dir = source_pattern.rstrip('/*')
|
||||
os.makedirs(os.path.dirname(zip_path), exist_ok=True)
|
||||
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
for root, dirs, files in os.walk(source_dir):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
|
||||
if root == source_dir:
|
||||
arcname = file
|
||||
else:
|
||||
arcname = os.path.relpath(file_path, source_dir)
|
||||
|
||||
zipf.write(file_path, arcname)
|
||||
|
||||
def move_file(src, dst):
|
||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||
|
||||
# Attempt to move the file
|
||||
for attempt in range(3):
|
||||
try:
|
||||
shutil.move(src, dst)
|
||||
break
|
||||
except PermissionError:
|
||||
if attempt < 2:
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
raise
|
||||
|
||||
if __name__ == "__main__":
|
||||
pack_plugins()
|
||||
args = parse_arguments()
|
||||
old_mode = args.old_mode
|
||||
|
||||
if args.old_mode:
|
||||
pack_plugins_old()
|
||||
else:
|
||||
pack_plugins()
|
||||
|
||||
Reference in New Issue
Block a user