76 lines
1.5 KiB
Python
76 lines
1.5 KiB
Python
#! /usr/bin/python
|
|
|
|
# To change this template, choose Tools | Templates
|
|
# and open the template in the editor.
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Feb 17, 2010 9:32:56 PM$"
|
|
|
|
from sys import argv,platform
|
|
import os
|
|
|
|
from bt.message import write
|
|
from bt.file import join
|
|
from bt import xm
|
|
|
|
|
|
class Settings(dict):
|
|
def __init__(self):
|
|
dict.__init__(self)
|
|
|
|
|
|
def setdefaults(self):
|
|
count = 0
|
|
if ("-v" in argv) or ("--verbose" in argv):
|
|
count = argv.count("-v") + argv.count("--verbose")
|
|
self['verbose'] = count
|
|
write("Setting default values",1)
|
|
self['user'] = os.path.expanduser("~")
|
|
self['plugpath'] = ["plugins", "extra"]
|
|
self['arch'] = platform
|
|
self['appname'] = "scion"
|
|
write(self,3)
|
|
|
|
|
|
|
|
def has(self,key):
|
|
return (key.upper() in self)
|
|
|
|
|
|
def init(self,key,value):
|
|
if self.has(key)==False:
|
|
self[key] = value
|
|
|
|
|
|
def __setitem__(self,key,value):
|
|
key = key.upper()
|
|
dict.__setitem__(self,key,value)
|
|
|
|
|
|
def __getitem__(self,key):
|
|
key = key.upper()
|
|
if self.has(key)==True:
|
|
return dict.__getitem__(self,key)
|
|
return None
|
|
|
|
|
|
def __delitem__(self,key):
|
|
dict.__delitem__(self,key.upper())
|
|
|
|
|
|
def load(self,path):
|
|
write("Loading saved settings",1)
|
|
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.value( xm.child(node) )
|
|
write(" ( "+key + ", " + str(val) + " )",2)
|
|
self[key] = val
|
|
pass
|