First pass at a V2.X to V3.x update strategy for weewx.conf

This commit is contained in:
Tom Keffer
2014-11-14 01:14:25 +00:00
parent 650ed394f9
commit 2ee39d0d86
3 changed files with 223 additions and 31 deletions

View File

@@ -757,7 +757,7 @@ class Restart(Exception):
"""Exception thrown when restarting the engine is desired."""
def sigHUPhandler(dummy_signum, dummy_frame):
syslog.syslog(syslog.LOG_DEBUG, "engine: Received signal HUP. Throwing Restart exception.")
syslog.syslog(syslog.LOG_DEBUG, "engine: Received signal HUP. Initiating restart.")
raise Restart
class Terminate(Exception):

249
setup.py
View File

@@ -375,7 +375,6 @@ def merge_config_files(new_config_path, old_config_path, weewx_root,
# Create a ConfigObj using the new contents:
new_config = configobj.ConfigObj(new_config_path)
new_config.indent_type = ' '
# FIXME: new_version_number is not used
new_version_number = version_number.split('.')
if len(new_version_number[1]) < 2:
new_version_number[1] = '0'+new_version_number[1]
@@ -404,18 +403,24 @@ def merge_config_files(new_config_path, old_config_path, weewx_root,
if len(old_version_number[1]) < 2:
old_version_number[1] = '0'+old_version_number[1]
if old_version_number[0] == '2':
print >>sys.stderr, "Old configuration file. You will have to do a manual merge."
# I don't know how to merge older, V2.X configuration files, only
# newer V3.X ones.
elif old_version_number[0:2] >= ['3','00']:
# Update the old version to reflect any changes made since it
# was created:
update_config_file(old_config)
# Now merge the old configuration file into the new file, thus
# I don't know how to merge older, V1.X configuration files, only
# newer V2.X ones.
if old_version_number[0] == '1':
print >>sys.stderr, "Don't know how to merge old Version %s weewx.conf" % old_version
print >>sys.stderr, "You will have to do it manually."
else:
# First update to V2.X
if old_version_number[0:2] >= ['2','00']:
update_to_v2_X(old_config)
# Now update to V3.X
update_to_v3_X(old_config)
# Now merge the updated old configuration file into the new file, thus
# saving any user modifications. First, turn interpolation off:
old_config.interpolation = False
# Now merge the old version into the new:
# Then do the merge
new_config.merge(old_config)
# Make sure WEEWX_ROOT reflects the choice made in setup.cfg:
@@ -425,11 +430,191 @@ def merge_config_files(new_config_path, old_config_path, weewx_root,
return new_config
def update_config_file(config_dict):
"""Updates a configuration file to reflect any recent changes."""
def update_to_v2_X(config_dict):
"""Updates a configuration file to the latest V2.X version.
Since V2.7 was the last 2.X version, that's our target"""
# No V3.X updates. Yet.
# webpath is now station_url
webpath = config_dict['Station'].get('webpath', None)
station_url = config_dict['Station'].get('station_url', None)
if webpath is not None and station_url is None:
config_dict['Station']['station_url'] = webpath
config_dict['Station'].pop('webpath', None)
if config_dict.has_key('StdArchive'):
# Option stats_types is no longer used. Get rid of it.
config_dict['StdArchive'].pop('stats_types', None)
# --- Davis Vantage series ---
if config_dict.has_key('Vantage'):
try:
if config_dict['Vantage']['driver'].strip() == 'weewx.VantagePro':
config_dict['Vantage']['driver'] = 'weewx.drivers.vantage'
except KeyError:
pass
# --- Oregon Scientific WMR100 ---
# The section name has changed from WMR-USB to WMR100
if config_dict.has_key('WMR-USB'):
if config_dict.has_key('WMR100'):
sys.stderr.write("\n*** Configuration file has both a 'WMR-USB' section and a 'WMR100' section. Aborting ***\n\n")
exit()
config_dict.rename('WMR-USB', 'WMR100')
# If necessary, reflect the section name in the station type:
try:
if config_dict['Station']['station_type'].strip() == 'WMR-USB':
config_dict['Station']['station_type'] = 'WMR100'
except KeyError:
pass
# Finally, the name of the driver has been changed
try:
if config_dict['WMR100']['driver'].strip() == 'weewx.wmrx':
config_dict['WMR100']['driver'] = 'weewx.drivers.wmr100'
except KeyError:
pass
# --- Oregon Scientific WMR9x8 series ---
# The section name has changed from WMR-918 to WMR9x8
if config_dict.has_key('WMR-918'):
if config_dict.has_key('WMR9x8'):
sys.stderr.write("\n*** Configuration file has both a 'WMR-918' section and a 'WMR9x8' section. Aborting ***\n\n")
exit()
config_dict.rename('WMR-918', 'WMR9x8')
# If necessary, reflect the section name in the station type:
try:
if config_dict['Station']['station_type'].strip() == 'WMR-918':
config_dict['Station']['station_type'] = 'WMR9x8'
except KeyError:
pass
# Finally, the name of the driver has been changed
try:
if config_dict['WMR9x8']['driver'].strip() == 'weewx.WMR918':
config_dict['WMR9x8']['driver'] = 'weewx.drivers.wmr9x8'
except KeyError:
pass
# --- Fine Offset instruments ---
try:
if config_dict['FineOffsetUSB']['driver'].strip() == 'weewx.fousb':
config_dict['FineOffsetUSB']['driver'] = 'weewx.drivers.fousb'
except KeyError:
pass
#--- The weewx Simulator ---
try:
if config_dict['Simulator']['driver'].strip() == 'weewx.simulator':
config_dict['Simulator']['driver'] = 'weewx.drivers.simulator'
except KeyError:
pass
# 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
# do not know what it is, then stick it in the last group we
# have 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']:
svc_name = _svc_name.strip()
# Skip the no longer needed StdRESTful service:
if svc_name == 'weewx.engine.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, using the old driver name to help us
for section in config_dict['StdRESTful'].sections:
svc = config_dict['StdRESTful'][section]['driver']
# weewx.restful has changed to weewx.restx
if svc.startswith('weewx.restful'):
svc = 'weewx.restx.Std' + section
# awekas is in weewx.restx since 2.6
if svc.endswith('AWEKAS'):
svc = 'weewx.restx.AWEKAS'
config_dict['Engines']['WxEngine']['restful_services'].append(svc)
# 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')
# Clean up the CWOP configuration
if config_dict.has_key('StdRESTful') and config_dict['StdRESTful'].has_key('CWOP'):
# Option "interval" has changed to "post_interval"
if config_dict['StdRESTful']['CWOP'].has_key('interval'):
config_dict['StdRESTful']['CWOP']['post_interval'] = config_dict['StdRESTful']['CWOP']['interval']
config_dict['StdRESTful']['CWOP'].pop('interval')
# Option "server" has become "server_list". It is also no longer
# included in the default weewx.conf, so just pop it.
if config_dict['StdRESTful']['CWOP'].has_key('server'):
config_dict['StdRESTful']['CWOP'].pop('server')
# Remove the no longer needed "driver" from all the RESTful services:
if config_dict.has_key('StdRESTful'):
for section in config_dict['StdRESTful'].sections:
config_dict['StdRESTful'][section].pop('driver', None)
def update_to_v3_X(config_dict):
"""Update a configuration file to V3.X"""
if 'Databases' in config_dict:
# The stats database no longer exists. Remove it from the [Databases] section:
config_dict['Databases'].pop('stats_sqlite', None)
config_dict['Databases'].pop('stats_mysql', None)
# The key "database" changed to "database_name"
for stanza in config_dict['Databases']:
if 'database' in config_dict['Databases'][stanza]:
config_dict['Databases'][stanza].rename('database', 'database_name')
if 'StdReport' in config_dict:
# The key "data_binding" is now used instead of these:
config_dict['StdReport'].pop('archive_database', None)
config_dict['StdReport'].pop('stats_database', None)
if 'StdArchive' in config_dict:
config_dict['StdArchive'].pop('archive_database', None)
config_dict['StdArchive'].pop('stats_database', None)
config_dict['StdArchive'].pop('archive_schema', None)
config_dict['StdArchive'].pop('stats_schema', None)
# Section ['Engines'] got renamed to ['Engine']
if 'Engine' not in config_dict and 'Engines' in config_dict:
config_dict.rename('Engines', 'Engine')
# Subsection [['WxEngine']] got renamed to [['Services']]
if 'WxEngine' in config_dict['Engine']:
config_dict['Engine'].rename('WxEngine', 'Services')
# Finally, module "wxengine" got renamed to "engine". Go through
# each of the service lists, making the change
for list_name in config_dict['Engine']['Services']:
service_list = config_dict['Engine']['Services'][list_name]
# If service_list is not already a list (it could be just a single name),
# then make it a list:
if not hasattr(service_list, '__iter__'):
service_list = [service_list]
config_dict['Engine']['Services'][list_name] = [this_item.replace('wxengine', 'engine') for this_item in service_list]
if list_name == 'process_services' and 'weewx.wxservices.StdWXCalculate' not in config_dict['Engine']['Services'][list_name]:
config_dict['Engine']['Services'][list_name].append('weewx.wxservices.StdWXCalculate')
def save_path(filepath):
# Sometimes the target has a trailing '/'. This will take care of it:
@@ -1159,29 +1344,35 @@ if __name__ == "__main__":
['docs/changes.txt',
'docs/copyright.htm',
'docs/customizing.htm',
'docs/images/day-gap-not-shown.png',
'docs/images/day-gap-showing.png',
'docs/images/daytemp_with_avg.png',
'docs/debian.htm',
'docs/images/ferrites.jpg',
'docs/images/funky_degree.png',
'docs/images/logo-apple.png',
'docs/images/logo-centos.png',
'docs/images/logo-debian.png',
'docs/images/logo-fedora.png',
'docs/images/logo-linux.png',
'docs/images/logo-mint.png',
'docs/images/logo-redhat.png',
'docs/images/logo-suse.png',
'docs/images/logo-ubuntu.png',
'docs/images/logo-weewx.png',
'docs/readme.htm',
'docs/redhat.htm',
'docs/setup.htm',
'docs/suse.htm',
'docs/upgrading.htm',
'docs/usersguide.htm',
'docs/images/daycompare.png',
'docs/images/day-gap-not-shown.png',
'docs/images/day-gap-showing.png',
'docs/images/daytemp_with_avg.png',
'docs/images/daywindvec.png',
'docs/images/ferrites.jpg',
'docs/images/funky_degree.png',
'docs/images/image_parts.png',
'docs/images/logo-apple.png',
'docs/images/logo-centos.png',
'docs/images/logo-debian.png',
'docs/images/logo-fedora.png',
'docs/images/logo-linux.png',
'docs/images/logo-mint.png',
'docs/images/logo-opensuse.png',
'docs/images/logo-redhat.png',
'docs/images/logo-suse.png',
'docs/images/logo-ubuntu.png',
'docs/images/logo-weewx.png',
'docs/images/sample_monthrain.png',
'docs/images/weekgustoverlay.png',
'docs/images/weektempdew.png',
'docs/images/yearhilow.png']),
('docs/css',
['docs/css/weewx_docs.css',

View File

@@ -564,7 +564,8 @@ version = 3.0.0a1
table_name = archive
# The class to manage the database
manager = weewx.wxmanager.WXDaySummaryManager
# The schema defines to structure of the database contents
# The schema defines the structure of the database.
# It is *only* used when the database is created.
schema = schemas.wview.schema