* 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!
This commit is contained in:
Thomas Vander Stichele
2012-08-12 18:03:21 +00:00
parent 1e2f8aa93f
commit 1da3c8cdfb
4 changed files with 35 additions and 3 deletions

View File

@@ -1,3 +1,12 @@
2012-08-12 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org>
* morituri/common/Makefile.am:

View File

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

View File

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

View File

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