Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/data/generate_storage_from_git.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
import os | import os | ||||
from subprocess import check_output | from subprocess import check_output | ||||
from typing import Dict, Optional | from typing import Dict, Optional | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | with open(output, "wb") as outstream: | ||||
for name in visit["branches"] | for name in visit["branches"] | ||||
} | } | ||||
snap = Snapshot(branches=branches) | snap = Snapshot(branches=branches) | ||||
sto.snapshot_add([snap]) | sto.snapshot_add([snap]) | ||||
# add a "closing" origin visit status update referencing the snapshot | # add a "closing" origin visit status update referencing the snapshot | ||||
status = OriginVisitStatus( | status = OriginVisitStatus( | ||||
origin=visit["origin"], | origin=visit["origin"], | ||||
visit=visit_id, | visit=visit_id, | ||||
date=datetime.fromtimestamp(visit["date"], tz=timezone.utc), | # +1 required otherwise this second visit status is ignored | ||||
# (storage sql query with ON CONFLICT DO NOTHING) | |||||
date=datetime.fromtimestamp(visit["date"] + 1, tz=timezone.utc), | |||||
status="full", | status="full", | ||||
snapshot=snap.id, | snapshot=snap.id, | ||||
) | ) | ||||
sto.origin_visit_status_add([status]) | sto.origin_visit_status_add([status]) | ||||
click.echo(f"Serialized the storage made from {reponame} in {output}") | click.echo(f"Serialized the storage made from {reponame} in {output}") | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
main() | main() |