89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Install the AirDbg plugin into the current user's home-local plugin directory."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
from typing import Any, Dict
|
|
|
|
PLUGIN_NAME = "airdbg"
|
|
|
|
|
|
def copy_plugin(source: Path, target: Path) -> None:
|
|
if source.resolve() == target.resolve():
|
|
return
|
|
if target.exists():
|
|
shutil.rmtree(target)
|
|
ignore = shutil.ignore_patterns("__pycache__", "*.pyc", ".DS_Store", ".git")
|
|
shutil.copytree(source, target, ignore=ignore)
|
|
|
|
|
|
def marketplace_payload() -> Dict[str, Any]:
|
|
return {
|
|
"name": "local-airdbg",
|
|
"interface": {"displayName": "Local AirDbg Plugins"},
|
|
"plugins": [],
|
|
}
|
|
|
|
|
|
def update_marketplace(path: Path) -> None:
|
|
if path.exists():
|
|
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
else:
|
|
payload = marketplace_payload()
|
|
|
|
payload.setdefault("name", "local-airdbg")
|
|
payload.setdefault("interface", {}).setdefault("displayName", "Local AirDbg Plugins")
|
|
plugins = payload.setdefault("plugins", [])
|
|
|
|
entry = {
|
|
"name": PLUGIN_NAME,
|
|
"source": {
|
|
"source": "local",
|
|
"path": f"./plugins/{PLUGIN_NAME}",
|
|
},
|
|
"policy": {
|
|
"installation": "INSTALLED_BY_DEFAULT",
|
|
"authentication": "ON_INSTALL",
|
|
},
|
|
"category": "Productivity",
|
|
}
|
|
|
|
for index, existing in enumerate(plugins):
|
|
if existing.get("name") == PLUGIN_NAME:
|
|
plugins[index] = entry
|
|
break
|
|
else:
|
|
plugins.append(entry)
|
|
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description="Install AirDbg as a home-local Codex plugin.")
|
|
parser.add_argument("--source", default=str(Path(__file__).resolve().parents[1]))
|
|
parser.add_argument("--home", default=str(Path.home()))
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
source = Path(args.source).expanduser().resolve()
|
|
home = Path(args.home).expanduser().resolve()
|
|
target = home / "plugins" / PLUGIN_NAME
|
|
marketplace = home / ".agents" / "plugins" / "marketplace.json"
|
|
|
|
copy_plugin(source, target)
|
|
update_marketplace(marketplace)
|
|
|
|
print(f"installed_plugin={target}")
|
|
print(f"marketplace={marketplace}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|