82 lines
2.7 KiB
Python
Executable file
82 lines
2.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import os
|
|
import zipfile
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
# --- CONFIGURATION ---
|
|
# Folders to include in the backup zip
|
|
INCLUDE_DIRS = [
|
|
"mods",
|
|
"config",
|
|
"kubejs",
|
|
"defaultconfigs",
|
|
"resourcepacks",
|
|
"shaderpacks",
|
|
"fancymenu_data", # Common layout mod folder
|
|
]
|
|
|
|
# Root files to include
|
|
INCLUDE_FILES = [
|
|
"options.txt",
|
|
"optionsshaders.txt",
|
|
"optionsof.txt",
|
|
]
|
|
|
|
def create_modpack_zip():
|
|
# Use current working directory where the script is executed
|
|
base_dir = Path.cwd()
|
|
|
|
# Generate timestamped filename
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
output_filename = f"Modpack_Export_{timestamp}.zip"
|
|
output_filepath = base_dir / output_filename
|
|
|
|
print("=========================================")
|
|
print(f"📦 Packaging Modpack from: {base_dir}")
|
|
print("=========================================\n")
|
|
|
|
files_added = 0
|
|
|
|
# Create ZIP using DEFLATED compression
|
|
with zipfile.ZipFile(output_filepath, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
|
|
|
# 1. Process Folders
|
|
for folder_name in INCLUDE_DIRS:
|
|
folder_path = base_dir / folder_name
|
|
if folder_path.is_dir():
|
|
print(f" [+] Adding folder: {folder_name}/")
|
|
for root, dirs, files in os.walk(folder_path):
|
|
for file in files:
|
|
file_path = Path(root) / file
|
|
# Preserve relative path inside zip
|
|
arcname = file_path.relative_to(base_dir)
|
|
zipf.write(file_path, arcname)
|
|
files_added += 1
|
|
else:
|
|
print(f" [-] Skipping (folder not found): {folder_name}/")
|
|
|
|
print()
|
|
|
|
# 2. Process Files
|
|
for file_name in INCLUDE_FILES:
|
|
file_path = base_dir / file_name
|
|
if file_path.is_file():
|
|
print(f" [+] Adding file: {file_name}")
|
|
zipf.write(file_path, file_name)
|
|
files_added += 1
|
|
else:
|
|
print(f" [-] Skipping (file not found): {file_name}")
|
|
|
|
print("\n=========================================")
|
|
if files_added > 0:
|
|
file_size_mb = output_filepath.stat().st_size / (1024 * 1024)
|
|
print(f"✅ SUCCESS! Packaged {files_added} files.")
|
|
print(f"💾 Saved as: {output_filename} ({file_size_mb:.2f} MB)")
|
|
else:
|
|
print("⚠️ WARNING: No files found to package. Check your execution folder.")
|
|
output_filepath.unlink(missing_ok=True) # Remove empty zip
|
|
print("=========================================")
|
|
|
|
if __name__ == "__main__":
|
|
create_modpack_zip()
|