From b8a0cefde315f73f28e88ac9dbf51cc2ac8a0c13 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Wed, 20 May 2015 14:38:04 -0700 Subject: [PATCH] Included function to generate the section canonical ordering from a config file. --- bin/weecfg/__init__.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/weecfg/__init__.py b/bin/weecfg/__init__.py index a48305c9..0b9ba85c 100644 --- a/bin/weecfg/__init__.py +++ b/bin/weecfg/__init__.py @@ -22,12 +22,15 @@ from weewx.engine import all_service_groups minor_comment_block = [""] major_comment_block = ["", "##############################################################################", ""] +#============================================================================== +# Section tuples # Each ConfigObj section is recursively described by a "section tuple." This is # a 3-way tuple with elements: # -# 0: The name of the section -# 1: A list of any subsection tuples -# 2: A list of any scalar names. +# 0: The name of the section; +# 1: A list of any subsection tuples; +# 2: A list of any scalar names. + canonical_order = ('', [('Station', [], ['location', 'latitude', 'longitude', 'altitude', 'station_type', 'rain_year_start', 'week_start']), ('AcuRite', [], []), ('CC3000', [], []), @@ -59,6 +62,17 @@ canonical_order = ('', [('Station', [], ['location', 'latitude', 'longitude', 'a ('Engine', [('Services', [], ['prep_services', 'data_services', 'process_services', 'archive_services', 'restful_services', 'report_services'])], [])], ['debug', 'WEEWX_ROOT', 'socket_timeout', 'version']) +def get_section_tuple(c_dict, section_name=''): + """ The above "canonical" ordering can be generated from a config file + by using this function: + c = configobj.ConfigObj('weewx.conf') + print get_section_tuple(c)""" + + subsections = [get_section_tuple(c_dict[ss], ss) for ss in c_dict.sections] + section_tuple = (section_name, subsections, c_dict.scalars) + return section_tuple +#============================================================================== + us_group = {'group_altitude': 'foot', 'group_degree_day': 'degree_F_day', 'group_pressure': 'inHg',