home · contact · privacy
Refactor VideoFile.flags setting.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 30 Nov 2024 18:18:36 +0000 (19:18 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 30 Nov 2024 18:18:36 +0000 (19:18 +0100)
src/ytplom/http.py
src/ytplom/misc.py

index 0c4a311f7d874a5f28ff1031bf9f6606026fc8a0..9027c98d8a731cf4cf8c410ae798b8d4cf05eda6 100644 (file)
@@ -12,9 +12,8 @@ from jinja2 import (  # type: ignore
         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,
@@ -149,10 +148,7 @@ class _TaskHandler(BaseHTTPRequestHandler):
                             ) -> 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()
index 5472934c9730a718aa081f03542933f01810aa4f..ca478a196d5c1aff90e1fab9c1d0891457d5fe8b 100644 (file)
@@ -311,7 +311,7 @@ class VideoFile(DbData):
                  ) -> 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:
@@ -361,21 +361,16 @@ class VideoFile(DbData):
         """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."""