diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 6acd893..b4c926d 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -238,8 +238,8 @@ def list_formats (): print except util.PatoolError: handlers = programs.get(None, programs.get(command)) - print " %8s: - (no program found; install one of %s)" % \ - (command, ", ".join(handlers)) + print " %8s: - (no program found; install %s)" % \ + (command, util.strlist_with_or(handlers)) return 0 diff --git a/patoolib/util.py b/patoolib/util.py index e6a7f61..6803c8e 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -120,3 +120,10 @@ def find_program (program): # XXX memoize result of this function path = os.environ['PATH'] return find_executable(program, path=path) + + +def strlist_with_or (list): + """Return comma separated string, and last entry appended with ' or '.""" + if len(list) > 1: + return "%s or %s" % (", ".join(list[:-1]), list[-1]) + return ", ".join(list) diff --git a/tests/test_formats.py b/tests/test_formats.py new file mode 100644 index 0000000..52326d1 --- /dev/null +++ b/tests/test_formats.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Bastian Kleineidam +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import unittest +import patoolib + +class TestFormats (unittest.TestCase): + + def test_list_formats (self): + patoolib.list_formats()