forked from openlp/openlp
Made a start on the LinRegistry class.
bzr-revno: 169
This commit is contained in:
parent
5a4f0a645e
commit
51ede824fc
@ -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-02, 21:51:18 -->
|
||||
<!-- Saved: 2008-12-02, 22:58:22 -->
|
||||
<!-- Copyright (C) 2008 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||
<UserProject version="4.0">
|
||||
</UserProject>
|
@ -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-02, 21:51:18 -->
|
||||
<!-- Saved: 2008-12-02, 22:58:22 -->
|
||||
<Tasks version="4.2">
|
||||
<Task priority="1" completed="False" bugfix="False">
|
||||
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
||||
|
@ -25,17 +25,9 @@ class ConfigHelper(object):
|
||||
Utility Helper to allow classes to find directories in a standard manner.
|
||||
"""
|
||||
@staticmethod
|
||||
def getConfigPath():
|
||||
if os.name == 'nt':
|
||||
import _winreg
|
||||
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
|
||||
def get_data_path():
|
||||
reg = ConfigHelper.get_registry()
|
||||
return reg.get_value('main', 'data_path')
|
||||
|
||||
@staticmethod
|
||||
def get_data_path():
|
||||
@ -43,7 +35,7 @@ class ConfigHelper(object):
|
||||
return reg.get_value('main', 'data_path')
|
||||
|
||||
@staticmethod
|
||||
def getSongsFile():
|
||||
def get_songs_file():
|
||||
path = ConfigHelper.get_data_path()
|
||||
songfile = os.path.join(path, "songs", "songs.olp")
|
||||
if os.path.exists(songfile):
|
||||
@ -66,5 +58,5 @@ class ConfigHelper(object):
|
||||
reg = WinRegistry(r'\Software\openlp')
|
||||
else:
|
||||
from linregistry import LinRegistry
|
||||
reg = LinRegistry()
|
||||
reg = LinRegistry(os.path.join(os.getenv('HOME'), '.openlp'))
|
||||
return reg
|
||||
|
@ -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
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
import os
|
||||
from ConfigParser import SimpleConfigParser
|
||||
from openlp.core.utils import Registry
|
||||
|
||||
class LinRegistry(Registry):
|
||||
@ -25,5 +26,6 @@ class LinRegistry(Registry):
|
||||
The LinRegistry class is a high-level class for working with Linux and
|
||||
Unix configurations.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, dir):
|
||||
self.config = SimpleConfigParser()
|
||||
self.config.read(os.path.join(dir, 'openlp.conf'))
|
||||
|
@ -40,7 +40,7 @@ class Registry(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_value(self, section, key):
|
||||
def get_value(self, section, key, default=None):
|
||||
"""
|
||||
Get a single value from the registry.
|
||||
"""
|
||||
|
@ -41,8 +41,12 @@ class WinRegistry(Registry):
|
||||
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)
|
||||
try:
|
||||
value, reg_type = _winreg.QueryValueEx(key_handle, key)
|
||||
except EnvironmentError:
|
||||
return False
|
||||
finally:
|
||||
_winreg.CloseKey(key_handle)
|
||||
if reg_type == _winreg.REG_NONE:
|
||||
return False
|
||||
elif reg_type == _winreg.REG_SZ and value == '':
|
||||
@ -52,14 +56,21 @@ class WinRegistry(Registry):
|
||||
else:
|
||||
return True
|
||||
|
||||
def get_value(self, section, key):
|
||||
def get_value(self, section, key, default=None):
|
||||
"""
|
||||
Get a single value from the Windows registry.
|
||||
"""
|
||||
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
|
||||
value = _winreg.QueryValueEx(key_handle, key)[0]
|
||||
_winreg.CloseKey(key_handle)
|
||||
return value
|
||||
if not self.has_value(section, key):
|
||||
return default
|
||||
else:
|
||||
key_handle = _winreg.OpenKey(self.reg_handle, self.base_key + section)
|
||||
try:
|
||||
value = _winreg.QueryValueEx(key_handle, key)[0]
|
||||
except EnvironmentError:
|
||||
value = default
|
||||
finally:
|
||||
_winreg.CloseKey(key_handle)
|
||||
return value
|
||||
|
||||
def set_value(self, section, key, value):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user