Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader)
import googleapiclient.discovery # type: ignore
from ytplom.misc import (
- B64Str, DatetimeStr, FilesWithIndex, FlagsInt, FlagName,
- NotFoundException, PlayerUpdateId, QueryId, QueryText, QuotaCost,
- UrlStr, YoutubeId,
+ B64Str, DatetimeStr, FilesWithIndex, FlagName, NotFoundException,
+ PlayerUpdateId, QueryId, QueryText, QuotaCost, UrlStr, YoutubeId,
FILE_FLAGS, PATH_APP_DATA, PATH_CACHE, TIMESTAMP_FMT,
YOUTUBE_URL_PREFIX,
ensure_expected_dirs,
) -> None:
conn = DbConnection()
file = VideoFile.get_by_b64(conn, rel_path_b64)
- flags = FlagsInt(0)
- for flag_name in flag_names:
- flags = FlagsInt(file.flags | FILE_FLAGS[flag_name])
- file.flags = flags
+ file.set_flags([FILE_FLAGS[name] for name in flag_names])
file.save(conn)
conn.commit_close()
file.ensure_absence_if_deleted()
) -> None:
self.rel_path = rel_path
self.yt_id = yt_id
- self._flags = flags
+ self.flags = flags
if last_update is None:
self._renew_last_update()
else:
"""Return if file absent despite absence of 'delete' flag."""
return not (self.is_flag_set(FlagName('delete')) or self.present)
- @property
- def flags(self) -> FlagsInt:
- """Return value of flags field."""
- return self._flags
-
- @flags.setter
- def flags(self, flags: list[FlagsInt]) -> None:
- # self._flags = FlagsInt(0)
- # for flag in flags:
- # self._flags = self._flags | flag
+ def set_flags(self, flags: list[FlagsInt]) -> None:
+ """Set .flags to bitwise OR of FlagsInt in flags."""
+ self.flags = FlagsInt(0)
+ for flag in flags:
+ self.flags = FlagsInt(self.flags | flag)
self._renew_last_update()
def is_flag_set(self, flag_name: FlagName) -> bool:
"""Return if flag of flag_name is set in flags field."""
- return bool(self._flags & FILE_FLAGS[flag_name])
+ return bool(self.flags & FILE_FLAGS[flag_name])
def ensure_absence_if_deleted(self) -> None:
"""If 'delete' flag set, ensure no actual file in filesystem."""