Create data directories when path is requested from config

bzr-revno: 227
This commit is contained in:
Michael Gorven 2008-12-15 20:37:50 +00:00
parent 0187da57b9
commit 63bb9b3186
2 changed files with 18 additions and 2 deletions

View File

@ -48,7 +48,12 @@ class PluginConfig(object):
app_data = ConfigHelper.get_data_path() app_data = ConfigHelper.get_data_path()
safe_name = self.section.replace(' ', '-') safe_name = self.section.replace(' ', '-')
plugin_data = self.get_config('data path', safe_name) 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): def set_data_path(self, path):
return self.set_config('data path', os.path.basename(path)) return self.set_config('data path', os.path.basename(path))

View File

@ -26,8 +26,19 @@ class ConfigHelper(object):
""" """
@staticmethod @staticmethod
def get_data_path(): 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() 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 @staticmethod
def get_config(section, key, default=None): def get_config(section, key, default=None):