Made a start on the LinRegistry class.

bzr-revno: 169
This commit is contained in:
Raoul Snyman 2008-12-02 20:59:05 +00:00
parent 5a4f0a645e
commit 51ede824fc
6 changed files with 31 additions and 26 deletions

View File

@ -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-02, 21:51:18 --> <!-- Saved: 2008-12-02, 22:58:22 -->
<!-- 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>

View File

@ -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-02, 21:51:18 --> <!-- Saved: 2008-12-02, 22:58:22 -->
<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>

View File

@ -25,17 +25,9 @@ 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 @staticmethod
def getConfigPath(): def get_data_path():
if os.name == 'nt': reg = ConfigHelper.get_registry()
import _winreg return reg.get_value('main', 'data_path')
reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
key = r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
path = get_registry_value(reg, key, "Common AppData")
elif os.name == 'posix':
path = os.path.join(os.getenv('HOME'), ".openlp.org")
#if os.path.exists(path) == False :
# raise Exception ('Configuration Directory does not Exist ')
return path
@staticmethod @staticmethod
def get_data_path(): def get_data_path():
@ -43,7 +35,7 @@ class ConfigHelper(object):
return reg.get_value('main', 'data_path') return reg.get_value('main', 'data_path')
@staticmethod @staticmethod
def getSongsFile(): def get_songs_file():
path = ConfigHelper.get_data_path() path = ConfigHelper.get_data_path()
songfile = os.path.join(path, "songs", "songs.olp") songfile = os.path.join(path, "songs", "songs.olp")
if os.path.exists(songfile): if os.path.exists(songfile):
@ -66,5 +58,5 @@ class ConfigHelper(object):
reg = WinRegistry(r'\Software\openlp') reg = WinRegistry(r'\Software\openlp')
else: else:
from linregistry import LinRegistry from linregistry import LinRegistry
reg = LinRegistry() reg = LinRegistry(os.path.join(os.getenv('HOME'), '.openlp'))
return reg return reg

View File

@ -17,7 +17,8 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os
from ConfigParser import SimpleConfigParser
from openlp.core.utils import Registry from openlp.core.utils import Registry
class LinRegistry(Registry): class LinRegistry(Registry):
@ -25,5 +26,6 @@ class LinRegistry(Registry):
The LinRegistry class is a high-level class for working with Linux and The LinRegistry class is a high-level class for working with Linux and
Unix configurations. Unix configurations.
""" """
def __init__(self): def __init__(self, dir):
pass self.config = SimpleConfigParser()
self.config.read(os.path.join(dir, 'openlp.conf'))

View File

@ -40,7 +40,7 @@ class Registry(object):
""" """
pass pass
def get_value(self, section, key): def get_value(self, section, key, default=None):
""" """
Get a single value from the registry. Get a single value from the registry.
""" """

View File

@ -41,7 +41,11 @@ class WinRegistry(Registry):
Check if a key/value exists. Check if a key/value exists.
""" """
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section) key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
value, reg_type = _winreg.QueryValueEx(key_handle, key)[0] try:
value, reg_type = _winreg.QueryValueEx(key_handle, key)
except EnvironmentError:
return False
finally:
_winreg.CloseKey(key_handle) _winreg.CloseKey(key_handle)
if reg_type == _winreg.REG_NONE: if reg_type == _winreg.REG_NONE:
return False return False
@ -52,12 +56,19 @@ class WinRegistry(Registry):
else: else:
return True return True
def get_value(self, section, key): def get_value(self, section, key, default=None):
""" """
Get a single value from the Windows registry. Get a single value from the Windows registry.
""" """
if not self.has_value(section, key):
return default
else:
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section) key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
try:
value = _winreg.QueryValueEx(key_handle, key)[0] value = _winreg.QueryValueEx(key_handle, key)[0]
except EnvironmentError:
value = default
finally:
_winreg.CloseKey(key_handle) _winreg.CloseKey(key_handle)
return value return value