Skip to content

Commit

Permalink
Do not use wee_resources at all when doing Debian packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
tkeffer committed Mar 24, 2023
1 parent c75ee15 commit f52cf24
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
7 changes: 1 addition & 6 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# To do

## `weectl`

Do not have `weectl station create` copy in a fresh copy of the docs and examples. That's a job
for `weectl station upgrade`.

Need an option `--no-backup` for `weectl station reconfigure`.
## Debian packaging

Right now, the Debian installer depends heavily on sed script to modify weewx.conf. For example,
altitude. This should be done using `weectl station reconfigure`.
Expand Down
29 changes: 20 additions & 9 deletions bin/weecfg/station_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


def station_create(config_path, *args,
dist_config_path=None,
docs_root=None,
examples_root=None,
user_root=None,
Expand Down Expand Up @@ -62,12 +63,19 @@ def station_create(config_path, *args,
print(f"The configuration file will be created "
f"at {bcolors.BOLD}{config_path}{bcolors.ENDC}.")

# Retrieve the configuration file as a ConfigObj
with importlib.resources.open_text('wee_resources', 'weewx.conf', encoding='utf-8') as fd:
dist_config_dict = configobj.ConfigObj(fd, encoding='utf-8', file_error=True)
# Unless we've been given a path to the new configuration file, retrieve it from
# package resources.
if dist_config_path:
dist_config_dict = configobj.ConfigObj(dist_config_path, encoding='utf-8', file_error=True)
else:
# Retrieve the new configuration file from package resources:
with importlib.resources.open_text('wee_resources', 'weewx.conf', encoding='utf-8') as fd:
dist_config_dict = configobj.ConfigObj(fd, encoding='utf-8', file_error=True)

config_config(config_path, dist_config_dict, weewx_root=weewx_root, dry_run=dry_run,
*args, **kwargs)
copy_skins(dist_config_dict, dry_run=dry_run)
copy_util(config_path, dist_config_dict, dry_run=dry_run)
copy_docs(dist_config_dict, docs_root=docs_root, dry_run=dry_run)
copy_examples(dist_config_dict, examples_root=examples_root, dry_run=dry_run)
copy_user(dist_config_dict, user_root=user_root, dry_run=dry_run)
Expand Down Expand Up @@ -125,8 +133,6 @@ def config_config(config_path, config_dict,
config_units(config_dict, unit_system=unit_system, no_prompt=no_prompt)
config_driver(config_dict, driver=driver, no_prompt=no_prompt)
config_roots(config_dict, weewx_root, skin_root, html_root, sqlite_root, user_root)
copy_skins(config_dict, dry_run=dry_run)
copy_util(config_path, config_dict, dry_run=dry_run)


def config_location(config_dict, location=None, no_prompt=False):
Expand Down Expand Up @@ -665,7 +671,7 @@ def _patch_file(srcpath, dstpath, re_list):
wd.write(line)


def station_upgrade(config_path, docs_root=None, examples_root=None,
def station_upgrade(config_path, dist_config_path=None, docs_root=None, examples_root=None,
no_prompt=False, no_backup=False, dry_run=False):
"""Upgrade the user data for the configuration file found at config_path"""

Expand All @@ -682,9 +688,14 @@ def station_upgrade(config_path, docs_root=None, examples_root=None,
print("Nothing done.")
return

# Retrieve the new configuration file as a ConfigObj:
with importlib.resources.open_text('wee_resources', 'weewx.conf', encoding='utf-8') as fd:
dist_config_dict = configobj.ConfigObj(fd, encoding='utf-8', file_error=True)
# Unless we've been given a path to the new configuration file, retrieve it from
# package resources.
if dist_config_path:
dist_config_dict = configobj.ConfigObj(dist_config_path, encoding='utf-8', file_error=True)
else:
# Retrieve the new configuration file from package resources:
with importlib.resources.open_text('wee_resources', 'weewx.conf', encoding='utf-8') as fd:
dist_config_dict = configobj.ConfigObj(fd, encoding='utf-8', file_error=True)

weecfg.update_config.update_and_merge(config_dict, dist_config_dict)
print(f"Finished upgrading the configuration file found at {config_path}.")
Expand Down
16 changes: 16 additions & 0 deletions bin/weectllib/parse_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from weeutil.weeutil import bcolors

station_create_usage = f"""{bcolors.BOLD}weectl station create [--config=CONFIG-PATH] \\
[--dist-config=DIST-CONFIG-PATH]] \\
[--driver=DRIVER] \\
[--location=LOCATION] \\
[--altitude=ALTITUDE,{{foot|meter}}] \\
Expand Down Expand Up @@ -41,6 +42,7 @@
[--dry-run]{bcolors.ENDC}
"""
station_upgrade_usage = f"""{bcolors.BOLD}weectl station upgrade [--config=CONFIG-PATH] \\
[--dist-config=DIST-CONFIG-PATH]] \\
[--docs-root=DOCS_ROOT] \\
[--examples-root=EXAMPLES_ROOT] \\
[--no-prompt] \\
Expand Down Expand Up @@ -94,6 +96,12 @@ def add_subparser(subparsers):
metavar='CONFIG-PATH',
help=f'Path to configuration file. It must not already '
f'exist. Default is "{weecfg.default_config_path}".')
station_create_parser.add_argument('--dist-config',
metavar='DIST-CONFIG-PATH',
help='Use configuration file DIST-CONFIG-PATH as the '
'new configuration file. Default is to retrieve it '
'from package resources. The average user is '
'unlikely to need this option.')
_add_common_args(station_create_parser)
station_create_parser.add_argument('--user-root',
help='Where to put the "user" directory, relative to '
Expand Down Expand Up @@ -146,6 +154,12 @@ def add_subparser(subparsers):
metavar='CONFIG-PATH',
help=f'Path to configuration file. '
f'Default is "{weecfg.default_config_path}"')
station_upgrade_parser.add_argument('--dist-config',
metavar='DIST-CONFIG-PATH',
help='Use configuration file DIST-CONFIG-PATH as the '
'new configuration file. Default is to retrieve it '
'from package resources. The average user is '
'unlikely to need this option.')
station_upgrade_parser.add_argument('--docs-root',
help='Where to put the new documentation, relative to '
'WEEWX_ROOT. Default is "docs".')
Expand Down Expand Up @@ -193,6 +207,7 @@ def create_station(namespace):
"""Map 'namespace' to a call to station_create()"""
try:
weecfg.station_config.station_create(config_path=namespace.config,
dist_config_path=namespace.dist_config,
driver=namespace.driver,
location=namespace.location,
altitude=namespace.altitude,
Expand Down Expand Up @@ -236,6 +251,7 @@ def reconfigure_station(namespace):

def upgrade_station(namespace):
weecfg.station_config.station_upgrade(config_path=namespace.config,
dist_config_path=namespace.dist_config,
docs_root=namespace.docs_root,
examples_root=namespace.examples_root,
no_prompt=namespace.no_prompt,
Expand Down
10 changes: 5 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ src-tarball: $(DSTDIR)/$(SRCPKG)

$(DSTDIR)/$(SRCPKG):
mkdir -p $(BLDDIR)/weewx-$(VERSION)
rsync -ar ./ $(BLDDIR)/weewx-$(VERSION) --exclude __pycache__ --exclude .gitignore \
--exclude .git --exclude tests --exclude dist --exclude build --exclude .editorconfig \
--exclude poetry.lock --exclude pyproject.toml --exclude mkdocs.yml --exclude .idea \
--exclude .github
rsync -ar ./ $(BLDDIR)/weewx-$(VERSION) --exclude wee_resources --exclude __pycache__ \
--exclude .gitignore --exclude .git --exclude tests --exclude dist --exclude build \
--exclude .editorconfig --exclude poetry.lock --exclude pyproject.toml \
--exclude mkdocs.yml --exclude .idea --exclude .github
mkdir -p $(DSTDIR)
tar cfz $(DSTDIR)/$(SRCPKG) -C $(BLDDIR) weewx-$(VERSION)

Expand Down Expand Up @@ -258,7 +258,7 @@ DEBPKG=python3-weewx_$(DEBVER)_$(DEBARCH).deb
ifneq ("$(SIGN)","1")
DPKG_OPT=-us -uc
endif
debian-package: bin/wee_resources/ deb-package-prep
debian-package: deb-package-prep
cp pkg/debian/control $(DEBBLDDIR)/debian/control
rm -f $(DEBBLDDIR)/debian/files
rm -rf $(DEBBLDDIR)/debian/weewx*
Expand Down
6 changes: 3 additions & 3 deletions pkg/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ merge_weewxconf() {
return
fi

NEWVER=`$cfgapp --version`
NEWVER=$(cfgapp --version | awk '{print $2}')
OLDVER=$(get_conf_version $cfgfile)
if dpkg --compare-versions $OLDVER lt $NEWVER; then
# this is an old config, so merge it into a new config
if [ -f $cfgfile.dist ]; then
DSTVER=$(get_conf_version $cfgfile.dist)
if dpkg --compare-versions $DSTVER eq $NEWVER; then
echo saving previous config file as $cfgfile-$OLDVER
mv $cfgfile $cfgfile-$OLDVER
cp -p $cfgfile $cfgfile-$OLDVER
echo saving distribution config file as $cfgfile-$NEWVER
cp -p $cfgfile.dist $cfgfile-$NEWVER
echo merging previous and distribution into $cfgfile
$cfgapp --upgrade --config=$cfgfile-$OLDVER --dist-config=$cfgfile-$NEWVER --output=$cfgfile --no-prompt --no-backup
$cfgapp station upgrade --config=$cfgfile --dist-config=$cfgfile-$NEWVER --no-prompt --no-backup
else
echo distribution config file is wrong version for merging
fi
Expand Down

0 comments on commit f52cf24

Please sign in to comment.