[SCM] morituri/master: Add path filter

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:10:05 UTC 2014


The following commit has been merged in the master branch:
commit c75f71ead328c193660108eed8176538a1f1e1a3
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sat Jul 13 18:38:31 2013 +0200

    Add path filter

diff --git a/morituri/common/Makefile.am b/morituri/common/Makefile.am
index bbda7f6..14c8c95 100644
--- a/morituri/common/Makefile.am
+++ b/morituri/common/Makefile.am
@@ -17,6 +17,7 @@ morituri_PYTHON = \
 	log.py \
 	logcommand.py \
 	mbngs.py \
+	path.py \
 	program.py \
 	renamer.py \
 	task.py
diff --git a/morituri/common/logcommand.py b/morituri/common/path.py
similarity index 55%
copy from morituri/common/logcommand.py
copy to morituri/common/path.py
index 06f8700..65fc206 100644
--- a/morituri/common/logcommand.py
+++ b/morituri/common/path.py
@@ -1,4 +1,4 @@
-# -*- Mode: Python -*-
+# -*- Mode: Python; test-case-name: morituri.test.test_common_path -*-
 # vi:si:et:sw=4:sts=4:ts=4
 
 # Morituri - for those about to RIP
@@ -20,22 +20,25 @@
 # You should have received a copy of the GNU General Public License
 # along with morituri.  If not, see <http://www.gnu.org/licenses/>.
 
-"""
-Logging Command.
-"""
+import re
 
-from morituri.extern.command import command
-from morituri.common import log
 
+class PathFilter(object):
+    """
+    I filter path components for safe storage on file systems.
+    """
 
-class LogCommand(command.Command, log.Loggable):
+    def __init__(self, slashes=True, fat=True, special=True):
+        """
+        @param slashes: whether to convert slashes to dashes
+        @parm  fat:     whether to strip characters illegal on FAT filesystems
+        """
+        self._slashes = slashes
+        self._fat = fat
+        self._special = special
 
-    def __init__(self, parentCommand=None, **kwargs):
-        command.Command.__init__(self, parentCommand, **kwargs)
-        self.logCategory = self.name
+    def filter(self, path):
+        if self._slashes:
+            path = re.sub(r'[/]', '-', path, re.UNICODE)
 
-    # command.Command has a fake debug method, so choose the right one
-
-    def debug(self, format, *args):
-        kwargs = {}
-        log.Loggable.doLog(self, log.DEBUG, -2, format, *args, **kwargs)
+        return path
diff --git a/morituri/test/Makefile.am b/morituri/test/Makefile.am
index b32aed1..792beb4 100644
--- a/morituri/test/Makefile.am
+++ b/morituri/test/Makefile.am
@@ -12,6 +12,7 @@ EXTRA_DIST = \
 	test_common_encode.py \
 	test_common_gstreamer.py \
 	test_common_mbngs.py \
+	test_common_path.py \
 	test_common_program.py \
 	test_common_renamer.py \
 	test_image_cue.py \
diff --git a/morituri/test/test_common_path.py b/morituri/test/test_common_path.py
new file mode 100644
index 0000000..45b160d
--- /dev/null
+++ b/morituri/test/test_common_path.py
@@ -0,0 +1,16 @@
+# -*- Mode: Python; test-case-name: morituri.test.test_common_path -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+from morituri.common import path
+
+from morituri.test import common
+
+
+class FilterTestCase(common.TestCase):
+
+    def setUp(self):
+        self._filter = path.PathFilter()
+
+    def testSlash(self):
+        part = u'A Charm/A Blade'
+        self.assertEquals(self._filter.filter(part), u'A Charm-A Blade')

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list