[SCM] morituri/master: * 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!

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:39 UTC 2014


The following commit has been merged in the master branch:
commit 1da3c8cdfb8d2ce1d329f6a0b3e1e489fcdd78d5
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sun Aug 12 18:03:21 2012 +0000

    	* 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!

diff --git a/ChangeLog b/ChangeLog
index d71371f..e273258 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 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:
 	* morituri/common/checksum.py:
 	* morituri/common/encode.py:
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)
+

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list