def test_run_function_per_group(self): mock_function = Mock(return_value=False) args = {} mock_iterable = [None] n = 10 self.assertFalse( run_function_per_group(mock_iterable, n, function=mock_function, arguments=args)) mock_function.assert_called() mock_function2 = Mock(return_value=True) self.assertTrue( run_function_per_group(mock_iterable, n, function=mock_function2, arguments=args)) mock_function2.assert_called() self.assertTrue( run_function_per_group(mock_iterable, n, function=mock_function, arguments=args, exit_on_fail=False)) mock_function.assert_called()
def _add_dir(self, dir_path, manifest_path, file_path='', ignore_rules=None): self.manifestfiles = yaml_load(manifest_path) f_index_file = self._full_idx.get_index() all_files = [] for root, dirs, files in os.walk(os.path.join(dir_path, file_path)): base_path = root[:len(dir_path) + 1:] relative_path = root[len(dir_path) + 1:] if '.' == root[0] or should_ignore_file( ignore_rules, '{}/'.format(relative_path)): continue for file in files: file_path = os.path.join(relative_path, file) if ignore_rules is None or not should_ignore_file( ignore_rules, file_path): all_files.append(file_path) self.wp.progress_bar_total_inc(len(all_files)) args = { 'wp': self.wp, 'base_path': base_path, 'f_index_file': f_index_file, 'all_files': all_files, 'dir_path': dir_path } result = run_function_per_group(range(len(all_files)), 10000, function=self._adding_dir_work, arguments=args) if not result: return False self._full_idx.save_manifest_index() self._mf.save()
def _add_dir(self, dirpath, manifestpath, file_path='', trust_links=True): self.manifestfiles = yaml_load(manifestpath) f_index_file = self._full_idx.get_index() all_files = [] for root, dirs, files in os.walk(os.path.join(dirpath, file_path)): if '.' == root[0]: continue basepath = root[:len(dirpath) + 1:] relativepath = root[len(dirpath) + 1:] for file in files: all_files.append(os.path.join(relativepath, file)) self.wp.progress_bar_total_inc(len(all_files)) args = { 'wp': self.wp, 'basepath': basepath, 'f_index_file': f_index_file, 'all_files': all_files, 'dirpath': dirpath } result = run_function_per_group(range(len(all_files)), 10000, function=self._adding_dir_work, arguments=args) if not result: return False self._full_idx.save_manifest_index() self._mf.save()