From 813bec2bab0c3a569a92cebb58df7cb320a90c15 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Fri, 21 Oct 2022 16:47:25 -0700 Subject: [PATCH] Post the top-level entry point to the station registry Relates to PR #705. Posts the location of the top-level module to the station registry, as well as the location of the configuration file. --- bin/weecfg/__init__.py | 2 ++ bin/weewx/restx.py | 10 +++++++++- docs/changes.txt | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/weecfg/__init__.py b/bin/weecfg/__init__.py index 7510b36f..9d451ba5 100644 --- a/bin/weecfg/__init__.py +++ b/bin/weecfg/__init__.py @@ -159,6 +159,8 @@ def read_config(config_path, args=None, locations=DEFAULT_LOCATIONS, # Remember where we found the config file config_dict['config_path'] = os.path.realpath(config_path) + # Find the top-level module. This is where the entry point will be. + config_dict['entry_path'] = getattr(sys.modules['__main__'], '__file__', 'Unknown') return config_path, config_dict diff --git a/bin/weewx/restx.py b/bin/weewx/restx.py index 49013205..3743cc11 100644 --- a/bin/weewx/restx.py +++ b/bin/weewx/restx.py @@ -1398,7 +1398,8 @@ class StdStationRegistry(StdRESTful): weewx_info weewx version python_info platform_info - config_path + config_path Where the configuration file is located. + entry_path The path to the top-level module (usually where weewxd is located) The station_url is the unique key by which a station is identified. """ @@ -1432,6 +1433,7 @@ class StdStationRegistry(StdRESTful): _registry_dict.setdefault('longitude', self.engine.stn_info.longitude_f) _registry_dict.setdefault('station_model', self.engine.stn_info.hardware) _registry_dict.setdefault('config_path', config_dict.get('config_path', 'Unknown')) + _registry_dict.setdefault('entry_path', config_dict.get('entry_path', 'Unknown')) self.archive_queue = queue.Queue() self.archive_thread = StationRegistryThread(self.archive_queue, @@ -1457,6 +1459,7 @@ class StationRegistryThread(RESTThread): station_type="Unknown", station_model="Unknown", config_path="Unknown", + entry_path="Unknown", post_interval=86400, timeout=60, **kwargs): @@ -1478,6 +1481,8 @@ class StationRegistryThread(RESTThread): config_path (str): location of the configuration file, used in system registration to determine how weewx might have been installed. Default is 'Unknown'. + entry_path (str): location of the top-level module that was executed. Usually this is + where 'weewxd' is located. Default is "Unknown". station_model (str): The hardware model, typically the hardware_name property provided by the driver. Default is 'Unknown'. post_interval (int): How long to wait between posts. @@ -1500,6 +1505,7 @@ class StationRegistryThread(RESTThread): self.station_type = station_type self.station_model = station_model self.config_path = config_path + self.entry_path = entry_path def get_record(self, dummy_record, dummy_archive): _record = { @@ -1513,6 +1519,7 @@ class StationRegistryThread(RESTThread): 'platform_info': platform.platform(), 'weewx_info': weewx.__version__, 'config_path': self.config_path, + 'entry_path' : self.entry_path, 'usUnits': weewx.US, } return _record @@ -1526,6 +1533,7 @@ class StationRegistryThread(RESTThread): 'python_info': 'python_info=%s', 'platform_info': 'platform_info=%s', 'config_path': 'config_path=%s', + 'entry_path': 'entry_path=%s', 'weewx_info': 'weewx_info=%s'} def format_url(self, record): diff --git a/docs/changes.txt b/docs/changes.txt index 4a954e61..4567a839 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -46,8 +46,8 @@ See the User's Guide. Resolves issue #730. Fix problem that prevented wee_reports from using a default location for weewx.conf. -Post location of configuration file to the station registry. Thanks to Vince! -PR #705. +Post location of the configuration file and the top-level module to the station +registry. Thanks to Vince! PR #705. Fix minor install warning under Python 3.10. Fixes issue #799.