Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory #62

Merged
merged 3 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions morituri/common/accurip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

from morituri.common import log, directory

d = directory.Directory()
_CACHE_DIR = d.getCache()
_CACHE_DIR = directory.cache_path()


class AccuCache(log.Loggable):
Expand Down
13 changes: 2 additions & 11 deletions morituri/common/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,9 @@ def get(self, key):
class ResultCache(log.Loggable):

def __init__(self, path=None):
if not path:
path = self._getResultCachePath()

self._path = path
self._path = path or directory.cache_path('result')
self._pcache = PersistedCache(self._path)

def _getResultCachePath(self):
d = directory.Directory()
path = d.getCache('result')
return path

def getRipResult(self, cddbdiscid, create=True):
"""
Retrieve the persistable RipResult either from our cache (from a
Expand Down Expand Up @@ -208,8 +200,7 @@ class TableCache(log.Loggable):

def __init__(self, path=None):
if not path:
d = directory.Directory()
self._path = d.getCache('table')
self._path = directory.cache_path('table')
else:
self._path = path

Expand Down
8 changes: 1 addition & 7 deletions morituri/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@
class Config(log.Loggable):

def __init__(self, path=None):
if not path:
path = self.getDefaultPath()

self._path = path
self._path = path or directory.config_path()

self._parser = ConfigParser.SafeConfigParser()

self.open()

def getDefaultPath(self):
return directory.Directory().getConfig()

def open(self):
# Open the file with the correct encoding
if os.path.exists(self._path):
Expand Down
76 changes: 28 additions & 48 deletions morituri/common/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,31 @@
# You should have received a copy of the GNU General Public License
# along with morituri. If not, see <http://www.gnu.org/licenses/>.

import os

from morituri.common import log


class Directory(log.Loggable):

def getConfig(self):
config_directory = os.getenv('XDG_CONFIG_HOME')
if not config_directory:
config_directory = os.path.join(os.path.expanduser('~'),
u'.config')
folder_path = os.path.join(config_directory, u'whipper')
if not os.path.exists(folder_path):
os.makedirs(folder_path)
path = os.path.join(config_directory, u'whipper/whipper.conf')
self.info('Configuration file path: %s' % path)
return path

def getCache(self, name=None):
cache_directory = os.getenv('XDG_CACHE_HOME')
if not cache_directory:
cache_directory = os.path.join(os.path.expanduser('~'), u'.cache')
path = os.path.join(cache_directory, u'whipper')
self.info('Cache directory path: %s' % path)
if not os.path.exists(path):
os.makedirs(path)
if name:
path = os.path.join(path, name)
if not os.path.exists(path):
os.makedirs(path)
return path

def getData(self, name=None):
data_directory = os.getenv('XDG_DATA_HOME')
if not data_directory:
data_directory = os.path.join(os.path.expanduser('~'),
u'.local/share')
path = os.path.join(data_directory, u'whipper')
self.info('Data directory path: %s' % path)
if not os.path.exists(path):
os.makedirs(path)
if name:
path = os.path.join(path, name)
if not os.path.exists(path):
os.makedirs(path)
return path

from os import getenv, makedirs
from os.path import join, expanduser, exists

def config_path():
path = join(getenv('XDG_CONFIG_HOME') or join(expanduser('~'), u'.config'),
u'whipper')
if not exists(path):
makedirs(path)
return join(path, u'whipper.conf')

def cache_path(name=None):
path = join(getenv('XDG_CACHE_HOME') or join(expanduser('~'), u'.cache'),
u'whipper')
if name:
path = join(path, name)
if not exists(path):
makedirs(path)
return path

def data_path(name=None):
path = join(getenv('XDG_DATA_HOME')
or join(expanduser('~'), u'.local/share'),
u'whipper')
if name:
path = join(path, name)
if not exists(path):
makedirs(path)
return path
5 changes: 5 additions & 0 deletions morituri/rip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def main():
# set user agent
musicbrainzngs.set_useragent("morituri", configure.version,
'https://thomas.apestaart.org/morituri/trac')
# register plugins with pkg_resources
distributions, _ = pkg_resources.working_set.find_plugins(
pkg_resources.Environment([directory.data_path('plugins')])
)
map(pkg_resources.working_set.add, distributions)
c = Rip()
try:
ret = c.parse(sys.argv[1:])
Expand Down
6 changes: 2 additions & 4 deletions morituri/test/test_common_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
class DirectoryTestCase(common.TestCase):

def testAll(self):
d = directory.Directory()

path = d.getConfig()
path = directory.config_path()
self.failUnless(path.startswith('/home'))

path = d.getCache()
path = directory.cache_path()
self.failUnless(path.startswith('/home'))