roc/config.py
2017-05-08 13:10:48 -07:00

45 lines
833 B
Python

import os
import files
class configmanager(object):
def __init__(self):
self.filepath = None
self.data = {}
def load(self):
self.filepath = os.path.join(files.get_basedir(), 'settings.cfg')
if not os.path.exists(self.filepath):
return
fd = open(self.filepath, 'r')
for x in fd:
x = x.strip()
if not '=' in x:
continue
x = x.split('=')
k = x[0].strip()
v = '='.join(x[1:]).strip()
self.data[k] = v
fd.close()
def save(self):
fd = open(self.filepath, 'w')
for k, v in list(self.data.items()):
fd.write("%s = %s\n" % (k, v))
fd.close()
def read_key(self, key):
if key in self.data:
return self.data[key]
else:
return None
def write_key(self, key, value):
self.data[key] = value
def init():
global mgr
mgr = configmanager()
mgr.load()
mgr = None