소스 검색

introduce ArchiveItem, see #1157

Thomas Waldmann 9 년 전
부모
커밋
585407f4f4
1개의 변경된 파일33개의 추가작업 그리고 0개의 파일을 삭제
  1. 33 0
      src/borg/item.py

+ 33 - 0
src/borg/item.py

@@ -204,3 +204,36 @@ class Key(PropDict):
     enc_hmac_key = PropDict._make_property('enc_hmac_key', bytes)
     id_key = PropDict._make_property('id_key', bytes)
     chunk_seed = PropDict._make_property('chunk_seed', int)
+
+
+class ArchiveItem(PropDict):
+    """
+    ArchiveItem abstraction that deals with validation and the low-level details internally:
+
+    An ArchiveItem is created either from msgpack unpacker output, from another dict, from kwargs or
+    built step-by-step by setting attributes.
+
+    msgpack gives us a dict with bytes-typed keys, just give it to ArchiveItem(d) and use arch.xxx later.
+
+    If a ArchiveItem shall be serialized, give as_dict() method output to msgpack packer.
+    """
+
+    VALID_KEYS = {'version', 'name', 'items', 'cmdline', 'hostname', 'username', 'time', 'time_end',
+                  'comment', 'chunker_params',
+                  'recreate_cmdline', 'recreate_source_id', 'recreate_args'}  # str-typed keys
+
+    __slots__ = ("_dict", )  # avoid setting attributes not supported by properties
+
+    version = PropDict._make_property('version', int)
+    name = PropDict._make_property('name', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    items = PropDict._make_property('items', list)
+    cmdline = PropDict._make_property('cmdline', list)  # list of s-e-str
+    hostname = PropDict._make_property('hostname', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    username = PropDict._make_property('username', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    time = PropDict._make_property('time', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    time_end = PropDict._make_property('time_end', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    comment = PropDict._make_property('comment', str, 'surrogate-escaped str', encode=safe_encode, decode=safe_decode)
+    chunker_params = PropDict._make_property('chunker_params', tuple)
+    recreate_source_id = PropDict._make_property('recreate_source_id', bytes)
+    recreate_cmdline = PropDict._make_property('recreate_cmdline', list)  # list of s-e-str
+    recreate_args = PropDict._make_property('recreate_args', list)  # list of s-e-str