コード例 #1
0
ファイル: test_util.py プロジェクト: Muges/quodlibet
 def test_basic(self):
     if is_win:
         v = strip_win32_incompat_from_path(u"C:\\foo\\<>/a")
         self.assertEqual(v, u"C:\\foo\\___a")
     else:
         v = strip_win32_incompat_from_path("/foo/<>a")
         self.assertEqual(v, "/foo/__a")
コード例 #2
0
ファイル: test_util.py プロジェクト: ptitjes/quodlibet
 def test_basic(self):
     if is_win:
         v = strip_win32_incompat_from_path(u"C:\\foo\\<>/a")
         self.assertEqual(v, u"C:\\foo\\___a")
     else:
         v = strip_win32_incompat_from_path("/foo/<>a")
         self.assertEqual(v, "/foo/__a")
コード例 #3
0
ファイル: test_util.py プロジェクト: ptitjes/quodlibet
    def test_types(self):
        v = strip_win32_incompat_from_path(fsnative(u""))
        self.assertTrue(isinstance(v, fsnative))
        v = strip_win32_incompat_from_path(fsnative(u"foo"))
        self.assertTrue(isinstance(v, fsnative))

        v = strip_win32_incompat_from_path(u"")
        self.assertTrue(isinstance(v, str))
        v = strip_win32_incompat_from_path(u"foo")
        self.assertTrue(isinstance(v, str))
コード例 #4
0
    def test_types(self):
        v = strip_win32_incompat_from_path("")
        self.assertTrue(isinstance(v, bytes))
        v = strip_win32_incompat_from_path("foo")
        self.assertTrue(isinstance(v, bytes))

        v = strip_win32_incompat_from_path(u"")
        self.assertTrue(isinstance(v, unicode))
        v = strip_win32_incompat_from_path(u"foo")
        self.assertTrue(isinstance(v, unicode))
コード例 #5
0
ファイル: test_util.py プロジェクト: bernd-wechner/quodlibet
    def test_types(self):
        v = strip_win32_incompat_from_path("")
        self.assertTrue(isinstance(v, bytes))
        v = strip_win32_incompat_from_path("foo")
        self.assertTrue(isinstance(v, bytes))

        v = strip_win32_incompat_from_path(u"")
        self.assertTrue(isinstance(v, unicode))
        v = strip_win32_incompat_from_path(u"foo")
        self.assertTrue(isinstance(v, unicode))
コード例 #6
0
ファイル: test_util.py プロジェクト: Muges/quodlibet
    def test_types(self):
        v = strip_win32_incompat_from_path(fsnative(u""))
        self.assertTrue(isinstance(v, fsnative))
        v = strip_win32_incompat_from_path(fsnative(u"foo"))
        self.assertTrue(isinstance(v, fsnative))

        v = strip_win32_incompat_from_path(u"")
        self.assertTrue(isinstance(v, text_type))
        v = strip_win32_incompat_from_path(u"foo")
        self.assertTrue(isinstance(v, text_type))
コード例 #7
0
ファイル: _pattern.py プロジェクト: thisfred/quodlibet
    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind("."):].lower()
                val_ext = value[-len(ext):].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)

            # Limit each path section to 255 (bytes on linux, chars on win).
            # http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
            path, ext = os.path.splitext(value)
            path = path.split(sep)
            limit = [255] * len(path)
            limit[-1] -= len(ext)
            elip = lambda (p, l): (len(p) > l and p[:l - 2] + "..") or p
            path = sep.join(map(elip, zip(path, limit)))
            value = path + ext

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
コード例 #8
0
ファイル: _pattern.py プロジェクト: kriskielce88/xn--ls8h
    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind("."):].lower()
                val_ext = value[-len(ext):].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)

            # Limit each path section to 255 (bytes on linux, chars on win).
            # http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
            path, ext = os.path.splitext(value)
            path = path.split(sep)
            limit = [255] * len(path)
            limit[-1] -= len(ext)
            elip = lambda (p, l): (len(p) > l and p[:l - 2] + "..") or p
            path = sep.join(map(elip, zip(path, limit)))
            value = path + ext

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
コード例 #9
0
    def _make_safe_name(self, input_path):
        """
        Make a file path safe by replacing unsafe characters.

        :param input_path: A relative Path.
        :return: The given path, with any unsafe characters replaced.
                 Returned as a string.
        """
        # Remove diacritics (accents)
        safe_filename = unicodedata.normalize('NFKD', str(input_path))
        safe_filename = u''.join(
            [c for c in safe_filename if not unicodedata.combining(c)])

        if os.name != "nt":
            # Ensure that Win32-incompatible chars are always removed.
            # On Windows, this is called during `FileFromPattern`.
            safe_filename = strip_win32_incompat_from_path(safe_filename)

        return safe_filename
コード例 #10
0
ファイル: _pattern.py プロジェクト: mistotebe/quodlibet
    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind("."):].lower()
                val_ext = value[-len(ext):].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)
            value = limit_path(value)

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
コード例 #11
0
ファイル: _pattern.py プロジェクト: MikeiLL/quodlibet
    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind(".") :].lower()
                val_ext = value[-len(ext) :].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)
            value = limit_path(value)

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
コード例 #12
0
    def copy(self, parent_widget, song):
        if not self.__pattern:
            self.__set_pattern()

        target = strip_win32_incompat_from_path(self.__pattern.format(song))
        dirname = os.path.dirname(target)

        if os.path.exists(target):
            dialog = ConfirmFileReplace(parent_widget, target)
            resp = dialog.run()
            if resp == ConfirmFileReplace.RESPONSE_REPLACE:
                try:
                    # Remove the current song
                    self.__library.remove([self.__library[target]])
                except KeyError:
                    pass
            else:
                return False

        try:
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            shutil.copyfile(song['~filename'], target)

            if self['covers']:
                coverfile = os.path.join(dirname, 'folder.jpg')
                cover = app.cover_manager.get_cover(song)
                if cover and mtime(cover.name) > mtime(coverfile):
                    image = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        cover.name, 200, 200)
                    image.savev(coverfile, "jpeg", [], [])

            song = copy.deepcopy(song)
            song.sanitize(target)
            self.__library.add([song])
            return song
        except (OSError, IOError, GLib.GError) as exc:
            encoding = util.get_locale_encoding()
            return str(exc).decode(encoding, 'replace')
コード例 #13
0
ファイル: storage.py プロジェクト: Konzertheld/quodlibet
    def copy(self, parent_widget, song):
        if not self.__pattern:
            self.__set_pattern()

        target = strip_win32_incompat_from_path(self.__pattern.format(song))
        dirname = os.path.dirname(target)

        if os.path.exists(target):
            dialog = ConfirmFileReplace(parent_widget, target)
            resp = dialog.run()
            if resp == ConfirmFileReplace.RESPONSE_REPLACE:
                try:
                    # Remove the current song
                    self.__library.remove([self.__library[target]])
                except KeyError:
                    pass
            else:
                return False

        try:
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            shutil.copyfile(song['~filename'], target)

            if self['covers']:
                coverfile = os.path.join(dirname, 'folder.jpg')
                cover = app.cover_manager.get_cover(song)
                if cover and mtime(cover.name) > mtime(coverfile):
                    image = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        cover.name, 200, 200)
                    image.savev(coverfile, "jpeg", [], [])

            song = copy.deepcopy(song)
            song.sanitize(target)
            self.__library.add([song])
            return song
        except (OSError, IOError, GLib.GError) as exc:
            encoding = util.get_locale_encoding()
            return str(exc).decode(encoding, 'replace')
コード例 #14
0
ファイル: renamefiles.py プロジェクト: mistotebe/quodlibet
 def filter(self, original, filename):
     return strip_win32_incompat_from_path(filename)
コード例 #15
0
ファイル: renamefiles.py プロジェクト: yaoml/quodlibet
 def filter(self, original, filename):
     return strip_win32_incompat_from_path(filename)
コード例 #16
0
 def filter(self, original, filename):
     assert isinstance(filename, unicode)
     return fsdecode(strip_win32_incompat_from_path(fsencode(filename)))