-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.py
More file actions
47 lines (35 loc) · 1.32 KB
/
Copy pathpackage.py
File metadata and controls
47 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""Build the plugin zip for distribution."""
import os
import re
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent
def get_plugin_dir() -> str:
"""Find the plugin directory (the one with metadata.txt)."""
for child in ROOT.iterdir():
if child.is_dir() and (child / "metadata.txt").exists():
return child.name
raise FileNotFoundError("No plugin directory with metadata.txt found")
def get_version(plugin_dir: str) -> str:
meta = ROOT / plugin_dir / "metadata.txt"
m = re.search(r"^version=(.+)", meta.read_text(), re.M)
return m.group(1).strip() if m else "0.0.0"
def build():
plugin = get_plugin_dir()
version = get_version(plugin)
zip_name = ROOT / f"{plugin}-{version}.zip"
with zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED) as zf:
src = ROOT / plugin
for path in sorted(src.rglob("*")):
rel = path.relative_to(src)
parts = rel.parts
if any(p.startswith(".") or p == "__pycache__" for p in parts):
continue
if path.is_file():
zf.write(path, f"{plugin}/{rel}")
size = os.path.getsize(zip_name)
print(f"Built: {zip_name.name} ({size / 1024:.0f} KB)")
return zip_name.name
if __name__ == "__main__":
build()