Example #1
0
 def GET(self):
     try:
         with open('./data/proto.json', 'r') as f:  # Read settings from json file if it exists
             settings = json.load(f)
     except IOError:  # If file does not exist return empty value
         settings = {}  # Default settings. can be list, dictionary, etc.
     return template_render.proto(settings)  # open settings page
Example #2
0
 def GET(self):
     previous = _settings.copy()
     qdict = (
         web.input()
     )  # Dictionary of values returned as query string from settings page.
     with open(DATA_FILE, u"w") as f:
         try:
             port = int(qdict[u"broker_port"])
             assert port > 80 and port < 65535
             _settings[u"broker_port"] = port
             _settings[u"broker_username"] = qdict[u"broker_username"]
             _settings[u"broker_password"] = qdict[u"broker_password"]
             _settings[u"broker_host"] = qdict[u"broker_host"]
             _settings[u"publish_up_down"] = qdict[u"publish_up_down"]
         except:
             return template_render.proto(
                 qdict,
                 gv.sd[u"name"],
                 u"Broker port must be a valid integer port number",
             )
         else:
             json.dump(_settings, f, indent=4,
                       sort_keys=True)  # save to file
             apply_new_mqtt_settings(previous)
     raise web.seeother(u"/")  # Return user to home page.
Example #3
0
 def GET(self):
     try:
         with open(u"./data/proto.json",
                   u"r") as f:  # Read settings from json file if it exists
             settings = json.load(f)
     except IOError:  # If file does not exist return empty value
         settings = {}  # Default settings. can be list, dictionary, etc.
     return template_render.proto(settings)  # open settings page
Example #4
0
 def GET(self):
     qdict = web.input()  # Dictionary of values returned as query string from settings page.
     with open(DATA_FILE, 'w') as f:
         try:
             port = int(qdict['broker_port'])
             assert port > 80 and port < 65535
             _settings['broker_port'] = port
             _settings['broker_username'] = qdict['broker_username']
             _settings['broker_password'] = qdict['broker_password']
             _settings['broker_host'] = qdict['broker_host']
             _settings['publish_up_down'] = qdict['publish_up_down']
         except:
             return template_render.proto(qdict, gv.sd[u'name'], "Broker port must be a valid integer port number")
         else:
             json.dump(_settings, f) # save to file
             publish_status()
     raise web.seeother('/')  # Return user to home page.
Example #5
0
 def GET(self):
     qdict = web.input(
     )  # Dictionary of values returned as query string from settings page.
     with open(DATA_FILE, 'w') as f:
         try:
             port = int(qdict['broker_port'])
             assert port > 80 and port < 65535
             _settings['broker_port'] = port
             _settings['broker_host'] = qdict['broker_host']
             _settings['publish_up_down'] = qdict['publish_up_down']
         except:
             return template_render.proto(
                 qdict, gv.sd[u'name'],
                 "Broker port must be a valid integer port number")
         else:
             json.dump(_settings, f)  # save to file
             publish_status()
     raise web.seeother('/')  # Return user to home page.