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

This commit is contained in:
Matthew Wall
2023-11-24 21:43:06 -05:00
6 changed files with 45 additions and 48 deletions

View File

@@ -538,19 +538,19 @@ def copy_docs(config_dict, docs_root=None, dry_run=False, force=False):
if os.path.isdir(docs_dir) and not force:
print(f"Directory {docs_dir} already exists.")
return None
with weeutil.weeutil.get_resource_path('weewx_data', 'docs') as docs_resources:
# Check whether new docs are actually available.
if os.path.isdir(docs_resources):
# They are available. Proceed.
# If the documentation has not been built, then a FileNotFoundError will be raised. Be
# prepared to catch it.
try:
with weeutil.weeutil.get_resource_path('weewx_data', 'docs') as docs_resources:
print(f"Removing {docs_dir}.")
if not dry_run:
shutil.rmtree(docs_dir, ignore_errors=True)
print(f"Copying new docs into {docs_dir}.")
if not dry_run:
shutil.copytree(docs_resources, docs_dir)
else:
print(f"{bcolors.WARNING}Documentation not available at {docs_resources}. "
f"Try building them using mkdocs.{bcolors.ENDC}", file=sys.stderr)
except FileNotFoundError:
print(f"{bcolors.WARNING}Documentation not available. "
f"Try building them using mkdocs.{bcolors.ENDC}", file=sys.stderr)
return docs_dir

View File

@@ -6,25 +6,10 @@
"""The 'weectllib' package."""
import datetime
import importlib
import weecfg
import weeutil.logger
import weewx
from weeutil.weeutil import to_int, bcolors
def initialize(config_dict):
# Set weewx.debug as necessary:
weewx.debug = to_int(config_dict.get('debug', 0))
# Customize the logging with user settings.
weeutil.logger.setup('weectl', config_dict)
# Add the 'user' package to PYTHONPATH
weewx.add_user_path(config_dict)
# Now we can import user.extensions
importlib.import_module('user.extensions')
from weeutil.weeutil import bcolors
def parse_dates(date=None, from_date=None, to_date=None, as_datetime=False):

View File

@@ -12,6 +12,7 @@ import time
import weecfg
import weectllib
import weedb
import weewx
import weewx.manager
from weeutil.weeutil import bcolors, y_or_n, timestamp_to_string
@@ -28,7 +29,7 @@ def create_database(config_path,
config_path, config_dict = weecfg.read_config(config_path)
print(f"The configuration file {bcolors.BOLD}{config_path}{bcolors.ENDC} will be used.")
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
# Try a simple open. If it succeeds, that means the database
# exists and is initialized. Otherwise, an exception will be raised.
@@ -50,7 +51,7 @@ def drop_daily(config_path,
"""Drop the daily summary from a WeeWX database."""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
print(f"Proceeding will delete all your daily summaries from database '{database_name}'")
ans = y_or_n("Are you sure you want to proceed (y/n)? ")
@@ -88,7 +89,7 @@ def rebuild_daily(config_path,
"""Rebuild the daily summaries."""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
# Get any dates the user might have specified.
from_d, to_d = weectllib.parse_dates(date, from_date, to_date)
@@ -159,7 +160,7 @@ def add_column(config_path,
column_type: The type ("REAL"|"INTEGER") of the new column.
"""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
column_type = column_type or 'REAL'
ans = y_or_n(
@@ -183,7 +184,7 @@ def rename_column(config_path,
db_binding='wx_binding',
dry_run=False):
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
ans = y_or_n(f"Rename column '{from_name}' to '{to_name}' "
f"in database {database_name}? (y/n) ")
@@ -205,7 +206,7 @@ def drop_columns(config_path,
dry_run=False):
"""Drop a set of columns from the database"""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
ans = y_or_n(f"Drop column(s) '{', '.join(column_names)}' from the database? (y/n) ")
if ans == 'y':
@@ -237,7 +238,7 @@ def reconfigure_database(config_path,
same name as the old, except with the suffix _new attached to the end."""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
manager_dict = weewx.manager.get_manager_dict_from_config(config_dict,
db_binding)
@@ -322,7 +323,7 @@ def transfer_database(config_path,
print("This is a dry run. Nothing will actually be done.")
config_path, config_dict = weecfg.read_config(config_path)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
print(f"The configuration file {bcolors.BOLD}{config_path}{bcolors.ENDC} will be used.")
@@ -439,7 +440,7 @@ def calc_missing(config_path,
import weecfg.database
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
log.info("Preparing to calculate missing derived observations...")
@@ -533,7 +534,7 @@ def check(config_path, db_binding='wx_binding'):
"""Check the database for any issues."""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run=False)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
print("Checking daily summary tables version...")
with weewx.manager.open_manager_with_config(config_dict, db_binding) as dbm:
@@ -565,7 +566,7 @@ def update_database(config_path,
"""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
ans = y_or_n("The update process does not affect archive data, "
"but does alter the database.\nContinue (y/n)? ")
@@ -655,7 +656,7 @@ def reweight_daily(config_path,
"""Recalculate the weighted sums in the daily summaries."""
config_path, config_dict, database_name = weectllib.prepare(config_path, db_binding, dry_run)
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
# Determine the period over which we are rebuilding from any command line date parameters
from_d, to_d = weectllib.parse_dates(date,

View File

@@ -72,7 +72,7 @@ def run_reports(config_path,
config_path, config_dict = weecfg.read_config(config_path)
print(f"The configuration file {bcolors.BOLD}{config_path}{bcolors.ENDC} will be used.")
weectllib.initialize(config_dict)
weewx.initialize(config_dict, 'weectl')
# We want to generate all reports irrespective of any report_timing settings that may exist.
# The easiest way to do this is walk the config dict, resetting any report_timing settings

View File

@@ -4,10 +4,14 @@
# See the file LICENSE.txt for your full rights.
#
"""Package weewx, containing modules specific to the weewx runtime engine."""
import importlib
import os.path
import sys
import time
import weeutil.logger
from weeutil.weeutil import to_int
__version__ = "5.0.0b15"
# Holds the program launch time in unix epoch seconds:
@@ -219,3 +223,19 @@ def extract_roots(config_dict):
pass
return root_dict
def initialize(config_dict, log_label):
"""Set debug, set up the logger, and add the user path"""
global debug
# Set weewx.debug as necessary:
debug = to_int(config_dict.get('debug', 0))
# Customize the logging with user settings.
weeutil.logger.setup(log_label, config_dict)
# Add the 'user' package to PYTHONPATH
add_user_path(config_dict)
# Now we can import user.extensions
importlib.import_module('user.extensions')

View File

@@ -87,18 +87,9 @@ def main():
weeutil.logger.log_traceback(log.critical, " **** ")
sys.exit(weewx.CMD_ERROR)
# Now that we have the configuration dictionary, we can add the path to the user
# directory to PYTHONPATH.
weewx.add_user_path(config_dict)
# Now we can import user extensions
importlib.import_module('user.extensions')
# Look for the debug flag. If set, ask for extra logging
weewx.debug = int(config_dict.get('debug', 0))
# Now that we have the config_dict and debug setting, we can customize the
# logging with user additions
weeutil.logger.setup(namespace.log_label, config_dict)
# Now that we have the configuration dictionary, we can set up logging, debug, and
# other housekeeping chores:
weewx.initialize(config_dict, namespace.log_label)
# Log key bits of information.
log.info("Initializing weewx version %s", weewx.__version__)