Skip to content

Commit 079b7fa

Browse files
reckless install: check and warn if a plugin is already installed.
1 parent edecdfe commit 079b7fa

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

tests/test_reckless.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ def test_install(node_factory):
274274
print(plugin_path)
275275
assert os.path.exists(plugin_path)
276276

277+
# Try to install again - should result in a warning.
278+
r = reckless([f"--network={NETWORK}", "-v", "install", "testplugpass"], dir=n.lightning_dir)
279+
r.check_stderr()
280+
assert r.search_stdout('already installed')
281+
assert r.returncode == 0
282+
277283

278284
def test_install_cleanup(node_factory):
279285
"""test failed installation and post install cleanup"""

tools/reckless

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,20 @@ def install(plugin_name: str) -> Union[str, None]:
17461746
LAST_FOUND = None
17471747
return None
17481748

1749+
# Check if we already have this installed.
1750+
destination = Path(RECKLESS_CONFIG.reckless_dir) / name.lower()
1751+
1752+
if Path(destination).exists():
1753+
# should we run listinstalled first and see what's in the list?
1754+
installed = listinstalled(plugin_name)
1755+
if installed:
1756+
log.info(f'already installed: {list(installed.keys())[0]} in {str(destination)}')
1757+
return name
1758+
else:
1759+
log.warning(f'destination directory {destination} already exists.')
1760+
return None
1761+
1762+
17491763
try:
17501764
installed = _install_plugin(src)
17511765
except FileExistsError as err:
@@ -2160,15 +2174,18 @@ def extract_metadata(plugin_name: str) -> dict:
21602174
return metadata
21612175

21622176

2163-
def listinstalled():
2164-
"""list all plugins currently managed by reckless"""
2177+
def listinstalled(name: str = None):
2178+
"""list all plugins currently managed by reckless. Optionally passed
2179+
a plugin name."""
21652180
dir_contents = os.listdir(RECKLESS_CONFIG.reckless_dir)
21662181
plugins = {}
21672182
for plugin in dir_contents:
21682183
if (Path(RECKLESS_CONFIG.reckless_dir) / plugin).is_dir():
21692184
# skip hidden dirs such as reckless' .remote_sources
21702185
if plugin[0] == '.':
21712186
continue
2187+
if name and name != plugin:
2188+
continue
21722189
plugins.update({plugin: None})
21732190

21742191
# Format output in a simple table
@@ -2201,8 +2218,9 @@ def listinstalled():
22012218
status = "disabled"
22022219
else:
22032220
print(f'cant handle {line}')
2204-
log.info(f"{plugin:<{name_len}} {md['installed commit']:<{inst_len}} "
2205-
f"{md['installation date']:<11} {status}")
2221+
if not name:
2222+
log.info(f"{plugin:<{name_len}} {md['installed commit']:<{inst_len}} "
2223+
f"{md['installation date']:<11} {status}")
22062224
# This doesn't originate from the metadata, but we want to provide enabled status for json output
22072225
md['enabled'] = status == "enabled"
22082226
md['entrypoint'] = installed.entry

0 commit comments

Comments
 (0)