From 1da3c8cdfb8d2ce1d329f6a0b3e1e489fcdd78d5 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 12 Aug 2012 18:03:21 +0000 Subject: [PATCH] * morituri/common/drive.py: If cdio.get_devices_with_cap finds a single drive, it returns a str instead of a list. Work around that bug. Fixes #102. * morituri/test/test_common_drive.py (added): * morituri/test/Makefile.am: Add test for it. Caught a bug in my first implementation, too! --- ChangeLog | 9 +++++++++ morituri/common/drive.py | 12 +++++++++--- morituri/test/Makefile.am | 1 + morituri/test/test_common_drive.py | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 morituri/test/test_common_drive.py diff --git a/ChangeLog b/ChangeLog index d71371f..e273258 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-08-12 Thomas Vander Stichele + + * morituri/common/drive.py: + If cdio.get_devices_with_cap finds a single drive, it returns a + str instead of a list. Work around that bug. Fixes #102. + * morituri/test/test_common_drive.py (added): + * morituri/test/Makefile.am: + Add test for it. Caught a bug in my first implementation, too! + 2012-08-12 Thomas Vander Stichele * morituri/common/Makefile.am: diff --git a/morituri/common/drive.py b/morituri/common/drive.py index 55ec837..0ae3ab7 100644 --- a/morituri/common/drive.py +++ b/morituri/common/drive.py @@ -24,20 +24,27 @@ import os from morituri.common import log +def _listify(listOrString): + if type(listOrString) == str: + return [listOrString, ] + + return listOrString + def getAllDevicePaths(): try: return _getAllDevicePathsPyCdio() except ImportError: log.info('drive', 'Cannot import pycdio') return _getAllDevicePathsStatic() - + def _getAllDevicePathsPyCdio(): import pycdio import cdio # using FS_AUDIO here only makes it list the drive when an audio cd # is inserted - return cdio.get_devices_with_cap(pycdio.FS_MATCH_ALL, False) + # ticket 102: this cdio call returns a list of str, or a single str + return _listify(cdio.get_devices_with_cap(pycdio.FS_MATCH_ALL, False)) def _getAllDevicePathsStatic(): ret = [] @@ -47,4 +54,3 @@ def _getAllDevicePathsStatic(): ret.append(c) return ret - diff --git a/morituri/test/Makefile.am b/morituri/test/Makefile.am index 8c6f673..b12725d 100644 --- a/morituri/test/Makefile.am +++ b/morituri/test/Makefile.am @@ -5,6 +5,7 @@ EXTRA_DIST = \ common.py \ test_common_accurip.py \ test_common_checksum.py \ + test_common_drive.py \ test_common_musicbrainzngs.py \ test_common_program.py \ test_common_renamer.py \ diff --git a/morituri/test/test_common_drive.py b/morituri/test/test_common_drive.py new file mode 100644 index 0000000..cecbbcb --- /dev/null +++ b/morituri/test/test_common_drive.py @@ -0,0 +1,16 @@ +# -*- Mode: Python; test-case-name: morituri.test.test_common_drive -*- +# vi:si:et:sw=4:sts=4:ts=4 + +from morituri.test import common +from morituri.common import drive + +class ListifyTestCase(common.TestCase): + + def testString(self): + string = '/dev/sr0' + self.assertEquals(drive._listify(string), [string, ]) + + def testList(self): + lst = ['/dev/scd0', '/dev/sr0'] + self.assertEquals(drive._listify(lst), lst) +