Skip to content

Commit

Permalink
Merge pull request #348 from whipper-team/bugfix/issue-135-plugins-fr…
Browse files Browse the repository at this point in the history
…om-system

Discover plugins in system directories too
  • Loading branch information
JoeLametta committed Dec 14, 2018
2 parents c803a59 + 3a56948 commit 951082d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,31 @@ python2 -m whipper -h

## Logger plugins

Whipper supports using external logger plugins to write rip `.log` files.
Whipper allows using external logger plugins to customize the template of `.log` files.

List available plugins with `whipper cd rip -h`. Specify a logger to rip with by passing `-L loggername`:
The available plugins can be listed with `whipper cd rip -h`. Specify a logger to rip with by passing `-L loggername`:

```bash
whipper cd rip -L what
whipper cd rip -L eac
```

Whipper searches for logger plugins in the following paths:

- `$XDG_DATA_HOME/whipper/plugins`
- Paths returned by the following Python instruction:

`[x + '/whipper/plugins' for x in site.getsitepackages()]`

- If whipper is run in a `virtualenv`, it will use these alternative instructions (from `distutils.sysconfig`):
- `get_python_lib(plat_specific=False, standard_lib=False, prefix='/usr/local') + '/whipper/plugins'`
- `get_python_lib(plat_specific=False, standard_lib=False) + '/whipper/plugins'`

On a default Debian/Ubuntu installation, the following paths are searched by whipper:

- `$HOME/.local/share/whipper/plugins`
- `/usr/local/lib/python2.7/dist-packages/whipper/plugins`
- `/usr/lib/python2.7/dist-packages/whipper/plugins`

### Official logger plugins

I suggest using whipper's default logger unless you've got particular requirements.
Expand Down
18 changes: 15 additions & 3 deletions whipper/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import sys
import pkg_resources
import musicbrainzngs

import site
import whipper

from distutils.sysconfig import get_python_lib
from whipper.command import cd, offset, drive, image, accurip, mblookup
from whipper.command.basecommand import BaseCommand
from whipper.common import common, directory, config
Expand All @@ -21,9 +21,21 @@
def main():
server = config.Config().get_musicbrainz_server()
musicbrainzngs.set_hostname(server)

# Find whipper's plugins paths (local paths have higher priority)
plugins_p = [directory.data_path('plugins')] # local path (in $HOME)
if hasattr(sys, 'real_prefix'): # no getsitepackages() in virtualenv
plugins_p.append(
get_python_lib(plat_specific=False, standard_lib=False,
prefix='/usr/local') + '/whipper/plugins')
plugins_p.append(get_python_lib(plat_specific=False,
standard_lib=False) + '/whipper/plugins')
else:
plugins_p += [x + '/whipper/plugins' for x in site.getsitepackages()]

# register plugins with pkg_resources
distributions, _ = pkg_resources.working_set.find_plugins(
pkg_resources.Environment([directory.data_path('plugins')])
pkg_resources.Environment(plugins_p)
)
list(map(pkg_resources.working_set.add, distributions))
try:
Expand Down

0 comments on commit 951082d

Please sign in to comment.