Start implementing weectl extension

This commit is contained in:
Tom Keffer
2022-12-26 13:53:46 -08:00
parent 35a1c4d2e0
commit b21c37a9b6
3 changed files with 97 additions and 2 deletions

15
TODO.md
View File

@@ -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
```

View File

@@ -25,7 +25,7 @@ usagestr = """weectl -v|--version
weectl daemon --help
"""
SUBCOMMANDS = ['station', 'daemon']
SUBCOMMANDS = ['station', 'daemon', 'extension']
# ===============================================================================

View File

@@ -0,0 +1,82 @@
#!/usr/bin/env python
#
# Copyright (c) 2009-2023 Tom Keffer <tkeffer@gmail.com> 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}.")