create_delivery_zip.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. #ident "@(#)$Format:LocalFoodAI:create_delivery_zip.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
  3. import os
  4. import zipfile
  5. import pathspec
  6. def main():
  7. repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. gitignore_path = os.path.join(repo_root, ".gitignore")
  9. if os.path.exists(gitignore_path):
  10. with open(gitignore_path, 'r') as f:
  11. spec = pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, f)
  12. else:
  13. spec = pathspec.PathSpec([])
  14. # Standard ignores
  15. spec.patterns.append(pathspec.patterns.GitWildMatchPattern('.git/'))
  16. spec.patterns.append(pathspec.patterns.GitWildMatchPattern('*.zip'))
  17. zip_path = os.path.join(repo_root, "delivery.zip")
  18. print(f"Building {zip_path}...")
  19. with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
  20. for root, dirs, files in os.walk(repo_root):
  21. for file in files:
  22. full_path = os.path.join(root, file)
  23. rel_path = os.path.relpath(full_path, repo_root)
  24. posix_path = rel_path.replace(os.sep, '/')
  25. # Check against .gitignore rules
  26. if not spec.match_file(posix_path):
  27. zipf.write(full_path, rel_path)
  28. print(f"Successfully created: delivery.zip")
  29. if __name__ == "__main__":
  30. main()