From 46df8c4f0dfe6f34f0fff8a143d754d2f2d08f76 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 16 Sep 2013 16:37:55 -0700 Subject: [PATCH] info: eager error detection (closes #371) --- beetsplug/info.py | 14 ++++++++++++-- docs/changelog.rst | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/beetsplug/info.py b/beetsplug/info.py index 53c33c4c7..8dd4ccaa6 100644 --- a/beetsplug/info.py +++ b/beetsplug/info.py @@ -15,12 +15,15 @@ """Shows file metadata. """ +import os + from beets.plugins import BeetsPlugin from beets import library from beets import ui from beets import mediafile from beets import util + def info(paths): # Set up fields to output. fields = [] @@ -39,11 +42,18 @@ def info(paths): ui.print_() path = util.normpath(path) + if not os.path.isfile(path): + ui.print_(u'not a file: {0}'.format( + util.displayable_path(path) + )) + continue ui.print_(path) try: mf = mediafile.MediaFile(path) except mediafile.UnreadableFileError: - ui.print_('cannot read file') + ui.print_('cannot read file: {0}'.format( + util.displayable_path(path) + )) continue # Basic fields. @@ -52,9 +62,9 @@ def info(paths): # Extra stuff. ui.print_(lineformat.format('album art', mf.art is not None)) - first = False + class InfoPlugin(BeetsPlugin): def commands(self): cmd = ui.Subcommand('info', help='show file metadata') diff --git a/docs/changelog.rst b/docs/changelog.rst index 0c30c4589..6c83f2f57 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,8 @@ And some fixes: unrecognized type. * :doc:`/plugins/mbcollection`: Detect, log, and skip invalid MusicBrainz IDs (instead of failing with an API error). +* :doc:`/plugins/info`: Fail gracefully when used erroneously with a + directory. .. _Opus: http://www.opus-codec.org/