Easy_Import_Export_NAT-4.1/build_zip.py

32 lines
1.2 KiB
Python

import zipfile, os, shutil
src_dir = os.path.dirname(os.path.abspath(__file__))
pkg_name = "easy_import_nat.ocmod.zip"
zip_path = os.path.join(src_dir, pkg_name)
if os.path.exists(zip_path):
os.remove(zip_path)
print("Deleted old zip")
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
# OC 4: root must have install.json, admin, catalog, system directly
for fname in ['install.json', 'readme.txt', 'Instruction ru-uk-en.txt']:
fpath = os.path.join(src_dir, fname)
if os.path.exists(fpath):
zipf.write(fpath, fname)
print(f"Added {fname}")
for fldr in ['admin', 'catalog', 'system']:
dir_path = os.path.join(src_dir, fldr)
if os.path.exists(dir_path):
for root, dirs, files in os.walk(dir_path):
for file in files:
file_path = os.path.join(root, file)
arc_name = os.path.relpath(file_path, src_dir).replace('\\', '/')
zipf.write(file_path, arc_name)
# Also create formatted distribution name
dist_name = "easy_import_export_nat_OC_41_1_0.ocmod.zip"
shutil.copy2(zip_path, os.path.join(src_dir, dist_name))
print(f"Created packages: {pkg_name} and {dist_name}")