forked from openlp/openlp
Updated config file registry object.
bzr-revno: 170
This commit is contained in:
parent
51ede824fc
commit
e8430a95f9
@ -27,5 +27,77 @@ class LinRegistry(Registry):
|
|||||||
Unix configurations.
|
Unix configurations.
|
||||||
"""
|
"""
|
||||||
def __init__(self, dir):
|
def __init__(self, dir):
|
||||||
self.config = SimpleConfigParser()
|
self.config = SafeConfigParser()
|
||||||
self.config.read(os.path.join(dir, 'openlp.conf'))
|
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
|
||||||
|
@ -34,12 +34,6 @@ class Registry(object):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_value(self, section, key):
|
|
||||||
"""
|
|
||||||
Create a new value in the registry.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_value(self, section, key, default=None):
|
def get_value(self, section, key, default=None):
|
||||||
"""
|
"""
|
||||||
Get a single value from the registry.
|
Get a single value from the registry.
|
||||||
|
Loading…
Reference in New Issue
Block a user