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

RF: Select functions accept/return plugin objects, rather than plugin names

parent f57b2024
......@@ -121,34 +121,34 @@ def createArchiveDir(archiveDir : Union[str, pathlib.Path]):
f'{archiveDir}!') from e
def _selectOnePlugin(pluginName : str) -> List[str]:
def _selectOnePlugin(plugin : Plugin) -> List[Plugin]:
"""Sub-function of :func:`selectPlugins` called when there is only one
plugin available to install. Asks the user if they would like to install
the plugin.
:arg pluginName: Name of the available plugin
:returns: Either ``[pluginName]``, or ``[]``, depending on whether
the user selected the plugin.
:arg plugin: The available plugin
:returns: Either ``[plugin]``, or ``[]``, depending on whether
the user selected the plugin.
"""
question(f'Do you want to download the [{pluginName}] module?', EMPHASIS)
question(f'Do you want to download the [{plugin.name}] module?', EMPHASIS)
info('Press enter or type Y to confirm the installation. Any other '
'response will cancel the download.', indent=2, wrap=True)
response = prompt(f'Install [{pluginName}]? (Y/n): ')
response = prompt(f'Install [{plugin.name}]? (Y/n): ')
if response.lower() in ('', 'y', 'yes'):
return [pluginName]
return [plugin]
else:
return []
def _selectMultiplePlugins(pluginNames : List[str]) -> List[str]:
def _selectMultiplePlugins(plugins : List[Plugin]) -> List[Plugin]:
"""Sub-function of :func:`selectPlugins` called when there are multiple
plugins available to install. Prompts the user to select which plugins to
install.
:arg pluginNames: List of available plugins.
:returns: List of plugins selected by the user.
:arg plugins: List of available plugins.
:returns: List of plugins selected by the user.
"""
while True:
......@@ -156,29 +156,28 @@ def _selectMultiplePlugins(pluginNames : List[str]) -> List[str]:
info('Type "all" to download all of the modules that are listed. '
'Alternately, enter the numbers of each module you would like '
'to download, separated by spaces. For example, if you would '
f'like to download the [{pluginNames[0]}] and [{pluginNames[1]}] '
'modules, enter "1 2".', indent=2, wrap=True)
f'like to download the [{plugins[0].name}] and '
'[{plugins[1],name}] modules, enter "1 2".', indent=2, wrap=True)
plugins = prompt('Enter module(s) to download: ')
response = prompt('Enter module(s) to download: ')
if plugins.lower() == 'all':
plugins = pluginNames
if response.lower() == 'all':
break
try:
plugins = [int(t) for t in plugins.split()]
response = [int(i) for i in response.split()]
except Exception:
error(f'Specified module(s) {plugins} not understood')
error(f'Specified module(s) {response} not understood')
continue
if len(plugins) == 0:
if len(response) == 0:
warning('No modules specified! Type "all" to '
'download all modules.', wrap=True)
continue
if any([p <= 0 or p > len(pluginNames) for p in plugins]):
error(f'One of the requested modules [{plugins}] does not exist')
if any([i <= 0 or i > len(plugins) for i in response]):
error(f'One of the requested modules [{response}] does not exist')
continue
plugins = [pluginNames[p - 1] for p in plugins]
plugins = [plugins[i - 1] for i in response]
break
return plugins
......@@ -207,11 +206,13 @@ def selectPlugins(manifest : Manifest, category : str = None) -> List[Plugin]:
return []
important('Modules available for download:', EMPHASIS)
info('')
if category is not None:
info(f' (Only showing modules in the [{category}] category)')
for i, plugin in enumerate(plugins, 1):
_printPlugin(plugin, i)
info('')
if len(plugins) > 1:
plugins = _selectMultiplePlugins(plugins)
......@@ -224,9 +225,9 @@ def selectPlugins(manifest : Manifest, category : str = None) -> List[Plugin]:
important('Modules selected for installation:', EMPHASIS)
for p in plugins:
info(f' {p}', EMPHASIS)
info(f' {p.name}', EMPHASIS)
return [manifest[p] for p in plugins]
return plugins
def _checkExist(dirname : Union[str, pathlib.Path]):
......
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