Create a new plugin from template. Args: name: Plugin name (used for directory and module) target_dir: Optional target directory (defaults to ~/.lichtfeld/plugins) Returns: Path to created plugin directory Raises: FileExistsError: If plugin directory al
(name: str, target_dir: Optional[Path] = None)
| 145 | |
| 146 | |
| 147 | def create_plugin(name: str, target_dir: Optional[Path] = None) -> Path: |
| 148 | """Create a new plugin from template. |
| 149 | |
| 150 | Args: |
| 151 | name: Plugin name (used for directory and module) |
| 152 | target_dir: Optional target directory (defaults to ~/.lichtfeld/plugins) |
| 153 | |
| 154 | Returns: |
| 155 | Path to created plugin directory |
| 156 | |
| 157 | Raises: |
| 158 | FileExistsError: If plugin directory already exists |
| 159 | """ |
| 160 | if target_dir is None: |
| 161 | target_dir = Path.home() / ".lichtfeld" / "plugins" |
| 162 | |
| 163 | plugin_dir = target_dir / name |
| 164 | if plugin_dir.exists(): |
| 165 | raise FileExistsError(f"Plugin directory already exists: {plugin_dir}") |
| 166 | |
| 167 | title = name.replace("_", " ").title() |
| 168 | |
| 169 | plugin_dir.mkdir(parents=True, exist_ok=True) |
| 170 | (plugin_dir / "panels").mkdir(exist_ok=True) |
| 171 | |
| 172 | (plugin_dir / "pyproject.toml").write_text(PYPROJECT_TOML.format(name=name)) |
| 173 | (plugin_dir / "__init__.py").write_text(INIT_PY.format(name=name)) |
| 174 | (plugin_dir / "panels" / "__init__.py").write_text("") |
| 175 | (plugin_dir / "panels" / "main_panel.py").write_text( |
| 176 | MAIN_PANEL_PY.format(name=name, title=title) |
| 177 | ) |
| 178 | (plugin_dir / "panels" / "main_panel.rml").write_text( |
| 179 | MAIN_PANEL_RML.format(name=name, title=title) |
| 180 | ) |
| 181 | (plugin_dir / "panels" / "main_panel.rcss").write_text(MAIN_PANEL_RCSS) |
| 182 | |
| 183 | _log.info("Created plugin template at %s", plugin_dir) |
| 184 | return plugin_dir |