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/path.py b/morituri/common/path.py new file mode 100644 index 0000000..65fc206 --- /dev/null +++ b/morituri/common/path.py @@ -0,0 +1,44 @@ +# -*- 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 + +# Copyright (C) 2009 Thomas Vander Stichele + +# This file is part of morituri. +# +# morituri 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. +# +# morituri 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 morituri. If not, see . + +import re + + +class PathFilter(object): + """ + I filter path components for safe storage on file systems. + """ + + 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 filter(self, path): + if self._slashes: + path = re.sub(r'[/]', '-', path, re.UNICODE) + + 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')