Create Config Helper

bzr-revno: 23
This commit is contained in:
Tim Bentley 2008-10-22 18:42:52 +00:00
parent 56dab843c5
commit 628f689782
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import os
# Utility Helper to allow classes to find directories in a standard manner
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
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 getSongsFile():
path = getConfigPath()
songfile = os.path.join(path, ".openlp.org", "Data", "songs.olp")
if os.path.exists(songfile):
filename.set_filename(songfile)
print songfile
def getBiblePath():
return os.path.join(getConfigPath(), 'Bibles')

1
openlp/utils/__init__.py Normal file
View File

@ -0,0 +1 @@