Beispiel #1
0
 def _move_or_rename_wvc(self, old_filename, new_filename):
     wvc_filename = replace_extension(old_filename, ".wvc")
     if not isfile(wvc_filename):
         return
     wvc_new_filename = replace_extension(new_filename, ".wvc")
     wvc_new_filename = get_available_filename(wvc_new_filename, wvc_filename)
     log.debug('Moving Wavepack correction file %r => %r', wvc_filename, wvc_new_filename)
     move_ensure_casing(wvc_filename, wvc_new_filename)
Beispiel #2
0
 def test_reuse_existing_number(self):
     with TemporaryDirectory() as d:
         expected_number = 2
         filename = os.path.join(d, 'foo.mp3')
         open(filename, 'a').close()
         for i in range(1, 3):
             open(self._add_number(filename, i), 'a').close()
         oldname = self._add_number(filename, expected_number)
         new_filename = get_available_filename(filename, oldname)
         self.assertEqual(self._add_number(filename, expected_number), new_filename)
Beispiel #3
0
 def test_append_additional_numbers(self):
     with TemporaryDirectory() as d:
         expected_number = 3
         oldname = os.path.join(d, 'bar.mp3')
         open(oldname, 'a').close()
         filename = os.path.join(d, 'foo.mp3')
         open(filename, 'a').close()
         for i in range(1, expected_number):
             open(self._add_number(filename, i), 'a').close()
         new_filename = get_available_filename(filename, oldname)
         self.assertEqual(self._add_number(filename, expected_number), new_filename)
Beispiel #4
0
    def _rename(self, old_filename, metadata, settings=None):
        new_filename = self.make_filename(old_filename, metadata, settings)
        if old_filename == new_filename:
            return old_filename

        new_dirname = os.path.dirname(new_filename)
        if not os.path.isdir(new_dirname):
            os.makedirs(new_dirname)
        new_filename = get_available_filename(new_filename, old_filename)
        log.debug("Moving file %r => %r", old_filename, new_filename)
        move_ensure_casing(old_filename, new_filename)
        return new_filename
Beispiel #5
0
 def test_handle_non_existant_old_path(self):
     with NamedTemporaryFile(prefix='foo', suffix='.mp3') as f:
         new_filename = get_available_filename(f.name, '/foo/old.mp3')
         self.assertEqual(self._add_number(f.name, 1), new_filename)
Beispiel #6
0
 def test_do_not_append_number_on_same_file(self):
     with NamedTemporaryFile(prefix='foo', suffix='.mp3') as f:
         new_filename = get_available_filename(f.name, f.name)
         self.assertEqual(f.name, new_filename)
Beispiel #7
0
 def test_append_number(self):
     with NamedTemporaryFile(prefix='foo', suffix='.mp3') as f:
         new_filename = get_available_filename(f.name)
         self.assertEqual(self._add_number(f.name, 1), new_filename)