From 628f6897824bebc98918fb4e8339a5e4843a8afe Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 22 Oct 2008 18:42:52 +0000 Subject: [PATCH] Create Config Helper bzr-revno: 23 --- openlp/utils/ConfigHelper.py | 32 ++++++++++++++++++++++++++++++++ openlp/utils/__init__.py | 1 + 2 files changed, 33 insertions(+) create mode 100644 openlp/utils/ConfigHelper.py create mode 100644 openlp/utils/__init__.py diff --git a/openlp/utils/ConfigHelper.py b/openlp/utils/ConfigHelper.py new file mode 100644 index 000000000..5acbb9552 --- /dev/null +++ b/openlp/utils/ConfigHelper.py @@ -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') + diff --git a/openlp/utils/__init__.py b/openlp/utils/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/openlp/utils/__init__.py @@ -0,0 +1 @@ +