From b21c37a9b61be14eb68c4055f8a4e25d09368d2c Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Mon, 26 Dec 2022 13:53:46 -0800 Subject: [PATCH] Start implementing `weectl extension` --- TODO.md | 15 +++++- bin/weectl.py | 2 +- bin/weectllib/parse_extension.py | 82 ++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 bin/weectllib/parse_extension.py diff --git a/TODO.md b/TODO.md index 1c32f82b..934fa664 100644 --- a/TODO.md +++ b/TODO.md @@ -5,7 +5,8 @@ Applications need to be converted into poetry scripts. ## Configuration related -Implement configuration for location. + +Change default directory to `~/weewx-data`. Check for validity of station_url. @@ -14,3 +15,15 @@ Check for validity of station_url. Make sure distutil isn't used anywhere. E.g., `distutils.copytree()`. +## Commands +``` +weectl station create +weectl station reconfigure +weectl station upgrade +weectl station upgrade-skins +weectl daemon install +weectl daemon uninstall +weectl extension install +weectl extension uninstall +weectl extension list +``` \ No newline at end of file diff --git a/bin/weectl.py b/bin/weectl.py index 48591dea..5848a204 100644 --- a/bin/weectl.py +++ b/bin/weectl.py @@ -25,7 +25,7 @@ usagestr = """weectl -v|--version weectl daemon --help """ -SUBCOMMANDS = ['station', 'daemon'] +SUBCOMMANDS = ['station', 'daemon', 'extension'] # =============================================================================== diff --git a/bin/weectllib/parse_extension.py b/bin/weectllib/parse_extension.py new file mode 100644 index 00000000..473527c0 --- /dev/null +++ b/bin/weectllib/parse_extension.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# +# Copyright (c) 2009-2023 Tom Keffer and Matthew Wall +# +# See the file LICENSE.txt for your rights. +# +"""Install and remove extensions.""" +import argparse +import sys + +import weewx +import weectllib +import weecfg.extension +import weeutil.logger +from weecfg import Logger +from weecfg.extension import ExtensionEngine +from weeutil.weeutil import to_int + +# Redirect the import of setup: +sys.modules['setup'] = weecfg.extension + +extension_list_usage = """weectllib extension list [--config=CONFIG-PATH] +""" +extension_install_usage = """ weectllib extension install {filename|directory|remote} + [--config=CONFIG-PATH] + [--tmpdir=DIR] [--dry-run] [--verbosity=N] +""" +extension_uninstall_usage = """ weectllib extension uninstall=EXTENSION + [--config=CONFIG-PATH] + [--dry-run] [--verbosity=N] +""" +extension_usage = '\n '.join((extension_list_usage, + extension_install_usage, + extension_uninstall_usage)) + + +def add_subparser(subparsers): + extension_parser = subparsers.add_parser('extension', + usage=extension_usage, + description='Manages WeeWX extensions', + help="Install, uninstall, or list " + "extensions") + action_parser = extension_parser.add_subparsers(dest='action', + title="Which action to take") + + # ---------- Action 'list' ---------- + list_extension_parser = action_parser.add_parser('list', + usage=extension_list_usage, + help='List all installed extensions') + list_extension_parser.add_argument('--config', + metavar='CONFIG-PATH', + help=f'Path to configuration file. ' + f'Default is "{weectllib.default_config_path}".') + + # ---------- Action 'install' ---------- + install_extension_parser = \ + action_parser.add_parser('install', + usage=extension_install_usage, + help="Install an extension contained in FILENAME " + " (such as pmon.tar.gz), or from a DIRECTORY, or from " + " an URL.") + install_extension_parser.add_argument('location', + metavar='FILE|DIR|URL', + help="Location of the extension. It can be either a " + "downloaded zipfile or tarball, an unpacked " + "directory, or an URL pointing to a zipfile " + "or tarball.") + install_extension_parser.add_argument('--config', + metavar='CONFIG-PATH', + help=f'Path to configuration file. ' + f'Default is "{weectllib.default_config_path}".') + install_extension_parser.add_argument('--tmpdir', + metavar='DIR', + help="Location of a temporarily directory to use if " + "a zipfile or tarball needs to be unpacked. " + "Optional.") + install_extension_parser.add_argument('--dry-run', + action='store_true', + help='Print what would happen, but do not actually ' + 'do it.') + install_extension_parser.add_argument('--verbosity', type=int, default=1, metavar='N', + help="How much information to display {0-3}.")