def basic_test(self): folder1 = temp_folder() sub1 = os.path.join(folder1, "subdir1") sub2 = os.path.join(folder1, "subdir2") save(os.path.join(sub1, "file1.txt"), "Hello1") save(os.path.join(sub1, "file2.c"), "Hello2") save(os.path.join(sub1, "sub1/file1.txt"), "Hello1 sub") save(os.path.join(sub1, "sub1/file2.c"), "Hello2 sub") save(os.path.join(sub2, "file1.txt"), "2 Hello1") save(os.path.join(sub2, "file2.c"), "2 Hello2") folder2 = temp_folder() copier = FileCopier(folder1, folder2) copier("*.txt", "texts") copier.execute() self.assertEqual("Hello1", load(os.path.join(folder2, "texts/subdir1/file1.txt"))) self.assertEqual("Hello1 sub", load(os.path.join(folder2, "texts/subdir1/sub1/file1.txt"))) self.assertEqual("2 Hello1", load(os.path.join(folder2, "texts/subdir2/file1.txt"))) self.assertEqual(['file1.txt'], os.listdir(os.path.join(folder2, "texts/subdir2"))) folder2 = temp_folder() copier = FileCopier(folder1, folder2) copier("*.txt", "texts", "subdir1") copier.execute() self.assertEqual("Hello1", load(os.path.join(folder2, "texts/file1.txt"))) self.assertEqual("Hello1 sub", load(os.path.join(folder2, "texts/sub1/file1.txt"))) self.assertNotIn("subdir2", os.listdir(os.path.join(folder2, "texts")))
def basic_test(self): folder1 = temp_folder() sub1 = os.path.join(folder1, "subdir1") sub2 = os.path.join(folder1, "subdir2") save(os.path.join(sub1, "file1.txt"), "Hello1") save(os.path.join(sub1, "file2.c"), "Hello2") save(os.path.join(sub1, "sub1/file1.txt"), "Hello1 sub") save(os.path.join(sub1, "sub1/file2.c"), "Hello2 sub") save(os.path.join(sub2, "file1.txt"), "2 Hello1") save(os.path.join(sub2, "file2.c"), "2 Hello2") folder2 = temp_folder() copier = FileCopier(folder1, folder2) copier("*.txt", "texts") copier.execute() self.assertEqual( "Hello1", load(os.path.join(folder2, "texts/subdir1/file1.txt"))) self.assertEqual( "Hello1 sub", load(os.path.join(folder2, "texts/subdir1/sub1/file1.txt"))) self.assertEqual( "2 Hello1", load(os.path.join(folder2, "texts/subdir2/file1.txt"))) self.assertEqual(['file1.txt'], os.listdir(os.path.join(folder2, "texts/subdir2"))) folder2 = temp_folder() copier = FileCopier(folder1, folder2) copier("*.txt", "texts", "subdir1") copier.execute() self.assertEqual("Hello1", load(os.path.join(folder2, "texts/file1.txt"))) self.assertEqual("Hello1 sub", load(os.path.join(folder2, "texts/sub1/file1.txt"))) self.assertNotIn("subdir2", os.listdir(os.path.join(folder2, "texts")))
def execute(self): """ Execute the stored requested copies, using a FileCopier as helper """ root_src_folder = self._paths.store file_copier = FileCopier(root_src_folder, self._dst_folder) for pattern, dst_folder, src_folder, conan_name_pattern in self._copies: real_dst_folder = os.path.normpath(os.path.join(self._dst_folder, dst_folder)) matching_paths = self._get_paths(conan_name_pattern) for matching_path in matching_paths: real_src_folder = os.path.join(matching_path, src_folder) file_copier(pattern, real_dst_folder, real_src_folder) file_copier.execute()
def _export(file_patterns, origin_folder, destination_folder): file_patterns = file_patterns or [] try: os.unlink(os.path.join(origin_folder, CONANFILE + 'c')) except: pass copier = FileCopier(origin_folder, destination_folder) for pattern in file_patterns: copier(pattern) copier.execute() shutil.copy2(os.path.join(origin_folder, CONANFILE), destination_folder)
def execute(self): """ Execute the stored requested copies, using a FileCopier as helper """ root_src_folder = self._paths.store file_copier = FileCopier(root_src_folder, self._dst_folder) for pattern, dst_folder, src_folder, conan_name_pattern in self._copies: real_dst_folder = os.path.normpath( os.path.join(self._dst_folder, dst_folder)) matching_paths = self._get_paths(conan_name_pattern) for matching_path in matching_paths: real_src_folder = os.path.join(matching_path, src_folder) file_copier(pattern, real_dst_folder, real_src_folder) file_copier.execute()
def _export(file_patterns, origin_folder, destination_folder): file_patterns = file_patterns or [] try: os.unlink(os.path.join(origin_folder, CONANFILE + 'c')) except: pass copier = FileCopier(origin_folder, destination_folder) for pattern in file_patterns: copier(pattern) copier.execute() shutil.copy2(os.path.join(origin_folder, CONANFILE), destination_folder)