Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enable/disable programs via a plugin
#1
Dan,

    Still hacking away on my weewx weather station plug in prototype.
    I've been scanning the code to understand how the enable/disable program works. The HTTP method is useful and SF for my shell script implementation. However, as I'm implementing the plugin I can't see a variable or list that handles program enables. I see that urls.py and webpages.py is the way the the HTTP method accesses the programData.json file to handle enable/disable.
    Also I see that gv.pd is the load of program data into sip.py for use executing programs.
    Here is my higher level reasoning, I have programs setup to handle my lawn sections, and programs for my veggy garden drip and another program for shrub drips. I use a monthly data json file to enable watering for the three program types. I use lawn as the system enable/disable and programs are always enabled since lawn has the largest window in months (system off in the cold/rainy months). Once system enabled for lawn, I  want to enable/disable veggy garden and shrubs programs based on the growing/hot dry months of the year (May,Jun,July,Aug...)

Any thoughts on the best way for a plugin to modify the programData.json?
   Should I use:  u"/ep" variable to "fake" a GET request via the plugin?
   or
   just use:
        gv.pd[pid]["enabled"] = int(["1/0"])
        jsave(gv.pd, "programData")
   in the plugin?

I have messed around a bit and programData seems to be a dict, which I have not handled yet in python. Seems that a for loop can find the index of an item in the dict and then I can change then enabled entry in that item.

Thanks,
Bryan
Reply
#2
You are on the right track.

The program data in Python is a dict.
Once you have the index of the program that you want to disable/enable you just need to set the "enabled" item to 0 for disabled or 1 for enabled.

The index of a program in the dict is the program number -1.

For example to disable program 2 you would use something like:
Code:
gv.pd[1]["enabled"] = 0
<p><br></p>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)