Updated config file registry object.

bzr-revno: 170
This commit is contained in:
Raoul Snyman 2008-12-03 08:51:35 +00:00
parent 51ede824fc
commit e8430a95f9
2 changed files with 74 additions and 8 deletions

View File

@ -27,5 +27,77 @@ class LinRegistry(Registry):
Unix configurations.
"""
def __init__(self, dir):
self.config = SimpleConfigParser()
self.config.read(os.path.join(dir, 'openlp.conf'))
self.config = SafeConfigParser()
self.file_name = os.path.join(dir, 'openlp.conf')
self.config.read(self.file_name)
def has_value(self, section, key):
"""
Check if a value exists.
"""
return self.config.has_option(section, key)
def get_value(self, section, key, default=None):
"""
Get a single value from the registry.
"""
if self.config.has_value(section, key):
return self.config.get(section, key)
else:
return default
def set_value(self, section, key, value):
"""
Set a single value in the registry.
"""
try:
self.config.set(section, key, value)
return self._save()
except:
return False
def delete_value(self, section, key):
"""
Delete a single value from the registry.
"""
try:
self.config.remove_option(section, key)
return self._save()
except:
return False
def has_section(self, section):
"""
Check if a section exists.
"""
return self.config.has_section(section)
def create_section(self, section):
"""
Create a new section in the registry.
"""
try:
self.config.add_section(section)
return self._save()
except:
return False
def delete_section(self, section):
"""
Delete a section (including all values).
"""
try:
self.config.remove_section(section)
return self._save()
except:
return False
def _save(self):
try:
file_handle = open(self.file_name, 'w')
self.config.write(file_handle)
close(file_handle)
self.config.read(self.file_name)
return True
except:
return False

View File

@ -34,12 +34,6 @@ class Registry(object):
"""
pass
def create_value(self, section, key):
"""
Create a new value in the registry.
"""
pass
def get_value(self, section, key, default=None):
"""
Get a single value from the registry.