From 41db4991aa037e515f071a22b8d830bf1bd21f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dejan=20Proki=C4=87?= Date: Sat, 25 Jul 2015 18:16:35 +0200 Subject: [PATCH] ext: Add getter methods for cache, config and data directories Methods do get or create directories --- mopidy/ext.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mopidy/ext.py b/mopidy/ext.py index ab35008a..cdaa5662 100644 --- a/mopidy/ext.py +++ b/mopidy/ext.py @@ -2,10 +2,12 @@ from __future__ import absolute_import, unicode_literals import collections import logging +import os import pkg_resources from mopidy import config as config_lib, exceptions +from mopidy.internal import path logger = logging.getLogger(__name__) @@ -58,6 +60,42 @@ class Extension(object): schema['enabled'] = config_lib.Boolean() return schema + def get_cache_dir(self, config): + """Get or create cache directory for extension and return path + + :param config: Loaded configuration + :return: string + """ + assert self.ext_name is not None + cache_dir_path = bytes(os.path.join(config['core']['cache_dir'], + self.ext_name)) + path.get_or_create_dir(cache_dir_path) + return cache_dir_path + + def get_config_dir(self, config): + """Get or create configuration directory for extension and return path + + :param config: Loaded configuration + :return: string + """ + assert self.ext_name is not None + config_dir_path = bytes(os.path.join(config['core']['config_dir'], + self.ext_name)) + path.get_or_create_dir(config_dir_path) + return config_dir_path + + def get_data_dir(self, config): + """Get or create data directory for extension and return path + + :param config: Loaded configuration + :returns: string + """ + assert self.ext_name is not None + data_dir_path = bytes(os.path.join(config['core']['data_dir'], + self.ext_name)) + path.get_or_create_dir(data_dir_path) + return data_dir_path + def get_command(self): """Command to expose to command line users running ``mopidy``.