Save settings to an xml document
This commit is contained in:
parent
490b297522
commit
b8f213c747
|
@ -1,4 +1,4 @@
|
||||||
# This is the base tools package
|
# This is the base tools package
|
||||||
# It contains various tools needed by the base layer of ocarina2
|
# It contains various tools needed by the base layer of ocarina2
|
||||||
|
|
||||||
__all__ = ["file", "proc", "message", "needle"]
|
__all__ = ["file", "proc", "message", "needle", "xm"]
|
|
@ -0,0 +1,44 @@
|
||||||
|
#! /usr/bin/python
|
||||||
|
|
||||||
|
# To change this template, choose Tools | Templates
|
||||||
|
# and open the template in the editor.
|
||||||
|
|
||||||
|
__author__="bjschuma"
|
||||||
|
__date__ ="$Jan 4, 2010 3:27:05 PM$"
|
||||||
|
|
||||||
|
|
||||||
|
import xml.dom.minidom as xml
|
||||||
|
from bt.file import *
|
||||||
|
|
||||||
|
global document
|
||||||
|
document = None
|
||||||
|
|
||||||
|
|
||||||
|
def new():
|
||||||
|
global document
|
||||||
|
document = xml.Document()
|
||||||
|
|
||||||
|
|
||||||
|
def element(name):
|
||||||
|
global document
|
||||||
|
return document.createElement(name)
|
||||||
|
|
||||||
|
|
||||||
|
def text(name):
|
||||||
|
global document
|
||||||
|
return document.createTextNode(name)
|
||||||
|
|
||||||
|
|
||||||
|
def append(child,root=None):
|
||||||
|
if root==None:
|
||||||
|
global document
|
||||||
|
document.appendChild(child)
|
||||||
|
return
|
||||||
|
root.appendChild(child)
|
||||||
|
|
||||||
|
|
||||||
|
def write(path):
|
||||||
|
global document
|
||||||
|
out = fopen(path,'w')
|
||||||
|
out.write(document.toprettyxml(indent=" "))
|
||||||
|
out.close()
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
from bt.message import *
|
from bt.message import *
|
||||||
from bt.file import *
|
from bt.file import *
|
||||||
import loader
|
import loader
|
||||||
|
import settings
|
||||||
|
|
||||||
class Manager:
|
class Manager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -86,6 +87,7 @@ class Manager:
|
||||||
keys = self.enabled.keys()
|
keys = self.enabled.keys()
|
||||||
for plugin in keys:
|
for plugin in keys:
|
||||||
self.disablePlugin(plugin)
|
self.disablePlugin(plugin)
|
||||||
|
settings.save(self.findsession())
|
||||||
|
|
||||||
|
|
||||||
def run(self,name,args=None):
|
def run(self,name,args=None):
|
||||||
|
@ -107,8 +109,7 @@ class Manager:
|
||||||
|
|
||||||
|
|
||||||
def savesession(self):
|
def savesession(self):
|
||||||
path = self.findsession()
|
path = join(self.findsession(),"enabled")
|
||||||
path = join(path,"enabled")
|
|
||||||
file = fopen(path,'w')
|
file = fopen(path,'w')
|
||||||
for key in self.enabled.keys():
|
for key in self.enabled.keys():
|
||||||
file.write(key+"\n")
|
file.write(key+"\n")
|
||||||
|
|
|
@ -8,7 +8,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
|
|
||||||
|
|
||||||
# Create a dictionary to hold the settings
|
# Create a dictionary to hold the settings
|
||||||
global settings
|
global settings
|
||||||
settings = dict()
|
settings = dict()
|
||||||
|
@ -26,12 +25,14 @@ def set(key,value):
|
||||||
from bt.message import write
|
from bt.message import write
|
||||||
from bt.message import error
|
from bt.message import error
|
||||||
from bt.file import fopen
|
from bt.file import fopen
|
||||||
|
from bt.file import join
|
||||||
|
from bt import xm
|
||||||
|
|
||||||
|
|
||||||
# Return true if settings contains key
|
# Return true if settings contains key
|
||||||
def has(key):
|
def has(key):
|
||||||
global settings
|
global settings
|
||||||
return (key in settings.keys())
|
return (key.upper() in settings.keys())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +99,34 @@ def parseInput():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def clean():
|
||||||
|
delete("user")
|
||||||
|
delete("arch")
|
||||||
|
delete("write")
|
||||||
|
delete("args")
|
||||||
|
delete("plugpath")
|
||||||
|
delete("verbose")
|
||||||
|
|
||||||
|
|
||||||
|
def save(path):
|
||||||
|
clean()
|
||||||
|
global settings
|
||||||
|
path = join(path,"settings")
|
||||||
|
xm.new()
|
||||||
|
elm = xm.element("settings")
|
||||||
|
xm.append(elm)
|
||||||
|
a = settings.keys()
|
||||||
|
for key in settings.keys():
|
||||||
|
value = get(key)
|
||||||
|
if value == None:
|
||||||
|
continue
|
||||||
|
e = xm.element(key)
|
||||||
|
t = xm.text(str(value))
|
||||||
|
xm.append(t,e)
|
||||||
|
xm.append(e,elm)
|
||||||
|
xm.write(path)
|
||||||
|
|
||||||
|
|
||||||
# Set default values
|
# Set default values
|
||||||
# Set verbose first so we can use write()
|
# Set verbose first so we can use write()
|
||||||
set("VERBOSE", ('-v' in sys.argv) or ("--verbose" in sys.argv) )
|
set("VERBOSE", ('-v' in sys.argv) or ("--verbose" in sys.argv) )
|
||||||
|
|
Loading…
Reference in New Issue