From e1c27b4881d2a4bb5fdcd99420e6fa5dc78eea69 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Mon, 11 Nov 2013 17:21:56 +0000 Subject: [PATCH] Broke up the giant service_list into five, smaller lists. Rewrote setup.py to backwards update old configuration file to use the smaller lists. --- TODO.txt | 9 +------ bin/weewx/restful.py | 6 ++++- bin/weewx/wxengine.py | 25 ++++++++++--------- docs/changes.txt | 4 ++++ setup.py | 56 +++++++++++++++++++++++++++++++++++++++++++ weewx.conf | 14 ++++------- 6 files changed, 83 insertions(+), 31 deletions(-) diff --git a/TODO.txt b/TODO.txt index 11c0fda2..4c038395 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,10 +1,3 @@ TODO before the next release: -Break up the now giant list service_list into 4 smaller sublists. - -Program setup.py to: - o Remove "driver = " for all subsections in [StdRESTful] - o Replace weewx.wxengine.StdRESTful with the individual protocols - o Refactor service_list into the smaller sublists. - - +Document the five service lists. diff --git a/bin/weewx/restful.py b/bin/weewx/restful.py index 9c3a29b0..7e4528f8 100644 --- a/bin/weewx/restful.py +++ b/bin/weewx/restful.py @@ -7,7 +7,11 @@ # $Author$ # $Date$ # -"""Publish weather data to RESTful sites such as the Weather Underground or PWSWeather.""" +"""Publish weather data to RESTful sites such as the Weather Underground or PWSWeather. + + THIS MODULE IS NOW OBSOLETE! YOU SHOULD USE MODULE weewx.restx INSTEAD! + +""" from __future__ import with_statement import syslog import datetime diff --git a/bin/weewx/wxengine.py b/bin/weewx/wxengine.py index 08014dc3..06c57cfb 100644 --- a/bin/weewx/wxengine.py +++ b/bin/weewx/wxengine.py @@ -106,24 +106,23 @@ class StdEngine(object): def loadServices(self, config_dict): """Set up the services to be run.""" - - # This will hold the list of services to be run: + + # This will hold the list of objects, after the services has been instantiated: self.service_obj = [] - # Get the names of the services to be run: - service_names = weeutil.weeutil.option_as_list(config_dict['Engines']['WxEngine'].get('service_list')) - # Wrap the instantiation of the services in a try block, so if an exception # occurs, any service that may have started can be shut down in an orderly way. try: - for svc in service_names: - # For each listed service in service_list, instantiates an - # instance of the class, passing self and the configuration - # dictionary as the arguments: - syslog.syslog(syslog.LOG_DEBUG, "wxengine: Loading service %s" % svc) - self.service_obj.append(weeutil.weeutil._get_object(svc)(self, config_dict)) - syslog.syslog(syslog.LOG_DEBUG, "wxengine: Finished loading service %s" % svc) - except: + for service_group in ['prep_services', 'process_services', 'archive_services', + 'restful_services', 'report_services']: + for svc in weeutil.weeutil.option_as_list(config_dict['Engines']['WxEngine'].get(service_group)): + # For each service, instantiates an instance of the class, + # passing self and the configuration dictionary as the + # arguments: + syslog.syslog(syslog.LOG_DEBUG, "wxengine: Loading service %s" % svc) + self.service_obj.append(weeutil.weeutil._get_object(svc)(self, config_dict)) + syslog.syslog(syslog.LOG_DEBUG, "wxengine: Finished loading service %s" % svc) + except Exception: # An exception occurred. Shut down any running services, then # reraise the exception. self.shutDown() diff --git a/docs/changes.txt b/docs/changes.txt index 8a89c960..d01ee930 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -7,6 +7,10 @@ Changed the RESTful architecture so RESTful services are now first-class weewx services. This should simplify the installation of 3rd party extensions that use these services. +Broke up service_list, the very long list of services to be run, into +five separate lists. This will allow services to be grouped together, +according to when they should be run. + Changed the default time and date labels to use locale dependent formatting. The defaults should now work in most locales, provided you set the environment variable LANG before running weewx. diff --git a/setup.py b/setup.py index 0f2abad5..29fd5c21 100755 --- a/setup.py +++ b/setup.py @@ -80,6 +80,17 @@ start_scripts = ['util/init.d/weewx.bsd', 'util/init.d/weewx.redhat', 'util/init.d/weewx.suse'] +service_map = {'weewx.wxengine.StdTimeSynch' : 'prep_services', + 'weewx.wxengine.StdConvert' : 'process_services', + 'weewx.wxengine.StdCalibrate' : 'process_services', + 'weewx.wxengine.StdQC' : 'process_services', + 'weewx.wxengine.StdArchive' : 'archive_services', + 'weewx.wxengine.StdPrint' : 'report_services', + 'weewx.wxengine.StdReport' : 'report_services'} + +all_service_groups = ['prep_services', 'process_services', 'archive_services', + 'restful_services', 'report_services'] + #============================================================================== # weewx_install_lib #============================================================================== @@ -415,6 +426,8 @@ def merge_config_files(new_config_path, old_config_path, weewx_root, def update_config_file(config_dict): """Updates a configuration file to reflect any recent changes.""" + + global service_map, all_service_groups, service_lists # webpath is now station_url webpath = config_dict['Station'].get('webpath', None) @@ -492,6 +505,49 @@ def update_config_file(config_dict): except KeyError: pass + # Remove the no longer needed "driver" option from all the RESTful + # services: + for section in config_dict['StdRESTful'].sections: + config_dict['StdRESTful'][section].pop('driver', None) + + # See if the engine configuration section has the old-style "service_list": + if config_dict['Engines']['WxEngine'].has_key('service_list'): + # It does. Break it up into five, smaller lists. If a service + # does not appear in the dictionary "service_map", meaning we don't + # know what it is, then stick it in the last group we've seen. This should + # get its position about right. + last_group = 'prep_services' + + # Set up a bunch of empty groups in the right order + for group in all_service_groups: + config_dict['Engines']['WxEngine'][group] = list() + + # Now map the old service names to the right group + for svc_name in config_dict['Engines']['WxEngine']['service_list']: + # Skip the no longer needed StdRESTful service: + if svc_name == 'weewx.wxengine.StdRESTful': + continue + # Do we know about this service? + if service_map.has_key(svc_name): + # Yes. Get which group it belongs to, and put it there + group = service_map[svc_name] + config_dict['Engines']['WxEngine'][group].append(svc_name) + last_group = group + else: + # No. Put it in the last group. + config_dict['Engines']['WxEngine'][last_group].append(svc_name) + + # Now add the restful services + for section in config_dict['StdRESTful'].sections: + config_dict['Engines']['WxEngine']['restful_services'].append('weewx.restx.Std' + section) + + # Depending on how old a version the user has, the station registry may have to be included: + if 'weewx.restx.StdStationRegistry' not in config_dict['Engines']['WxEngine']['restful_services']: + config_dict['Engines']['WxEngine']['restful_services'].append('weewx.restx.StdStationRegistry') + + # Get rid of the no longer needed service_list: + config_dict['Engines']['WxEngine'].pop('service_list') + def save_path(filepath): # Sometimes the target has a trailing '/'. This will take care of it: filepath = os.path.normpath(filepath) diff --git a/weewx.conf b/weewx.conf index bf87091f..b460e375 100644 --- a/weewx.conf +++ b/weewx.conf @@ -230,8 +230,6 @@ version = 2.6.0a2 #station = your Weather Underground station ID (eg, KORHOODR3) #password = your Weather Underground password - driver = weewx.restful.Ambient - [[PWSweather]] # This section is for configuring posts to PWSweather.com @@ -240,8 +238,6 @@ version = 2.6.0a2 #station = your PWSweather station ID (eg, KORHOODR3) #password = your PWSweather password - driver = weewx.restful.Ambient - [[CWOP]] # This section is for configuring posts to CWOP @@ -259,8 +255,6 @@ version = 2.6.0a2 # How often we should post in seconds. 0=with every archive record interval = 600 - driver = weewx.restful.CWOP - [[StationRegistry]] # Uncomment the following line to register this weather station. #register_this_station = True @@ -273,8 +267,6 @@ version = 2.6.0a2 # [Station] will be used. #description = The greatest station on earth - driver = weewx.restful.StationRegistry - ############################################################################## [StdReport] @@ -491,4 +483,8 @@ version = 2.6.0a2 [[WxEngine]] # The list of services the main weewx engine should run: - service_list = weewx.wxengine.StdTimeSynch, weewx.wxengine.StdConvert, weewx.wxengine.StdCalibrate, weewx.wxengine.StdQC, weewx.wxengine.StdArchive, weewx.wxengine.StdPrint, weewx.wxengine.StdRESTful, weewx.wxengine.StdReport + prep_services = weewx.wxengine.StdTimeSynch + process_services = weewx.wxengine.StdConvert, weewx.wxengine.StdCalibrate, weewx.wxengine.StdQC + archive_services = weewx.wxengine.StdArchive, + restful_services = weewx.restx.StdWunderground, weewx.restx.StdPWSweather, weewx.restx.StdCWOP, weewx.restx.StdStationRegistry + report_services = weewx.wxengine.StdPrint, weewx.wxengine.StdReport