Commit f57b2024 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: listPlugins and selectPlugins share code for printing plugin list

parent 5ff0163b
......@@ -52,6 +52,43 @@ def downloadPluginManifest(url : Union[str, pathlib.Path]) -> Manifest:
return manifest
def _printPlugin(plugin : Plugin,
index : int = None,
verbose : bool = False):
"""Prints an overview of ``plugin``. Used by :func:`listPlugins` and
:func:`selectPlugins`.
:arg plugin: The :class:`.Plugin` to print.
:arg index: Plugin index number (optional).
:arg verbose: If ``True``, more information is printed.
"""
if index:
info(f'{index:2d} {plugin.name:25s}', EMPHASIS, indent=2)
else:
info(f'{plugin.name:25s}', EMPHASIS, indent=2)
if plugin.version is not None:
info(f'[version {plugin.version}]', indent=4)
if plugin.description is not None:
info(plugin.description, indent=4, wrap=True)
if plugin.termsOfUse is not None:
info('Installation of this plugin is subject '
'to the following terms of use:',
indent=4)
info(plugin.termsOfUse, indent=6, wrap=True)
if verbose:
for item in ('url', 'destination', 'checksum'):
value = getattr(plugin, item)
item = f'{item}:'
if value in (None, ''):
value = 'N/A'
info(f'{item:12s} {value}', indent=4)
def listPlugins(manifest : Manifest, verbose : bool = False):
"""Prints a list of all available plugins.
......@@ -67,27 +104,7 @@ def listPlugins(manifest : Manifest, verbose : bool = False):
plugins = manifest.getCategory(category)
for plugin in plugins:
info(f'{plugin.name:25s}', EMPHASIS, indent=2)
if plugin.version is not None:
info(f'Version {plugin.version}', indent=4)
if plugin.description is not None:
info(plugin.description, indent=4, wrap=True)
if plugin.termsOfUse is not None:
info('Installation of this plugin is subject to terms of use:',
indent=4)
info(plugin.termsOfUse, indent=6, wrap=True)
if verbose:
for item in ('url', 'destination', 'checksum'):
value = getattr(plugin, item)
item = f'{item}:'
if value in (None, ''):
value = 'N/A'
info(f'{item:12s} {value}', indent=4)
_printPlugin(plugin, verbose=verbose)
def createArchiveDir(archiveDir : Union[str, pathlib.Path]):
......@@ -180,10 +197,10 @@ def selectPlugins(manifest : Manifest, category : str = None) -> List[Plugin]:
that the user selected.
"""
plugins = list(manifest.keys())
plugins = list(manifest.values())
if category is not None:
plugins = [n for n in plugins if manifest[n].category == category]
plugins = [p for p in plugins if p.category == category]
if len(plugins) == 0:
error('No modules are available!')
......@@ -193,12 +210,8 @@ def selectPlugins(manifest : Manifest, category : str = None) -> List[Plugin]:
if category is not None:
info(f' (Only showing modules in the [{category}] category)')
for i, name in enumerate(plugins, 1):
plugin = manifest[name]
name = f'[{name}]'
info(f' {i} {name:25s}', EMPHASIS)
if plugin.description is not None:
info(plugin.description, indent=4)
for i, plugin in enumerate(plugins, 1):
_printPlugin(plugin, i)
if len(plugins) > 1:
plugins = _selectMultiplePlugins(plugins)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment