fix some plugins
This commit is contained in:
@@ -115,6 +115,8 @@ class PluginHandler:
|
|||||||
|
|
||||||
# Populate local plugins
|
# Populate local plugins
|
||||||
for name, details in local_plugins.items():
|
for name, details in local_plugins.items():
|
||||||
|
if details.get("origin") == "core":
|
||||||
|
continue
|
||||||
state = "Disabled" if not details.get("enabled", True) else "Active"
|
state = "Disabled" if not details.get("enabled", True) else "Active"
|
||||||
color = "red" if state == "Disabled" else "green"
|
color = "red" if state == "Disabled" else "green"
|
||||||
|
|
||||||
@@ -123,11 +125,14 @@ class PluginHandler:
|
|||||||
state = "Shadowed (Override by Remote)"
|
state = "Shadowed (Override by Remote)"
|
||||||
color = "yellow"
|
color = "yellow"
|
||||||
|
|
||||||
table.add_row(name, f"[{color}]{state}[/{color}]", "Local")
|
origin = details.get("origin", "Local").capitalize()
|
||||||
|
table.add_row(name, f"[{color}]{state}[/{color}]", origin)
|
||||||
|
|
||||||
# Populate remote plugins
|
# Populate remote plugins
|
||||||
if self.app.services.mode == "remote":
|
if self.app.services.mode == "remote":
|
||||||
for name, details in remote_plugins.items():
|
for name, details in remote_plugins.items():
|
||||||
|
if details.get("origin") == "core":
|
||||||
|
continue
|
||||||
state = "Disabled" if not details.get("enabled", True) else "Active"
|
state = "Disabled" if not details.get("enabled", True) else "Active"
|
||||||
color = "red" if state == "Disabled" else "green"
|
color = "red" if state == "Disabled" else "green"
|
||||||
|
|
||||||
@@ -138,7 +143,8 @@ class PluginHandler:
|
|||||||
state = "Shadowed (Override by Local)"
|
state = "Shadowed (Override by Local)"
|
||||||
color = "yellow"
|
color = "yellow"
|
||||||
|
|
||||||
table.add_row(name, f"[{color}]{state}[/{color}]", "Remote")
|
origin = details.get("origin", "Remote").capitalize()
|
||||||
|
table.add_row(name, f"[{color}]{state}[/{color}]", origin)
|
||||||
|
|
||||||
if not local_plugins and not remote_plugins:
|
if not local_plugins and not remote_plugins:
|
||||||
printer.console.print(" No plugins found.")
|
printer.console.print(" No plugins found.")
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ def _get_plugins(which, defaultdir):
|
|||||||
if name not in final_all_plugins or preferences.get(name) == "remote":
|
if name not in final_all_plugins or preferences.get(name) == "remote":
|
||||||
final_all_plugins[name] = path
|
final_all_plugins[name] = path
|
||||||
|
|
||||||
# Combine enabled/disabled for the helper commands
|
# Combine enabled/disabled for the helper commands (excluding core plugins from management autocomplete)
|
||||||
enabled_files = list(set(user_enabled + core_enabled + [k for k,v in remote_all_plugins.items() if preferences.get(k) == "remote"]))
|
enabled_files = list(set(user_enabled + [k for k,v in remote_all_plugins.items() if preferences.get(k) == "remote"]))
|
||||||
disabled_files = list(set(user_disabled + core_disabled))
|
disabled_files = list(set(user_disabled))
|
||||||
|
|
||||||
# Return based on the command
|
# Return based on the command
|
||||||
if which == "--disable":
|
if which == "--disable":
|
||||||
@@ -356,7 +356,10 @@ def _build_tree(nodes, folders, profiles, plugins, configdir):
|
|||||||
},
|
},
|
||||||
"plugin": {
|
"plugin": {
|
||||||
"--add": {"*": lambda w: get_cwd(w, "--add")},
|
"--add": {"*": lambda w: get_cwd(w, "--add")},
|
||||||
"--update": {"*": lambda w: get_cwd(w, "--update")},
|
"--update": {
|
||||||
|
"__extra__": lambda w: _get_plugins("--update", configdir),
|
||||||
|
"*": lambda w: get_cwd(w, "--update")
|
||||||
|
},
|
||||||
"--del": lambda w: _get_plugins("--del", configdir),
|
"--del": lambda w: _get_plugins("--del", configdir),
|
||||||
"--enable": lambda w: _get_plugins("--enable", configdir),
|
"--enable": lambda w: _get_plugins("--enable", configdir),
|
||||||
"--disable": lambda w: _get_plugins("--disable", configdir),
|
"--disable": lambda w: _get_plugins("--disable", configdir),
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class PluginService(BaseService):
|
|||||||
if f.endswith(".py"):
|
if f.endswith(".py"):
|
||||||
name = f[:-3]
|
name = f[:-3]
|
||||||
path = os.path.join(core_dir, f)
|
path = os.path.join(core_dir, f)
|
||||||
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path)}
|
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path), "origin": "core"}
|
||||||
|
|
||||||
# 2. Scan shared plugins (medium priority)
|
# 2. Scan shared plugins (medium priority)
|
||||||
if hasattr(self.config, "_shared_config") and self.config._shared_config:
|
if hasattr(self.config, "_shared_config") and self.config._shared_config:
|
||||||
@@ -74,10 +74,10 @@ class PluginService(BaseService):
|
|||||||
if f.endswith(".py"):
|
if f.endswith(".py"):
|
||||||
name = f[:-3]
|
name = f[:-3]
|
||||||
path = os.path.join(shared_dir, f)
|
path = os.path.join(shared_dir, f)
|
||||||
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path)}
|
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path), "origin": "shared"}
|
||||||
elif f.endswith(".py.bkp"):
|
elif f.endswith(".py.bkp"):
|
||||||
name = f[:-7]
|
name = f[:-7]
|
||||||
all_plugin_info[name] = {"enabled": False}
|
all_plugin_info[name] = {"enabled": False, "origin": "shared"}
|
||||||
|
|
||||||
# 3. Scan user plugins (highest priority)
|
# 3. Scan user plugins (highest priority)
|
||||||
user_dir = os.path.join(self.config.defaultdir, "plugins")
|
user_dir = os.path.join(self.config.defaultdir, "plugins")
|
||||||
@@ -86,10 +86,10 @@ class PluginService(BaseService):
|
|||||||
if f.endswith(".py"):
|
if f.endswith(".py"):
|
||||||
name = f[:-3]
|
name = f[:-3]
|
||||||
path = os.path.join(user_dir, f)
|
path = os.path.join(user_dir, f)
|
||||||
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path)}
|
all_plugin_info[name] = {"enabled": True, "hash": get_hash(path), "origin": "user"}
|
||||||
elif f.endswith(".py.bkp"):
|
elif f.endswith(".py.bkp"):
|
||||||
name = f[:-7]
|
name = f[:-7]
|
||||||
all_plugin_info[name] = {"enabled": False}
|
all_plugin_info[name] = {"enabled": False, "origin": "user"}
|
||||||
|
|
||||||
return all_plugin_info
|
return all_plugin_info
|
||||||
|
|
||||||
|
|||||||
@@ -241,5 +241,28 @@ class TestSsoCompletions:
|
|||||||
assert "authelia" in completions
|
assert "authelia" in completions
|
||||||
|
|
||||||
|
|
||||||
|
class TestPluginUpdateCompletion:
|
||||||
|
def test_plugin_update_first_arg_suggests_plugins(self, tmp_path):
|
||||||
|
from connpy.completion import _build_tree, resolve_completion
|
||||||
|
|
||||||
|
# Create a mock user plugin
|
||||||
|
plugins_dir = tmp_path / "plugins"
|
||||||
|
plugins_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
(plugins_dir / "my_custom_plugin.py").touch()
|
||||||
|
|
||||||
|
# Build tree with plugin mock dict
|
||||||
|
plugins = {"my_custom_plugin": str(plugins_dir / "my_custom_plugin.py")}
|
||||||
|
tree = _build_tree([], [], [], plugins, str(tmp_path))
|
||||||
|
|
||||||
|
# First argument of --update should suggest my_custom_plugin
|
||||||
|
completions = resolve_completion(["plugin", "--update", ""], tree)
|
||||||
|
assert "my_custom_plugin" in completions
|
||||||
|
|
||||||
|
# Second argument should suggest file paths (calling get_cwd)
|
||||||
|
# Type "plugin --update my_custom_plugin "
|
||||||
|
file_completions = resolve_completion(["plugin", "--update", "my_custom_plugin", ""], tree)
|
||||||
|
assert isinstance(file_completions, list)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user