txoof / PaperPi

E-Paper display loop with plugins
97 stars 10 forks source link

menu-driven command line interface for configuring #139

Open txoof opened 11 months ago

txoof commented 11 months ago

Is your feature request related to a problem? Please describe. Add a command line interface for adding, removing and configuring plugins. Use the same interface to configure the main section of the config as well.

Describe the solution you'd like Add a function that can help users configure plugins by displaying fields, descriptions and checking for reasonable values. The interface should also reveal the user-facing helper functions that some plugins have (e.g. LMS search, lat/lon lookup). This should be a menu driven interface with yes/no questions, prompts for input.

Describe alternatives you've considered The JSON config file that will be rolled out in 0.6 is terrible to edit by hand

txoof commented 11 months ago

Update documentation for plugin configuration

Build menu driven interface for configuring JSON configuration

Connect menu driven interface to PaperPi from command line

txoof commented 11 months ago

see also #123 #130

rewrite user facing functions to have defined key-word args and also accept args and kwargs.

def get_coord(place=None, *args, **kwargs):
    '''USER FACING HELPER FUNCTION:
    lookup and print the latitude, longitude of a place given as a string:

    usage: --run_plugin_func met_no.get_coord "Horsetooth Reservoir, Fort Collins CO, USA"

    Args:
        place(`str`): "City, Provence, Country

    Returns:
        `tuple`: lat, lon

    Example:
        get_coord("Denver, Colorado, USA")
        get_coord("Bamako, Mali")
        %U'''

#     if args:
#         place = args[0]
#     elif 'place' in kwargs:
#         place = kwargs['place']
#     else:
#         place = None
....
      return (lat, lon)
txoof commented 9 months ago

weird crash when running from command line:

Traceback (most recent call last):
  File "/home/pi/src/PaperPi/paperpi/./paperpi.py", line 482, in <module>
    exit_code = main()
                ^^^^^^
  File "/home/pi/src/PaperPi/paperpi/./paperpi.py", line 365, in main
    interactive_config.interactive_config(config, backup_notify=True)
  File "/home/pi/src/PaperPi/paperpi/interactive_config.py", line 800, in interactive_config
    function(**kwargs)
  File "/home/pi/src/PaperPi/paperpi/interactive_config.py", line 658, in plugin_configuration
    configured_plugin, plugin_index = _configure_plugin(config_json, plugin_name)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/src/PaperPi/paperpi/interactive_config.py", line 533, in _configure_plugin
    module_json, config_index = _find_plugin_config(config_json, plugin_name)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/src/PaperPi/paperpi/interactive_config.py", line 345, in _find_plugin_config
    if plugin_name in plugin.get('plugin', {}).get('value', ''):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

This does not appear to happen when running in Jupyter.

Steps to reproduce:

  1. paperpi.py -i
  2. option (1) Configure Plugins
  3. configure a plugin? y
  4. (8) moon phase
  5. Run helper function? y
  6. (2) list_country_locales
  7. NL
  8. run one of the helper functions? n
  9. CRASH