-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_manager.py
More file actions
79 lines (63 loc) · 2.8 KB
/
Copy pathplugin_manager.py
File metadata and controls
79 lines (63 loc) · 2.8 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from pathlib import Path
from typing import Dict, Any, Optional
import importlib
import yaml
from .config import config
class PluginManager:
"""Manages provider plugins"""
def __init__(self):
self.plugins_dir = Path.home() / ".repoforge" / "plugins"
self.plugins_dir.mkdir(exist_ok=True)
self.installed_plugins = self._load_plugins()
def _load_plugins(self) -> Dict[str, Dict[str, Any]]:
plugins_file = self.plugins_dir / "installed.yaml"
if plugins_file.exists():
with open(plugins_file, 'r') as f:
return yaml.safe_load(f) or {}
return {}
def _save_plugins(self):
plugins_file = self.plugins_dir / "installed.yaml"
with open(plugins_file, 'w') as f:
yaml.safe_dump(self.installed_plugins, f, default_flow_style=False)
def install(self, provider_name: str, provider_config: Optional[Dict[str, Any]] = None) -> bool:
"""Install a provider plugin"""
from .providers.registry import ProviderRegistry
provider_class = ProviderRegistry.get_provider(provider_name)
if not provider_class:
return False
if provider_name in self.installed_plugins:
return False
self.installed_plugins[provider_name] = {
"enabled": True,
"config": provider_config or {}
}
self._save_plugins()
return True
def uninstall(self, provider_name: str) -> bool:
"""Uninstall a provider plugin"""
if provider_name not in self.installed_plugins:
return False
del self.installed_plugins[provider_name]
self._save_plugins()
return True
def enable(self, provider_name: str) -> bool:
"""Enable a provider"""
if provider_name not in self.installed_plugins:
return False
self.installed_plugins[provider_name]["enabled"] = True
self._save_plugins()
return True
def disable(self, provider_name: str) -> bool:
"""Disable a provider"""
if provider_name not in self.installed_plugins:
return False
self.installed_plugins[provider_name]["enabled"] = False
self._save_plugins()
return True
def get_enabled_providers(self) -> list:
"""Get list of enabled providers"""
return [name for name, info in self.installed_plugins.items() if info.get("enabled", False)]
def get_provider_config(self, provider_name: str) -> Optional[Dict[str, Any]]:
"""Get configuration for a provider"""
plugin = self.installed_plugins.get(provider_name)
return plugin.get("config") if plugin else None