| 541 | return result |
| 542 | |
| 543 | def write(self): |
| 544 | from .item import ManifestItem |
| 545 | |
| 546 | # self.timestamp needs to be strictly monotonically increasing. Clocks often are not set correctly |
| 547 | if self.timestamp is None: |
| 548 | self.timestamp = datetime.now(tz=timezone.utc).isoformat(timespec="microseconds") |
| 549 | else: |
| 550 | incremented_ts = self.last_timestamp + timedelta(microseconds=1) |
| 551 | now_ts = datetime.now(tz=timezone.utc) |
| 552 | max_ts = max(incremented_ts, now_ts) |
| 553 | self.timestamp = max_ts.isoformat(timespec="microseconds") |
| 554 | # include checks for limits as enforced by limited unpacker (used by load()) |
| 555 | assert self.archives.count() <= MAX_ARCHIVES |
| 556 | assert len(self.item_keys) <= 100 |
| 557 | self.config["item_keys"] = tuple(sorted(self.item_keys)) |
| 558 | manifest_archives = self.archives.finish(self) |
| 559 | manifest = ManifestItem( |
| 560 | version=2, archives=manifest_archives, timestamp=self.timestamp, config=StableDict(self.config) |
| 561 | ) |
| 562 | data = self.key.pack_metadata(manifest.as_dict()) |
| 563 | self.id = self.repo_objs.id_hash(data) |
| 564 | robj = self.repo_objs.format(self.MANIFEST_ID, {}, data, ro_type=ROBJ_MANIFEST) |
| 565 | self.repository.put_manifest(robj) |