Made some changes to the ConfigHelper to use the Registry objects.

bzr-revno: 165
This commit is contained in:
Raoul Snyman 2008-12-02 14:40:22 +00:00
parent 9a7c2b42a7
commit 170c480817
4 changed files with 38 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
<!-- eric4 user project file for project openlp.org 2.0 -->
<!-- Saved: 2008-12-01, 22:23:24 -->
<!-- Saved: 2008-12-02, 16:38:39 -->
<!-- Copyright (C) 2008 Raoul Snyman, raoulsnyman@openlp.org -->
<UserProject version="4.0">
</UserProject>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
<!-- eric4 tasks file for project openlp.org 2.0 -->
<!-- Saved: 2008-12-01, 22:23:24 -->
<!-- Saved: 2008-12-02, 16:38:46 -->
<Tasks version="4.2">
<Task priority="1" completed="False" bugfix="False">
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>

View File

@ -24,13 +24,6 @@ class ConfigHelper(object):
"""
Utility Helper to allow classes to find directories in a standard manner.
"""
@staticmethod
def get_registry_value(reg, key, value_name):
k = _winreg.OpenKey(reg, key)
value = _winreg.QueryValueEx(k, value_name)[0]
_winreg.CloseKey(k)
return value
@staticmethod
def getConfigPath():
if os.name == 'nt':
@ -44,10 +37,15 @@ class ConfigHelper(object):
# raise Exception ('Configuration Directory does not Exist ')
return path
@staticmethod
def get_data_path():
reg = ConfigHelper.get_registry()
return reg.get_value('main', 'data_path')
@staticmethod
def getSongsFile():
path = ConfigHelper.getConfigPath()
songfile = os.path.join(path, ".openlp.org", "Data", "songs.olp")
path = ConfigHelper.get_data_path()
songfile = os.path.join(path, "songs", "songs.olp")
if os.path.exists(songfile):
filename.set_filename(songfile)
print songfile
@ -57,7 +55,7 @@ class ConfigHelper(object):
return os.path.join(ConfigHelper.getConfigPath(), "Data","Bibles")
@staticmethod
def getRegistry():
def get_registry():
"""
This static method loads the appropriate registry class based on the
current operating system, and returns an instantiation of that class.
@ -65,7 +63,7 @@ class ConfigHelper(object):
reg = None
if os.name == 'nt':
from winregistry import WinRegistry
reg = WinRegistry()
reg = WinRegistry(r'\Software\openlp')
else:
from linregistry import LinRegistry
reg = LinRegistry()

View File

@ -26,8 +26,6 @@ class WinRegistry(Registry):
"""
The WinRegistry class is a high-level wrapper class for the Windows registry
functions in Python.
Notes:
"""
def __init__(self, base_key):
"""
@ -40,15 +38,19 @@ class WinRegistry(Registry):
def has_value(self, section, key):
"""
Check if a key exists.
Check if a key/value exists.
"""
return False
def create_value(self, section, key):
"""
Create a new key in the Windows registry.
"""
pass
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
value, reg_type = _winreg.QueryValueEx(key_handle, key)[0]
_winreg.CloseKey(key_handle)
if reg_type == _winreg.REG_NONE:
return False
elif reg_type == _winreg.REG_SZ and value == '':
return False
elif reg_type == _winreg.REG_DWORD and value == 0:
return False
else:
return True
def get_value(self, section, key):
"""
@ -84,7 +86,13 @@ class WinRegistry(Registry):
"""
Check if a section exists.
"""
return False
try:
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
except EnvironmentError:
return False
finally:
_winreg.CloseKey(key_handle)
return True
def create_section(self, section):
"""
@ -97,4 +105,11 @@ class WinRegistry(Registry):
return False
def delete_section(self, section):
pass
try:
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key)
_winreg.DeleteKey(key_handle, section)
except EnvironmentError:
return False
finally:
_winreg.CloseKey(key_handle)
return True