forked from openlp/openlp
Made some changes to the ConfigHelper to use the Registry objects.
bzr-revno: 165
This commit is contained in:
parent
9a7c2b42a7
commit
170c480817
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
||||||
<!-- eric4 user project file for project openlp.org 2.0 -->
|
<!-- 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 -->
|
<!-- Copyright (C) 2008 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||||
<UserProject version="4.0">
|
<UserProject version="4.0">
|
||||||
</UserProject>
|
</UserProject>
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
|
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
|
||||||
<!-- eric4 tasks file for project openlp.org 2.0 -->
|
<!-- 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">
|
<Tasks version="4.2">
|
||||||
<Task priority="1" completed="False" bugfix="False">
|
<Task priority="1" completed="False" bugfix="False">
|
||||||
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
||||||
|
@ -24,13 +24,6 @@ class ConfigHelper(object):
|
|||||||
"""
|
"""
|
||||||
Utility Helper to allow classes to find directories in a standard manner.
|
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
|
@staticmethod
|
||||||
def getConfigPath():
|
def getConfigPath():
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
@ -44,10 +37,15 @@ class ConfigHelper(object):
|
|||||||
# raise Exception ('Configuration Directory does not Exist ')
|
# raise Exception ('Configuration Directory does not Exist ')
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_data_path():
|
||||||
|
reg = ConfigHelper.get_registry()
|
||||||
|
return reg.get_value('main', 'data_path')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSongsFile():
|
def getSongsFile():
|
||||||
path = ConfigHelper.getConfigPath()
|
path = ConfigHelper.get_data_path()
|
||||||
songfile = os.path.join(path, ".openlp.org", "Data", "songs.olp")
|
songfile = os.path.join(path, "songs", "songs.olp")
|
||||||
if os.path.exists(songfile):
|
if os.path.exists(songfile):
|
||||||
filename.set_filename(songfile)
|
filename.set_filename(songfile)
|
||||||
print songfile
|
print songfile
|
||||||
@ -57,7 +55,7 @@ class ConfigHelper(object):
|
|||||||
return os.path.join(ConfigHelper.getConfigPath(), "Data","Bibles")
|
return os.path.join(ConfigHelper.getConfigPath(), "Data","Bibles")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getRegistry():
|
def get_registry():
|
||||||
"""
|
"""
|
||||||
This static method loads the appropriate registry class based on the
|
This static method loads the appropriate registry class based on the
|
||||||
current operating system, and returns an instantiation of that class.
|
current operating system, and returns an instantiation of that class.
|
||||||
@ -65,7 +63,7 @@ class ConfigHelper(object):
|
|||||||
reg = None
|
reg = None
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
from winregistry import WinRegistry
|
from winregistry import WinRegistry
|
||||||
reg = WinRegistry()
|
reg = WinRegistry(r'\Software\openlp')
|
||||||
else:
|
else:
|
||||||
from linregistry import LinRegistry
|
from linregistry import LinRegistry
|
||||||
reg = LinRegistry()
|
reg = LinRegistry()
|
||||||
|
@ -26,8 +26,6 @@ class WinRegistry(Registry):
|
|||||||
"""
|
"""
|
||||||
The WinRegistry class is a high-level wrapper class for the Windows registry
|
The WinRegistry class is a high-level wrapper class for the Windows registry
|
||||||
functions in Python.
|
functions in Python.
|
||||||
|
|
||||||
Notes:
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, base_key):
|
def __init__(self, base_key):
|
||||||
"""
|
"""
|
||||||
@ -40,15 +38,19 @@ class WinRegistry(Registry):
|
|||||||
|
|
||||||
def has_value(self, section, key):
|
def has_value(self, section, key):
|
||||||
"""
|
"""
|
||||||
Check if a key exists.
|
Check if a key/value exists.
|
||||||
"""
|
"""
|
||||||
|
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
|
return False
|
||||||
|
elif reg_type == _winreg.REG_SZ and value == '':
|
||||||
def create_value(self, section, key):
|
return False
|
||||||
"""
|
elif reg_type == _winreg.REG_DWORD and value == 0:
|
||||||
Create a new key in the Windows registry.
|
return False
|
||||||
"""
|
else:
|
||||||
pass
|
return True
|
||||||
|
|
||||||
def get_value(self, section, key):
|
def get_value(self, section, key):
|
||||||
"""
|
"""
|
||||||
@ -84,7 +86,13 @@ class WinRegistry(Registry):
|
|||||||
"""
|
"""
|
||||||
Check if a section exists.
|
Check if a section exists.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
|
||||||
|
except EnvironmentError:
|
||||||
return False
|
return False
|
||||||
|
finally:
|
||||||
|
_winreg.CloseKey(key_handle)
|
||||||
|
return True
|
||||||
|
|
||||||
def create_section(self, section):
|
def create_section(self, section):
|
||||||
"""
|
"""
|
||||||
@ -97,4 +105,11 @@ class WinRegistry(Registry):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def delete_section(self, section):
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user