Merge branch 'V5' of github.com:weewx/weewx into V5

This commit is contained in:
Matthew Wall
2023-12-03 09:41:30 -05:00
4 changed files with 29 additions and 24 deletions

View File

@@ -395,7 +395,7 @@ formula to calculate reception quality for wireless stations. Default is `1`.
#### timeout
How many seconds to wait for a response from the station before giving up.
Default is `5`.
Default is `4`.
#### wait_before_retry

View File

@@ -166,6 +166,8 @@ def read_config(config_path, args=None, locations=DEFAULT_LOCATIONS,
if 'WEEWX_ROOT' not in config_dict:
# If missing, set WEEWX_ROOT to the directory the config file is in
config_dict['WEEWX_ROOT'] = os.path.dirname(config_path)
elif config_dict['WEEWX_ROOT'] == '/':
config_dict['WEEWX_ROOT'] == '/etc/weewx'
# In case WEEWX_ROOT is a relative path, join it with the location of the config file, then
# convert it to an absolute path.
config_dict['WEEWX_ROOT'] = os.path.abspath(os.path.join(os.path.dirname(config_path),

View File

@@ -532,14 +532,16 @@ def copy_examples(config_dict, examples_root=None, dry_run=False, force=False):
# examples_root is relative to WEEWX_PATH. Join them to get the absolute path.
examples_dir = os.path.join(config_dict['WEEWX_ROOT'], examples_root)
if os.path.isdir(examples_dir) and not force:
print(f"Directory {examples_dir} already exists.")
return None
print(f"Removing directory {examples_dir}")
if not dry_run:
shutil.rmtree(examples_dir, ignore_errors=True)
if os.path.isdir(examples_dir):
if not force:
print(f"Directory {examples_dir} already exists.")
return None
else:
print(f"Removing example directory {examples_dir}")
if not dry_run:
shutil.rmtree(examples_dir, ignore_errors=True)
with weeutil.weeutil.get_resource_path('weewx_data', 'examples') as examples_resources:
print(f"Copying new examples into {examples_dir}")
print(f"Copying examples into {examples_dir}")
if not dry_run:
shutil.copytree(examples_resources, examples_dir)
return examples_dir
@@ -565,7 +567,7 @@ def copy_user(config_dict, user_root=None, dry_run=False):
ignore=shutil.ignore_patterns('*.pyc', '__pycache__', ))
def copy_util(config_path, config_dict, dry_run=False):
def copy_util(config_path, config_dict, dry_run=False, force=False):
import weewxd
weewxd_path = weewxd.__file__
username = getpass.getuser()
@@ -621,18 +623,26 @@ def copy_util(config_path, config_dict, dry_run=False):
'rsyslog.d', 'scripts', 'solaris',
'tmpfiles.d')
util_dir = os.path.join(weewx_root, 'util')
if os.path.isdir(util_dir):
if not force:
print(f"Utility directory {util_dir} already exists. Nothing done.")
return None
else:
print(f"Removing utility directory {util_dir}")
if not dry_run:
shutil.rmtree(util_dir, ignore_errors=True)
with weeutil.weeutil.get_resource_path('weewx_data', 'util') as util_resources:
dstdir = os.path.join(weewx_root, 'util')
print(f"Creating utility files in {dstdir}")
print(f"Copying utility files into {util_dir}")
if not dry_run:
# Copy the tree rooted in 'util_resources' to 'dstdir', while ignoring files given
# by _ignore_function. While copying, use the function _patch_file() to massage
# the files.
shutil.copytree(util_resources, dstdir,
shutil.copytree(util_resources, util_dir,
ignore=_ignore_function,
copy_function=_patch_file)
return dstdir
return util_dir
def station_upgrade(config_path, dist_config_path=None, examples_root=None,
@@ -683,7 +693,7 @@ def station_upgrade(config_path, dist_config_path=None, examples_root=None,
print(f"Finished upgrading examples at {examples_dir}")
if 'util' in what:
util_dir = copy_util(config_path, config_dict, dry_run=dry_run)
util_dir = copy_util(config_path, config_dict, dry_run=dry_run, force=True)
if util_dir:
print(f"Finished upgrading utilities directory at {util_dir}")
else:

View File

@@ -1678,7 +1678,6 @@ def max_with_none(x_seq):
def move_with_timestamp(path):
"""Save a file or directory to a path with a timestamp."""
import shutil
# Sometimes the target has a trailing '/'. This will take care of it:
path = os.path.normpath(path)
newpath = path + time.strftime(".%Y%m%d%H%M%S")
@@ -1798,12 +1797,8 @@ def deep_copy_path(path, dest_dir):
else:
# path is a file. Get the directory it's in.
d = os.path.dirname(os.path.join(dest_dir, path))
# Make the destination directory, wrapping it in a try block in
# case it already exists:
try:
os.makedirs(d)
except OSError:
pass
# Make the destination directory:
os.makedirs(d, exist_ok=True)
# This version of copy does not copy over modification time,
# so it will look like a new file, causing it to be (for
# example) ftp'd to the server:
@@ -1856,7 +1851,6 @@ def version_compare(v1, v2):
def get_resource_path(package, resource):
"""Return a path to a resource within a package. The resource can be a directory or a file."""
import sys
import importlib.resources
if sys.version_info.major == 3 and sys.version_info.minor < 9:
# For earlier Python versions, use the deprecated function path()
@@ -1869,7 +1863,6 @@ def get_resource_path(package, resource):
def get_resource_fd(package, resource):
"""Return a file descriptor to a resource within a package."""
import sys
import importlib.resources
if sys.version_info.major == 3 and sys.version_info.minor < 9:
# For earlier Python versions, use the deprecated function open_text