ext: Add getter methods for cache, config and data directories
Methods do get or create directories
This commit is contained in:
parent
13133fd919
commit
41db4991aa
@ -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``.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user