Ejemplo n.º 1
0
 def test_correct(self):
     self.assertEqual(util.replace_win32_incompat("c:\\test\\te\"st/2"),
                          "c:\\test\\te_st/2")
     self.assertEqual(util.replace_win32_incompat("c:\\test\\d:/2"),
                          "c:\\test\\d_/2")
     self.assertEqual(util.replace_win32_incompat("A\"*:<>?|b"),
                          "A_______b")
Ejemplo n.º 2
0
Archivo: file.py Proyecto: Freso/picard
 def _script_to_filename(self, format, file_metadata, settings=None):
     if settings is None:
         settings = config.setting
     metadata = Metadata()
     if config.setting["clear_existing_tags"]:
         metadata.copy(file_metadata)
     else:
         metadata.copy(self.orig_metadata)
         metadata.update(file_metadata)
     # make sure every metadata can safely be used in a path name
     for name in metadata.keys():
         if isinstance(metadata[name], basestring):
             metadata[name] = sanitize_filename(metadata[name])
     format = format.replace("\t", "").replace("\n", "")
     filename = ScriptParser().eval(format, metadata, self)
     if settings["ascii_filenames"]:
         if isinstance(filename, unicode):
             filename = unaccent(filename)
         filename = replace_non_ascii(filename)
     # replace incompatible characters
     if settings["windows_compatibility"] or sys.platform == "win32":
         filename = replace_win32_incompat(filename)
     # remove null characters
     filename = filename.replace("\x00", "")
     return filename
Ejemplo n.º 3
0
 def _make_image_filename(self, filename, dirname, metadata):
     if config.setting["ascii_filenames"]:
         if isinstance(filename, unicode):
             filename = unaccent(filename)
         filename = replace_non_ascii(filename)
     if not filename:
         filename = "cover"
     if not os.path.isabs(filename):
         filename = os.path.join(dirname, filename)
     # replace incompatible characters
     if config.setting["windows_compatibility"] or sys.platform == "win32":
         filename = replace_win32_incompat(filename)
     # remove null characters
     filename = filename.replace("\x00", "")
     return encode_filename(filename)
Ejemplo n.º 4
0
def script_to_filename(naming_format, metadata, file=None, settings=None):
    if settings is None:
        settings = config.setting
    # make sure every metadata can safely be used in a path name
    for name in metadata:
        values = [sanitize_filename(str(v)) for v in metadata.getall(name)]
        metadata.set(name, values)
    naming_format = naming_format.replace("\t", "").replace("\n", "")
    filename = ScriptParser().eval(naming_format, metadata, file)
    if settings["ascii_filenames"]:
        filename = replace_non_ascii(filename, pathsave=True)
    # replace incompatible characters
    if settings["windows_compatibility"] or sys.platform == "win32":
        filename = replace_win32_incompat(filename)
    # remove null characters
    filename = filename.replace("\x00", "")
    return filename
Ejemplo n.º 5
0
 def _script_to_filename(self, format, file_metadata, settings):
     metadata = Metadata()
     metadata.copy(file_metadata)
     # make sure every metadata can safely be used in a path name
     for name in metadata.keys():
         if isinstance(metadata[name], basestring):
             metadata[name] = sanitize_filename(metadata[name])
     format = format.replace("\t", "").replace("\n", "")
     filename = ScriptParser().eval(format, metadata, self)
     # replace incompatible characters
     if settings["windows_compatible_filenames"] or sys.platform == "win32":
         filename = replace_win32_incompat(filename)
     if settings["ascii_filenames"]:
         if isinstance(filename, unicode):
             filename = unaccent(filename)
         filename = replace_non_ascii(filename)
     return filename
Ejemplo n.º 6
0
 def test_incorrect(self):
     self.assertNotEqual(util.replace_win32_incompat("c:\\test\\te\"st2"),
                          "c:\\test\\te\"st2")
Ejemplo n.º 7
0
 def test_incorrect(self):
     self.assertNotEqual(util.replace_win32_incompat('c:\\test\\te"st2'), 'c:\\test\\te"st2')
Ejemplo n.º 8
0
 def test_incorrect(self):
     self.assertNotEqual(util.replace_win32_incompat("c:\\test\\te\"st2"),
                          "c:\\test\\te\"st2")
Ejemplo n.º 9
0
 def test_correct(self):
     self.assertEqual(util.replace_win32_incompat('c:\\test\\te"st/2'), "c_\\test\\te_st/2")
     self.assertEqual(util.replace_win32_incompat('A"*:<>?|b'), "A_______b")
Ejemplo n.º 10
0
 def test_correct_absolute_non_win32(self):
     self.assertEqual(util.replace_win32_incompat("/test/te\"st/2"),
                          "/test/te_st/2")
     self.assertEqual(util.replace_win32_incompat("/test/d:/2"),
                          "/test/d_/2")
Ejemplo n.º 11
0
 def test_correct_relative(self):
     self.assertEqual(util.replace_win32_incompat("A\"*:<>?|b"),
                          "A_______b")
     self.assertEqual(util.replace_win32_incompat("d:tes<t"),
                          "d_tes_t")
Ejemplo n.º 12
0
 def test_correct_absolute_win32(self):
     self.assertEqual(util.replace_win32_incompat("c:\\test\\te\"st/2"),
                          "c:\\test\\te_st/2")
     self.assertEqual(util.replace_win32_incompat("c:\\test\\d:/2"),
                          "c:\\test\\d_/2")
Ejemplo n.º 13
0
 def test_incorrect(self):
     self.failIfEqual(util.replace_win32_incompat("c:\\test\\te\"st2"),
                      "c:\\test\\te\"st2")
Ejemplo n.º 14
0
 def test_correct(self):
     self.failUnlessEqual(util.replace_win32_incompat("c:\\test\\te\"st/2"),
                          "c_\\test\\te_st/2")
     self.failUnlessEqual(util.replace_win32_incompat("A\"*:<>?|b"),
                          "A_______b")
Ejemplo n.º 15
0
 def test_incorrect(self):
     self.failIfEqual(util.replace_win32_incompat("c:\\test\\te\"st2"),
                          "c:\\test\\te\"st2")
Ejemplo n.º 16
0
 def test_correct(self):
     self.failUnlessEqual(util.replace_win32_incompat("c:\\test\\te\"st/2"),
                          "c_\\test\\te_st/2")
     self.failUnlessEqual(util.replace_win32_incompat("A\"*:<>?|b"),
                          "A_______b")