extension installer sleight of hand question

102 views
Skip to first unread message

vince

unread,
Dec 23, 2020, 5:20:16 PM12/23/20
to weewx-user
One of the things that we see FAQs about for many extensions, in particular the combination of weewx-mqtt and Belchertown, is related to what to edit+add in weewx.conf to salt to taste, so to speak.

I was thinking it might be helpful to be able to insert relatively large commented-out blocks of config file into a section, to aid folks in knowing what to tweak to do frequently desired things, and to do this as part of an extension being installed.

For example, using the weewx-mqtt extension as an example...

By default it adds:
    [[MQTT]]
        server_url = INSERT_SERVER_URL_HERE

But to do MQTT for Belchertown realtime stats you need to (a) edit the server_url line and (b) add a few more lines so the result is:

    [[MQTT]]
        server_url = mqtt://192.168.1.123:1883
        topic = weather
        binding = archive, loop
        aggregation = aggregate
        log_success = false

Is it possible to easily extend install.py to insert a block of additional lines, commented out, into the right place(s) as part of installing the extension ?   I was thinking that some better enhanced 'uncomment this to do that' stuff for a lot of extensions might make it easier for folks to figure out.

I know it's easy to hack on the install.py to add 'uncommented' things.  I'm looking to have it also be able to insert comments into that area.  Even being able to read in an external file'o'comments might be good enough if that's possible as an alternative.

    [[MQTT]]
        server_url = mqtt://192.168.1.123:1883
        #--- uncomment the lines below if you use MQTT with Belchertown
        #--- and make sure your Belchertown skin references weather/loop 
        #--- as the MQTT topic
        #
        #  topic = weather
        # binding = archive, loop
        # aggregation = aggregate
        # log_success = false

Yes I know it's also possible to expect people to RTFM but sometimes TFM get a bit cryptic.   I was thinking some inline 'comment this out to do that' things would be helpful if the extension installer had a way to do that.

Ideas ?

Tom Keffer

unread,
Dec 23, 2020, 5:48:37 PM12/23/20
to weewx-user
I guess I'm not understanding this. If you create a config section for the installer, it will be faithfully reproduced as it gets injected into weewx.conf, including any comments. 

As an example, take a look at install.py for weewx-nmea-xdr.

Or, am I missing something?

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/e8243a7f-d32e-4555-93d7-37c58e72ce2dn%40googlegroups.com.

vince

unread,
Dec 23, 2020, 7:04:39 PM12/23/20
to weewx-user
On Wednesday, December 23, 2020 at 2:48:37 PM UTC-8 Tom Keffer wrote:
I guess I'm not understanding this. If you create a config section for the installer, it will be faithfully reproduced as it gets injected into weewx.conf, including any comments. 

As an example, take a look at install.py for weewx-nmea-xdr.


Perfect.
Exactly what I was hoping to do.

Neither Belchertown (here) nor weewx-mqtt (here) do it that way.
Your way is way slicker.
 
Or, am I missing something?


Not in the least.

Thanks a bunch !

Tom Keffer

unread,
Dec 23, 2020, 7:56:37 PM12/23/20
to weewx-user
Now that I look at the actual code, my approach doesn't always work!  It will not preserve comments at the root level. For example:

# This is a comment
[SectionA]
  # Comment on option1
  option1 = foo
  option2 = bar  # Inline comment about option2

The highlighted comment would not get preserved. The others would.

Fixed in commit 98eef9b


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

vince

unread,
Dec 24, 2020, 3:15:39 PM12/24/20
to weewx-user
Tom - can we get this into 4.3 please since that's imminent and this one affects only comments ?

vince

unread,
Jan 27, 2021, 4:43:58 PM1/27/21
to weewx-user
Tom - think I found a bug in 4.3.0 for this one - the extension installer gets confused if you flip-flop back and forth in a sub-element between comments and uncommented items in the install.py script. wee_extension seems to not put any comments that are in install.py 'below' the last uncommented item in the config_dict into the resulting weewx.conf file.

background -  I was working on some tweaks to Pat's install.py (my forked version is HERE) and found this one experimentally by installing/uninstalling my forked Belchertown.   The intent FWIW is to have a fully populated [[[Belchertown]]] stanza there with the zillion options present, just commented out as the default.

I found a solid workaround by putting an uncommented unused bogus var=value line on line 154, but I thought I'd mention it anyway as a nice-to-have.

To show the bug:
  • grab my forked skin, comment out line 154 (the workaround) so the config_dict Extras elements are all comments
  • install the skin.  All the comments in the [[[Belchertown]]] stanza make it into weewx ok
  • uninstall the skin to revert to clean weewx
  • uncomment line 90 in install.py and install the extension.   That will be the last line wee_extension puts into weewx.conf. Everything above that line makes it into weewx ok....but nothing 'after' that line will be in weewx (that's the bug)
  • uninstall the skin to revert to clean weewx

The pattern is that nothing under the 'last' uncommented item in the install.py config_dict makes it into the resulting weewx.conf file.  It doesn't matter which line has a uncommented key=value pair.   The rest of the lines 'below' the last uncommented ones get dropped by the extension installer

I think the commit you made to get to today's config is https://github.com/weewx/weewx/commit/47a55eede790b3da0025e71596d13cd39ebc7e03

Obviously an edge case.   If you want me to open a github issue for getting to it whenever, let me know...

Tom Keffer

unread,
Jan 27, 2021, 5:13:30 PM1/27/21
to weewx-user
It's not a bug, it's a limitation with ConfigObj.

In ConfigObj, all comments belong to the option or section below them. If you don't have anything below, there is no place for ConfigObj to put the comment and it is ignored.

Usually one can find creative ways around the problem. For example, this is the reason why [[Corrections]] has the entry "foo = foo + 0.2".

vince

unread,
Jan 27, 2021, 5:14:12 PM1/27/21
to weewx-user
Thanks for the clarification.  I think we can live with the workaround (which works fine).
Reply all
Reply to author
Forward
0 new messages