Skip to content

Commit

Permalink
delete remove content items:
Browse files Browse the repository at this point in the history
 - this was missing the whole time, I just noticed, that removed items aren't removed
 - this now removes not present items
  • Loading branch information
Totto16 committed Aug 1, 2023
1 parent adef547 commit 64f5dca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/content/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ScannedFile,
ScannedFileType,
Summary,
safe_index,
)

ContentCharacteristic = tuple[Optional[ContentType], ScannedFileType]
Expand Down Expand Up @@ -136,13 +137,14 @@ def process_folder(
results.append(result)

value = (parent_type, ScannedFileType.folder)
callback.finish(directory.name, parent_folders, value)
callback.finish(directory.name, parent_folders, 0, value)

return results

already_scanned_file_paths: list[Path] = [
content.scanned_file.path for content in rescan
]
scanned_file_registry: list[bool] = [False for _ in rescan]

for file_path, file_type, parent_folders in temp:
is_rescan = (
Expand All @@ -168,7 +170,30 @@ def process_folder(
if result is not None and is_rescan is None:
rescan.append(result)

if is_rescan is not None:
idx = already_scanned_file_paths.index(file_path)
scanned_file_registry[idx] = True

deleted: int = 0
for path, was_found in zip(
already_scanned_file_paths,
scanned_file_registry,
strict=True,
):
if was_found:
continue

index: Optional[int] = safe_index(
[content.scanned_file.path for content in rescan],
path,
)
if index is None:
raise RuntimeError(f"Path to delete wasn't founds: {path}")

del rescan[index]
deleted += 1

value = (parent_type, ScannedFileType.folder)
callback.finish(directory.name, parent_folders, value)
callback.finish(directory.name, parent_folders, deleted, value)

return rescan
2 changes: 2 additions & 0 deletions src/content/episode_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def scan(
callback.finish(
self.scanned_file.path.name,
self.scanned_file.parents,
0,
characteristic,
)

Expand Down Expand Up @@ -200,6 +201,7 @@ def scan(
callback.finish(
self.scanned_file.path.name,
self.scanned_file.parents,
0,
characteristic,
)

Expand Down
11 changes: 11 additions & 0 deletions src/content/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,20 @@ def finish(
self: Self,
name: str, # noqa: ARG002
parent_folders: list[str], # noqa: ARG002
deleted: int, # noqa: ARG002
characteristic: CT, # noqa: ARG002
) -> None:
return None

def get_saved(self: Self) -> RT:
raise MissingOverrideError


SF = TypeVar("SF")


def safe_index(ls: list[SF], item: SF) -> Optional[int]:
try:
return ls.index(item)
except ValueError:
return None
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def finish(
self: Self,
name: str,
parent_folders: list[str],
deleted: int,
characteristic: ContentCharacteristic,
) -> None:
if self.__progress_bars.get(name) is None:
Expand Down

0 comments on commit 64f5dca

Please sign in to comment.