Merge pull request #348 from whipper-team/bugfix/issue-135-plugins-from-system

Discover plugins in system directories too
This commit is contained in:
JoeLametta
2018-12-14 21:21:21 +00:00
committed by GitHub
2 changed files with 35 additions and 6 deletions

View File

@@ -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.

View File

@@ -5,9 +5,9 @@ import os
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
@@ -21,9 +21,21 @@ logger = logging.getLogger(__name__)
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: