Improved format listing and added a test case for this command.

This commit is contained in:
Bastian Kleineidam 2010-03-01 16:17:14 +01:00
parent f7e3fded29
commit 3982c133be
3 changed files with 31 additions and 2 deletions

View File

@ -238,8 +238,8 @@ def list_formats ():
print print
except util.PatoolError: except util.PatoolError:
handlers = programs.get(None, programs.get(command)) handlers = programs.get(None, programs.get(command))
print " %8s: - (no program found; install one of %s)" % \ print " %8s: - (no program found; install %s)" % \
(command, ", ".join(handlers)) (command, util.strlist_with_or(handlers))
return 0 return 0

View File

@ -120,3 +120,10 @@ def find_program (program):
# XXX memoize result of this function # XXX memoize result of this function
path = os.environ['PATH'] path = os.environ['PATH']
return find_executable(program, path=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)

22
tests/test_formats.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
import unittest
import patoolib
class TestFormats (unittest.TestCase):
def test_list_formats (self):
patoolib.list_formats()