def rename_dir(self, prev_dir_name, new_dir_name): for file_name in self.parser.sections(): if is_subdirectory(dirname(join(self._base_dir, file_name)), prev_dir_name): k, m = self._get_split_info(file_name) chunks = self._get_chunks(file_name) state = self._get_state(file_name) new_file_path = join(new_dir_name, basename(file_name)) self.add_file(new_file_path, k, m, state) self.update_chunks_for_file(new_file_path, chunks) self._remove_file(file_name)
def decorated(*args, **kwargs): base_dir = args[0].base_dir file_path = args[1] if not is_subdirectory(dirname(file_path), base_dir): raise NotInBaseDirException return func(*args, **kwargs)
def get_files_in_dir(self, dir_name): return [file_path for file_path in self.parser.sections() if is_subdirectory(dirname(join(self._base_dir, file_path)), dir_name)]
def remove_dir(self, dir_name): for file_name in self.parser.sections(): if is_subdirectory(dirname(join(self._base_dir, file_name)), dir_name): self._remove_file(file_name)
def get_files_in_dir(self, dir_name): return [ file_path for file_path in self.parser.sections() if is_subdirectory( dirname(join(self._base_dir, file_path)), dir_name) ]
def test_is_subdirectory(self): self.assertFalse(is_subdirectory('/var/test2', '/var/test')) self.assertFalse(is_subdirectory('/var/test', '/var/test2')) self.assertFalse(is_subdirectory('var/test2', 'var/test')) self.assertFalse(is_subdirectory('var/test', 'var/test2')) self.assertTrue(is_subdirectory('/var/test/sub', '/var/test')) self.assertFalse(is_subdirectory('/var/test', '/var/test/sub')) self.assertTrue(is_subdirectory('var/test/sub', 'var/test')) self.assertTrue(is_subdirectory('var/test', 'var/test')) self.assertTrue(is_subdirectory('var/test', 'var/test/fake_sub/..')) self.assertTrue(is_subdirectory('var/test/sub/sub2/sub3/../..', 'var/test')) self.assertTrue(is_subdirectory('var/test/sub', 'var/test/fake_sub/..')) self.assertFalse(is_subdirectory('var/test', 'var/test/sub'))