Negative temperature fixed
This commit is contained in:
@@ -11,5 +11,11 @@
|
||||
|
||||
"clock" : {
|
||||
"test":""
|
||||
},
|
||||
"dashboard" : {
|
||||
"test":""
|
||||
},
|
||||
"global" : {
|
||||
"shopping_list" : []
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,37 @@
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
import shutil
|
||||
|
||||
class Variables():
|
||||
""""""
|
||||
|
||||
def __init__(self, module_name, file_name="persistence/persistent_vars.json", init_name="persistence/persistent_init.json", ):
|
||||
self.path = file_name
|
||||
self.init_path = init_name
|
||||
self.last_action = ""
|
||||
|
||||
self.module = module_name
|
||||
|
||||
self.last_action = ""
|
||||
# last performed action, if only reads are made, then the underlying var has not been changed
|
||||
# and doesn't need to be read again
|
||||
self.savefile = {}
|
||||
|
||||
if not os.path.exists(self.path):
|
||||
shutil.copy(self.init_path, self.path)
|
||||
|
||||
|
||||
def global_action(self, action, name, value=""):
|
||||
old = self.module
|
||||
self.module = "global"
|
||||
action = getattr(self, action)
|
||||
if value != "":
|
||||
ret = action(name,value)
|
||||
else:
|
||||
ret = action(name)
|
||||
self.module = old
|
||||
return ret
|
||||
|
||||
def write(self, name, value):
|
||||
pre = self.read("")
|
||||
pre[self.module][name] = value
|
||||
@@ -28,23 +46,13 @@ class Variables():
|
||||
|
||||
def read(self, name):
|
||||
if self.last_action == "read":
|
||||
if name == "":
|
||||
return self.savefile
|
||||
else:
|
||||
return self.savefile[self.module][name]
|
||||
|
||||
try:
|
||||
if os.path.exists(self.path):
|
||||
file_path = self.path
|
||||
else:
|
||||
file_path = self.init_path
|
||||
file = open(file_path,"r")
|
||||
vars = self.savefile
|
||||
else:
|
||||
file = open(self.path,"r")
|
||||
vars = json.load(file)
|
||||
file.close()
|
||||
self.savefile = vars
|
||||
self.last_action = "read"
|
||||
except:
|
||||
return None
|
||||
|
||||
if name != "":
|
||||
vars = vars[self.module][name]
|
||||
@@ -53,9 +61,11 @@ class Variables():
|
||||
|
||||
def increment(self, name, inc=1):
|
||||
pre = self.read(name)
|
||||
plus1 = pre + inc
|
||||
self.write(name, plus1)
|
||||
|
||||
if pre:
|
||||
self.write(name, pre + inc)
|
||||
else:
|
||||
self.write(name, inc)
|
||||
|
||||
|
||||
def append_list(self, name, value):
|
||||
pre = self.read(name)
|
||||
|
Reference in New Issue
Block a user