Skip to content

Commit 746dc65

Browse files
authored
Issue24 (whipper-team#42)
* Address issue whipper-team#24 * Remove getReadCaches() & replace it with getCache() Now whipper always follows XDG specifications. All changes were documented into the README file. The changes introduced here aren't backward compatible so, after updating whipper, you may need to configure it again (old config file are retained, though).
1 parent 4d81a02 commit 746dc65

6 files changed

Lines changed: 70 additions & 76 deletions

File tree

README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FORK INFORMATIONS
22
---------
33
The name of this fork is still to be decided: right now I'll be using whipper.
44

5-
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:
5+
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:
66
- [#79](https://github.com/thomasvs/morituri/issues/79)
77
- [#92](https://github.com/thomasvs/morituri/issues/92)
88
- [#109](https://github.com/thomasvs/morituri/issues/109)
@@ -12,19 +12,37 @@ This branch is very close to morituri's master one (the internal 'morituri' refe
1212
- [#140](https://github.com/thomasvs/morituri/issues/140)
1313
- [#141](https://github.com/thomasvs/morituri/issues/141)
1414

15-
And changed the default logger to morituri-whatlogger's one.
15+
And changed the default logger to [morituri-yamllogger](https://github.com/JoeLametta/morituri-yamllogger)'s one.
1616

17-
In order to track whipper's development it's better to check its commit history (readme needs to be updated).
17+
In order to track whipper's current development it's better to check its commit history (README *needs* to be updated).
18+
19+
**WARNING:** As whipper is still under heavy development sometimes I will force push (`--force-with-lease`) to the non master branches.
20+
21+
BACKWARD INCOMPATIBLE CHANGES
22+
---------
23+
* Whipper has adopted new config/cache/state file paths
24+
* Now always follows XDG specifications
25+
* Paths used when XDG environment variables are available:
26+
* `$XDG_CONFIG_HOME/whipper`
27+
* `$XDG_CACHE_HOME/whipper`
28+
* `$XDG_DATA_HOME/whipper`
29+
* Paths used when XDG environment variables are **NOT** available:
30+
* `$HOME/.config/whipper`
31+
* `$HOME/.cache/whipper`
32+
* `$HOME/.local/share/whipper`
33+
* Configuration file information:
34+
* `.moriturirc`, `morituri.conf` aren't used anymore
35+
* `$XDG_CONFIG_HOME/whipper/whipper.conf` (OR `$HOME/.config/whipper/whipper.conf`)
36+
* Plugins folder path:
37+
* `$XDG_DATA_HOME/whipper/plugins` (OR `$HOME/.local/share/whipper/plugins`)
1838

1939
WHIPPER [![Build Status](https://travis-ci.org/JoeLametta/whipper.svg?branch=master)](https://travis-ci.org/JoeLametta/whipper)
2040
---------
2141
whipper is a fork of the morituri project (CDDA ripper for *nix systems aiming for accuracy over speed).
2242

2343
It improves morituri which development seems to have halted/slowed down merging old pull requests and improving it with bugfixes and new functions.
2444

25-
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.
26-
27-
The project home page is still TBD.
45+
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.
2846

2947
RATIONALE
3048
---------
@@ -150,7 +168,7 @@ The simplest way to get started making accurate rips is:
150168

151169
FILING BUGS
152170
-----------
153-
whipper's bug tracker is still TBD.
171+
whipper's bugs are tracked using the repository issue section provided by GitHub.
154172

155173
morituri's bug tracker is at [http://thomas.apestaart.org/morituri/trac/](
156174
http://thomas.apestaart.org/morituri/trac/).
@@ -184,7 +202,7 @@ The configuration file is stored according to [XDG Base Directory Specification]
184202
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)
185203
when possible.
186204

187-
It lives in `$XDG_CONFIG_HOME/morituri/morituri.conf`
205+
It lives in `$XDG_CONFIG_HOME/whipper/whipper.conf` (or `$HOME/.config/whipper/whipper.conf`)
188206

189207
The configuration file follows python's ConfigParser syntax.
190208

@@ -217,3 +235,4 @@ Note: to get a literal '%' character it must be doubled.
217235
CONTRIBUTING
218236
------------
219237
- Please send pull requests through GitHub.
238+

morituri/common/accurip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import urlparse
2727
import urllib2
2828

29-
from morituri.common import log
29+
from morituri.common import log, directory
3030

31-
_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
31+
d = directory.Directory()
32+
_CACHE_DIR = d.getCache()
3233

3334

3435
class AccuCache(log.Loggable):

morituri/common/cache.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def __init__(self, path=None):
162162
self._pcache = PersistedCache(self._path)
163163

164164
def _getResultCachePath(self):
165-
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache',
166-
'result')
165+
d = directory.Directory()
166+
path = d.getCache('result')
167167
return path
168168

169169
def getRipResult(self, cddbdiscid, create=True):
@@ -210,33 +210,26 @@ def __init__(self, path=None):
210210
if not path:
211211
d = directory.Directory()
212212
self._path = d.getCache('table')
213-
self._readPaths = d.getReadCaches('table')
214213
else:
215214
self._path = path
216-
self._readPaths = [path, ]
217215

218216
self._pcache = PersistedCache(self._path)
219-
self._readPCaches = [PersistedCache(p) for p in self._readPaths]
220217

221218
def get(self, cddbdiscid, mbdiscid):
222219
# Before 0.2.1, we only saved by cddbdiscid, and had collisions
223220
# mbdiscid collisions are a lot less likely
224-
for pcache in self._readPCaches:
225-
ptable = pcache.get('mbdiscid.' + mbdiscid)
226-
if ptable.object:
227-
break
221+
ptable = self._pcache.get('mbdiscid.' + mbdiscid)
228222

229223
if not ptable.object:
230-
for pcache in self._readPCaches:
231-
ptable = pcache.get(cddbdiscid)
232-
if ptable.object:
233-
if ptable.object.getMusicBrainzDiscId() != mbdiscid:
234-
self.debug('cached table is for different mb id %r' % (
235-
ptable.object.getMusicBrainzDiscId()))
236-
ptable.object = None
237-
else:
238-
self.debug('no valid cached table found for %r' %
239-
cddbdiscid)
224+
ptable = self._pcache.get(cddbdiscid)
225+
if ptable.object:
226+
if ptable.object.getMusicBrainzDiscId() != mbdiscid:
227+
self.debug('cached table is for different mb id %r' % (
228+
ptable.object.getMusicBrainzDiscId()))
229+
ptable.object = None
230+
else:
231+
self.debug('no valid cached table found for %r' %
232+
cddbdiscid)
240233

241234
if not ptable.object:
242235
# get an empty persistable from the writable location

morituri/common/directory.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,56 +28,40 @@
2828
class Directory(log.Loggable):
2929

3030
def getConfig(self):
31-
try:
32-
from xdg import BaseDirectory
33-
directory = BaseDirectory.save_config_path('morituri')
34-
path = os.path.join(directory, 'morituri.conf')
35-
self.info('Using XDG, configuration file is %s' % path)
36-
except ImportError:
37-
path = os.path.join(os.path.expanduser('~'), '.moriturirc')
38-
self.info('Not using XDG, configuration file is %s' % path)
31+
config_directory = os.getenv('XDG_CONFIG_HOME')
32+
if not config_directory:
33+
config_directory = os.path.join(os.path.expanduser('~'),
34+
u'.config')
35+
path = os.path.join(config_directory, u'whipper/whipper.conf')
36+
self.info('Configuration file path: %s' % path)
3937
return path
4038

41-
4239
def getCache(self, name=None):
43-
try:
44-
from xdg import BaseDirectory
45-
path = BaseDirectory.save_cache_path('morituri')
46-
self.info('Using XDG, cache directory is %s' % path)
47-
except (ImportError, AttributeError):
48-
# save_cache_path was added in pyxdg 0.25
49-
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
40+
cache_directory = os.getenv('XDG_CACHE_HOME')
41+
if not cache_directory:
42+
cache_directory = os.path.join(os.path.expanduser('~'), u'.cache')
43+
path = os.path.join(cache_directory, u'whipper')
44+
self.info('Cache directory path: %s' % path)
45+
if not os.path.exists(path):
46+
os.makedirs(path)
47+
if name:
48+
path = os.path.join(path, name)
5049
if not os.path.exists(path):
5150
os.makedirs(path)
52-
self.info('Not using XDG, cache directory is %s' % path)
51+
return path
5352

53+
def getData(self, name=None):
54+
data_directory = os.getenv('XDG_DATA_HOME')
55+
if not data_directory:
56+
data_directory = os.path.join(os.path.expanduser('~'),
57+
u'.local/share')
58+
path = os.path.join(data_directory, u'whipper')
59+
self.info('Data directory path: %s' % path)
60+
if not os.path.exists(path):
61+
os.makedirs(path)
5462
if name:
5563
path = os.path.join(path, name)
5664
if not os.path.exists(path):
5765
os.makedirs(path)
58-
5966
return path
6067

61-
def getReadCaches(self, name=None):
62-
paths = []
63-
64-
try:
65-
from xdg import BaseDirectory
66-
path = BaseDirectory.save_cache_path('morituri')
67-
self.info('For XDG, read cache directory is %s' % path)
68-
paths.append(path)
69-
except (ImportError, AttributeError):
70-
# save_cache_path was added in pyxdg 0.21
71-
pass
72-
73-
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
74-
if os.path.exists(path):
75-
self.info('From before XDG, read cache directory is %s' % path)
76-
paths.append(path)
77-
78-
if name:
79-
paths = [os.path.join(p, name) for p in paths]
80-
81-
return paths
82-
83-

morituri/rip/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import pkg_resources
77

8-
from morituri.common import log, logcommand, common, config
8+
from morituri.common import log, logcommand, common, config, directory
99
from morituri.configure import configure
1010

1111
from morituri.rip import cd, offset, drive, image, accurip, debug
@@ -19,8 +19,8 @@ def main(argv):
1919

2020
from morituri.configure import configure
2121
pluginsdir = configure.pluginsdir
22-
homepluginsdir = os.path.join(os.path.expanduser('~'),
23-
'.morituri', 'plugins')
22+
d = directory.Directory()
23+
homepluginsdir = d.getData('plugins')
2424

2525
distributions, errors = pkg_resources.working_set.find_plugins(
2626
pkg_resources.Environment([pluginsdir, homepluginsdir]))

morituri/test/test_common_directory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ def testAll(self):
1616

1717
path = d.getCache()
1818
self.failUnless(path.startswith('/home'))
19-
20-
paths = d.getReadCaches()
21-
self.failUnless(paths[0].startswith('/home'))

0 commit comments

Comments
 (0)