Properly save and restore settings between sessions

This commit is contained in:
bjschuma 2010-01-04 17:26:05 -05:00
parent b8f213c747
commit 4cacc390c2
3 changed files with 66 additions and 1 deletions

View File

@ -37,8 +37,57 @@ def append(child,root=None):
root.appendChild(child)
def child(root=None):
if root==None:
global document
if document == None:
return
return document.firstChild
return root.firstChild
def children(root=None):
if root == None:
global document
if document == None:
return []
return document.childNodes
return root.childNodes
def write(path):
global document
out = fopen(path,'w')
out.write(document.toprettyxml(indent=" "))
out.close()
out.close()
def load(path):
global document
fin = fopen(path)
if fin == None:
return
document = xml.parse(fin)
def isElm(node):
return node.nodeType == 1
def isText(node):
return node.nodeType == 3
def name(node):
return node.nodeName
def value(node):
val = node.nodeValue.strip()
if val == "False":
return False
elif val == "True":
return True
elif val.isdigit() == True:
return int(val)
return val

View File

@ -118,6 +118,7 @@ class Manager:
def restoresession(self):
path = self.findsession()
settings.load(path)
path = join(path,"enabled")
file = fopen(path)
self.restored = []

View File

@ -127,6 +127,21 @@ def save(path):
xm.write(path)
def load(path):
global settings
path = join(path,"settings")
xm.load(path)
elm = xm.child()
if elm == None:
return
for node in xm.children(elm):
if xm.isElm(node) == False:
continue
key = xm.name(node)
val = xm.child(node)
set(key,xm.value(val))
# Set default values
# Set verbose first so we can use write()
set("VERBOSE", ('-v' in sys.argv) or ("--verbose" in sys.argv) )