return file if isinstance(file, VideoFile) else cls(None, Path(''))
@classmethod
- def get_all(cls, conn: DbConn) -> list[Self]:
+ def get_all_non_deleted(cls, conn: DbConn) -> list[Self]:
"""Extend super by excluding deleteds."""
return [f for f in super().get_all(conn) if not f.deleted]
@classmethod
- def get_deleteds(cls, conn: DbConn) -> list[Self]:
- """Get _only_ deleteds."""
+ def get_all_deleted(cls, conn: DbConn) -> list[Self]:
+ """Get only deleteds."""
return [f for f in super().get_all(conn) if f.deleted]
@classmethod
needed_tags_seen: TagSet = TagSet(set()),
show_absent: bool = False
) -> list[Self]:
- """Return cls.get_all matching provided filter criteria."""
+ """Return cls.get_all_non_deleted matching provided filter criteria."""
return [
- f for f in cls.get_all(conn)
+ f for f in cls.get_all_non_deleted(conn)
if (show_absent or f.present)
and str(filter_path).lower() in str(f.rel_path).lower()
and (cls.tags_prefilter_needed.are_all_in(f.tags)
def all_tags_showable(cls, conn) -> TagSet:
"""Show all used tags passing .tags_display_whitelist."""
tags = TagSet()
- for file in cls.get_all(conn):
+ for file in cls.get_all_non_deleted(conn):
tags.add(file.tags.whitelisted(cls.tags_display_whitelist))
return tags
def unused_tags(self, conn: DbConn) -> TagSet:
"""Return tags used among other VideoFiles, not in self."""
tags = TagSet()
- for file in self.get_all(conn):
+ for file in self.get_all_non_deleted(conn):
tags.add(file.tags.all_not_in(self.tags).whitelisted(
self.tags_display_whitelist))
return tags
"""Return if flag of flag_name is set in flags field."""
return bool(self.flags & FILE_FLAGS[flag_name])
- def ensure_unlinked_if_deleted(self, conn: DbConn) -> None:
- """If 'delete' flag set and no undeleted owner, ensure unlinked."""
- if self.full_path in [f.full_path for f in self.get_all(conn)]:
+ def ensure_unlinked_if_no_living_owners(self, conn: DbConn) -> None:
+ """If 'delete' flag set and no undeleted owner, unlink."""
+ if self.full_path in [f.full_path
+ for f in self.get_all_non_deleted(conn)]:
return
- if self.is_flag_set(FlagName('delete')) and self.present:
+ if self.present:
self.unlink_locally()
def unlink_locally(self) -> None:
@classmethod
def purge_deleteds(cls, conn: DbConn) -> None:
"""For all of .is_flag_set("deleted"), remove file _and_ DB entry."""
- for file in cls.get_deleteds(conn):
+ for file in cls.get_all_deleted(conn):
if file.present:
file.unlink_locally()
print(f'SYNC: purging off DB: {file.digest.b64} ({file.rel_path})')
def _sync_db(self):
with DbConn() as conn:
- known_paths = [file.rel_path for file in VideoFile.get_all(conn)]
+ known_paths = [file.rel_path for
+ file in VideoFile.get_all_non_deleted(conn)]
old_cwd = Path.cwd()
chdir(PATH_DOWNLOADS)
for path in [p for p in Path('.').iterdir() if p.is_file()]:
'present',
str(path),
VideoFile.get_by_yt_id(conn, yt_id).digest.b64)
- for file in VideoFile.get_deleteds(conn):
- file.ensure_unlinked_if_deleted(conn)
- self._files = VideoFile.get_all(conn)
+ for file in VideoFile.get_all_deleted(conn):
+ file.ensure_unlinked_if_no_living_owners(conn)
+ self._files = VideoFile.get_all_non_deleted(conn)
chdir(old_cwd)
def last_update_for(self,