From 63bb9b3186e20ebf9bb6c9e27ea8314cfe40aef2 Mon Sep 17 00:00:00 2001 From: Michael Gorven Date: Mon, 15 Dec 2008 20:37:50 +0000 Subject: [PATCH] Create data directories when path is requested from config bzr-revno: 227 --- openlp/core/lib/pluginconfig.py | 7 ++++++- openlp/core/utils/confighelper.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/pluginconfig.py b/openlp/core/lib/pluginconfig.py index 57a0016b3..8a00b92d3 100644 --- a/openlp/core/lib/pluginconfig.py +++ b/openlp/core/lib/pluginconfig.py @@ -48,7 +48,12 @@ class PluginConfig(object): app_data = ConfigHelper.get_data_path() safe_name = self.section.replace(' ', '-') plugin_data = self.get_config('data path', safe_name) - return os.path.join(app_data, plugin_data) + path = os.path.join(app_data, plugin_data) + + if not os.path.exists(path): + os.makedirs(path) + + return path def set_data_path(self, path): return self.set_config('data path', os.path.basename(path)) diff --git a/openlp/core/utils/confighelper.py b/openlp/core/utils/confighelper.py index c7c1fadc2..90a17c54a 100644 --- a/openlp/core/utils/confighelper.py +++ b/openlp/core/utils/confighelper.py @@ -26,8 +26,19 @@ class ConfigHelper(object): """ @staticmethod def get_data_path(): + if os.name == 'nt': + default = os.path.join(os.path.expanduser(u'~'), + u'Application Data', u'.openlp', u'data') + else: + default = os.path.expanduser(u'~/.openlp/data') + reg = ConfigHelper.get_registry() - return reg.get_value('main', 'data path') + path = reg.get_value('main', 'data path', default) + + if not os.path.exists(path): + os.makedirs(path) + + return path @staticmethod def get_config(section, key, default=None):