feat: feedback verbetering 01
This commit is contained in:
@@ -298,26 +298,22 @@ class TaskRunner:
|
||||
self._update_history_failed(task_id, str(exc))
|
||||
|
||||
def _run_move_directory(self, task_id: str, item: dict[str, object]) -> None:
|
||||
files = self._file_entries(item)
|
||||
directories = self._directory_entries(item)
|
||||
total_items = len(files)
|
||||
total_items = int(item.get("progress_total_items", 1))
|
||||
source_path = self._item_source_path(item)
|
||||
destination_path = self._item_destination_path(item)
|
||||
current_item = str(item.get("progress_label") or Path(source_path).name)
|
||||
if not self._repository.mark_running(
|
||||
task_id=task_id,
|
||||
done_items=0,
|
||||
total_items=total_items,
|
||||
current_item=files[0]["label"] if files else None,
|
||||
current_item=current_item,
|
||||
):
|
||||
self._finalize_if_already_cancelled(task_id, done_items=0, total_items=total_items)
|
||||
return
|
||||
|
||||
try:
|
||||
completed_items = self._move_directory_files(
|
||||
directories,
|
||||
files,
|
||||
task_id=task_id,
|
||||
completed_items=0,
|
||||
total_items=total_items,
|
||||
)
|
||||
self._filesystem.move_directory(source=source_path, destination=destination_path)
|
||||
completed_items = total_items
|
||||
if self._is_cancel_requested(task_id):
|
||||
self._finalize_cancelled(task_id, done_items=completed_items, total_items=total_items)
|
||||
return
|
||||
@@ -338,8 +334,8 @@ class TaskRunner:
|
||||
self._update_history_failed(task_id, str(exc))
|
||||
|
||||
def _run_move_batch(self, task_id: str, items: list[dict[str, str]]) -> None:
|
||||
total_items = self._total_file_count(items)
|
||||
current_item = self._first_file_label(items)
|
||||
total_items = self._total_move_work_count(items)
|
||||
current_item = self._first_move_item_label(items)
|
||||
if not self._repository.mark_running(
|
||||
task_id=task_id,
|
||||
done_items=0,
|
||||
@@ -501,6 +497,40 @@ class TaskRunner:
|
||||
return 0
|
||||
return int(task["done_items"])
|
||||
|
||||
@staticmethod
|
||||
def _item_source_path(item: dict[str, object]) -> str:
|
||||
value = item.get("source")
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
return str(item["source_absolute"])
|
||||
|
||||
@staticmethod
|
||||
def _item_destination_path(item: dict[str, object]) -> str:
|
||||
value = item.get("destination")
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
return str(item["destination_absolute"])
|
||||
|
||||
def _total_move_work_count(self, items: list[dict[str, object]]) -> int:
|
||||
total = 0
|
||||
for item in items:
|
||||
progress_total_items = item.get("progress_total_items")
|
||||
if progress_total_items is not None:
|
||||
total += int(progress_total_items)
|
||||
continue
|
||||
total += len(self._file_entries(item))
|
||||
return total
|
||||
|
||||
def _first_move_item_label(self, items: list[dict[str, object]]) -> str | None:
|
||||
for item in items:
|
||||
progress_label = item.get("progress_label")
|
||||
if isinstance(progress_label, str) and progress_label:
|
||||
return progress_label
|
||||
files = self._file_entries(item)
|
||||
if files:
|
||||
return files[0]["label"]
|
||||
return None
|
||||
|
||||
def _copy_single_planned_file(
|
||||
self,
|
||||
task_id: str,
|
||||
@@ -607,44 +637,24 @@ class TaskRunner:
|
||||
completed_items: int,
|
||||
total_items: int,
|
||||
) -> int:
|
||||
return self._move_directory_files(self._directory_entries(item), self._file_entries(item), task_id=task_id, completed_items=completed_items, total_items=total_items)
|
||||
|
||||
def _move_directory_files(
|
||||
self,
|
||||
directories: list[dict[str, str]],
|
||||
files: list[dict[str, str]],
|
||||
*,
|
||||
task_id: str | None = None,
|
||||
completed_items: int = 0,
|
||||
total_items: int = 0,
|
||||
) -> int:
|
||||
for directory in directories:
|
||||
Path(directory["destination"]).mkdir(parents=True, exist_ok=True)
|
||||
for file_entry in files:
|
||||
if task_id is not None and self._is_cancel_requested(task_id):
|
||||
return completed_items
|
||||
if task_id is not None:
|
||||
self._repository.update_progress(
|
||||
task_id=task_id,
|
||||
done_items=completed_items,
|
||||
total_items=total_items,
|
||||
current_item=file_entry["label"],
|
||||
)
|
||||
self._filesystem.move_file(source=file_entry["source"], destination=file_entry["destination"])
|
||||
completed_items += 1
|
||||
if task_id is not None:
|
||||
self._repository.update_progress(
|
||||
task_id=task_id,
|
||||
done_items=completed_items,
|
||||
total_items=total_items,
|
||||
current_item=self._next_item_label_after_completion(completed_items, total_items, file_entry["label"]),
|
||||
)
|
||||
if task_id is not None and self._is_cancel_requested(task_id):
|
||||
return completed_items
|
||||
for directory in reversed(directories):
|
||||
shutil.copystat(Path(directory["source"]), Path(directory["destination"]), follow_symlinks=False)
|
||||
for directory in reversed(directories):
|
||||
self._filesystem.delete_empty_directory(Path(directory["source"]))
|
||||
progress_total_items = int(item.get("progress_total_items", 1))
|
||||
source_path = self._item_source_path(item)
|
||||
destination_path = self._item_destination_path(item)
|
||||
progress_label = str(item.get("progress_label") or Path(source_path).name)
|
||||
self._repository.update_progress(
|
||||
task_id=task_id,
|
||||
done_items=completed_items,
|
||||
total_items=total_items,
|
||||
current_item=progress_label,
|
||||
)
|
||||
self._filesystem.move_directory(source=source_path, destination=destination_path)
|
||||
completed_items += progress_total_items
|
||||
self._repository.update_progress(
|
||||
task_id=task_id,
|
||||
done_items=completed_items,
|
||||
total_items=total_items,
|
||||
current_item=self._next_item_label_after_completion(completed_items, total_items, progress_label),
|
||||
)
|
||||
return completed_items
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user