From c87e13f14ac847fa0edf0c22137a68cd4055d72b Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Sun, 24 Jul 2016 16:08:53 +0200 Subject: [PATCH 1/2] Address issue #24 Now whipper always follows XDG specifications. All changes were documented into the README file. --- README.md | 35 ++++++++++++---- morituri/common/accurip.py | 5 ++- morituri/common/cache.py | 4 +- morituri/common/directory.py | 80 ++++++++++++++++++------------------ morituri/rip/main.py | 6 +-- 5 files changed, 74 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 1489f6f6..ce7b28b3 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FORK INFORMATIONS --------- The name of this fork is still to be decided: right now I'll be using whipper. -This branch is very close to morituri's master one (the internal 'morituri' references are still unchanged). As a starting point, I've just merged the following commits: +This branch is very close to morituri's master one (internal morituri references are still unchanged). As a starting point, I've just merged the following commits: - [#79](https://github.com/thomasvs/morituri/issues/79) - [#92](https://github.com/thomasvs/morituri/issues/92) - [#109](https://github.com/thomasvs/morituri/issues/109) @@ -12,9 +12,29 @@ This branch is very close to morituri's master one (the internal 'morituri' refe - [#140](https://github.com/thomasvs/morituri/issues/140) - [#141](https://github.com/thomasvs/morituri/issues/141) -And changed the default logger to morituri-whatlogger's one. +And changed the default logger to [morituri-yamllogger](https://github.com/JoeLametta/morituri-yamllogger)'s one. -In order to track whipper's development it's better to check its commit history (readme needs to be updated). +In order to track whipper's current development it's better to check its commit history (README *needs* to be updated). + +**WARNING:** As whipper is still under heavy development sometimes I will force push (`--force-with-lease`) to the non master branches. + +BACKWARD INCOMPATIBLE CHANGES +--------- +* Whipper has adopted new config/cache/state file paths + * Now always follows XDG specifications + * Paths used when XDG environment variables are available: + * `$XDG_CONFIG_HOME/whipper` + * `$XDG_CACHE_HOME/whipper` + * `$XDG_DATA_HOME/whipper` + * Paths used when XDG environment variables are **NOT** available: + * `$HOME/.config/whipper` + * `$HOME/.cache/whipper` + * `$HOME/.local/share/whipper` + * Configuration file information: + * `.moriturirc`, `morituri.conf` aren't used anymore + * `$XDG_CONFIG_HOME/whipper/whipper.conf` (OR `$HOME/.config/whipper/whipper.conf`) + * Plugins folder path: + * `$XDG_DATA_HOME/whipper/plugins` (OR `$HOME/.local/share/whipper/plugins`) WHIPPER [![Build Status](https://travis-ci.org/JoeLametta/whipper.svg?branch=master)](https://travis-ci.org/JoeLametta/whipper) --------- @@ -22,9 +42,7 @@ whipper is a fork of the morituri project (CDDA ripper for *nix systems aiming f It improves morituri which development seems to have halted/slowed down merging old pull requests and improving it with bugfixes and new functions. -If possible, I'll try to mainline the useful commits of this fork but, in the future, this may not be possible because of different project choices. - -The project home page is still TBD. +If possible, I'll try to upstream the progress done here but, in the future, this may not be possible because of different project choices. RATIONALE --------- @@ -150,7 +168,7 @@ The simplest way to get started making accurate rips is: FILING BUGS ----------- -whipper's bug tracker is still TBD. +whipper's bugs are tracked using the repository issue section provided by GitHub. morituri's bug tracker is at [http://thomas.apestaart.org/morituri/trac/]( http://thomas.apestaart.org/morituri/trac/). @@ -184,7 +202,7 @@ The configuration file is stored according to [XDG Base Directory Specification] http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) when possible. -It lives in `$XDG_CONFIG_HOME/morituri/morituri.conf` +It lives in `$XDG_CONFIG_HOME/whipper/whipper.conf` (or `$HOME/.config/whipper/whipper.conf`) The configuration file follows python's ConfigParser syntax. @@ -217,3 +235,4 @@ Note: to get a literal '%' character it must be doubled. CONTRIBUTING ------------ - Please send pull requests through GitHub. + diff --git a/morituri/common/accurip.py b/morituri/common/accurip.py index 4f5c7014..a6c2309f 100644 --- a/morituri/common/accurip.py +++ b/morituri/common/accurip.py @@ -26,9 +26,10 @@ import urlparse import urllib2 -from morituri.common import log +from morituri.common import log, directory -_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache') +d = directory.Directory() +_CACHE_DIR = d.getCache() class AccuCache(log.Loggable): diff --git a/morituri/common/cache.py b/morituri/common/cache.py index d2ff9feb..ce94f6f0 100644 --- a/morituri/common/cache.py +++ b/morituri/common/cache.py @@ -162,8 +162,8 @@ def __init__(self, path=None): self._pcache = PersistedCache(self._path) def _getResultCachePath(self): - path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache', - 'result') + d = directory.Directory() + path = d.getCache('result') return path def getRipResult(self, cddbdiscid, create=True): diff --git a/morituri/common/directory.py b/morituri/common/directory.py index 47aac112..b9a2320c 100644 --- a/morituri/common/directory.py +++ b/morituri/common/directory.py @@ -28,56 +28,54 @@ class Directory(log.Loggable): def getConfig(self): - try: - from xdg import BaseDirectory - directory = BaseDirectory.save_config_path('morituri') - path = os.path.join(directory, 'morituri.conf') - self.info('Using XDG, configuration file is %s' % path) - except ImportError: - path = os.path.join(os.path.expanduser('~'), '.moriturirc') - self.info('Not using XDG, configuration file is %s' % path) + config_directory = os.getenv('XDG_CONFIG_HOME') + if not config_directory: + config_directory = os.path.join(os.path.expanduser('~'), + u'.config') + path = os.path.join(config_directory, u'whipper/whipper.conf') + self.info('Configuration file path: %s' % path) return path - def getCache(self, name=None): - try: - from xdg import BaseDirectory - path = BaseDirectory.save_cache_path('morituri') - self.info('Using XDG, cache directory is %s' % path) - except (ImportError, AttributeError): - # save_cache_path was added in pyxdg 0.25 - path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache') - if not os.path.exists(path): - os.makedirs(path) - self.info('Not using XDG, cache directory is %s' % path) - + 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 getReadCaches(self, name=None): - paths = [] - - try: - from xdg import BaseDirectory - path = BaseDirectory.save_cache_path('morituri') - self.info('For XDG, read cache directory is %s' % path) - paths.append(path) - except (ImportError, AttributeError): - # save_cache_path was added in pyxdg 0.21 - pass - - path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache') - if os.path.exists(path): - self.info('From before XDG, read cache directory is %s' % path) - paths.append(path) - + 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('Read cache path: %s' % path) + if not os.path.exists(path): + os.makedirs(path) if name: - paths = [os.path.join(p, name) for p in paths] - - return paths - + 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 diff --git a/morituri/rip/main.py b/morituri/rip/main.py index 3693636b..a73efaa2 100644 --- a/morituri/rip/main.py +++ b/morituri/rip/main.py @@ -5,7 +5,7 @@ import sys import pkg_resources -from morituri.common import log, logcommand, common, config +from morituri.common import log, logcommand, common, config, directory from morituri.configure import configure from morituri.rip import cd, offset, drive, image, accurip, debug @@ -19,8 +19,8 @@ def main(argv): from morituri.configure import configure pluginsdir = configure.pluginsdir - homepluginsdir = os.path.join(os.path.expanduser('~'), - '.morituri', 'plugins') + d = directory.Directory() + homepluginsdir = d.getData('plugins') distributions, errors = pkg_resources.working_set.find_plugins( pkg_resources.Environment([pluginsdir, homepluginsdir])) From fa82121a741a3088a7dd37e21d4ad0317dcf680b Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Sun, 18 Sep 2016 23:10:35 +0200 Subject: [PATCH 2/2] Remove getReadCaches() & replace it with getCache() Untested --- morituri/common/cache.py | 27 ++++++++++---------------- morituri/common/directory.py | 14 ------------- morituri/test/test_common_directory.py | 3 --- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/morituri/common/cache.py b/morituri/common/cache.py index ce94f6f0..f9c701a9 100644 --- a/morituri/common/cache.py +++ b/morituri/common/cache.py @@ -210,33 +210,26 @@ def __init__(self, path=None): if not path: d = directory.Directory() self._path = d.getCache('table') - self._readPaths = d.getReadCaches('table') else: self._path = path - self._readPaths = [path, ] self._pcache = PersistedCache(self._path) - self._readPCaches = [PersistedCache(p) for p in self._readPaths] def get(self, cddbdiscid, mbdiscid): # Before 0.2.1, we only saved by cddbdiscid, and had collisions # mbdiscid collisions are a lot less likely - for pcache in self._readPCaches: - ptable = pcache.get('mbdiscid.' + mbdiscid) - if ptable.object: - break + ptable = self._pcache.get('mbdiscid.' + mbdiscid) if not ptable.object: - for pcache in self._readPCaches: - ptable = pcache.get(cddbdiscid) - if ptable.object: - if ptable.object.getMusicBrainzDiscId() != mbdiscid: - self.debug('cached table is for different mb id %r' % ( - ptable.object.getMusicBrainzDiscId())) - ptable.object = None - else: - self.debug('no valid cached table found for %r' % - cddbdiscid) + ptable = self._pcache.get(cddbdiscid) + if ptable.object: + if ptable.object.getMusicBrainzDiscId() != mbdiscid: + self.debug('cached table is for different mb id %r' % ( + ptable.object.getMusicBrainzDiscId())) + ptable.object = None + else: + self.debug('no valid cached table found for %r' % + cddbdiscid) if not ptable.object: # get an empty persistable from the writable location diff --git a/morituri/common/directory.py b/morituri/common/directory.py index b9a2320c..326e8ac9 100644 --- a/morituri/common/directory.py +++ b/morituri/common/directory.py @@ -50,20 +50,6 @@ def getCache(self, name=None): os.makedirs(path) return path - def getReadCaches(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('Read cache 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: diff --git a/morituri/test/test_common_directory.py b/morituri/test/test_common_directory.py index c7b2766d..1c7b6c14 100644 --- a/morituri/test/test_common_directory.py +++ b/morituri/test/test_common_directory.py @@ -16,6 +16,3 @@ def testAll(self): path = d.getCache() self.failUnless(path.startswith('/home')) - - paths = d.getReadCaches() - self.failUnless(paths[0].startswith('/home'))