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 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 | ||||
import click | import click | ||||
import yaml | import yaml | ||||
from swh.loader.git.from_disk import GitLoaderFromDisk | from swh.loader.git.from_disk import GitLoaderFromDisk | ||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Origin, | Origin, | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | with open(output, "wb") as outstream: | ||||
date=datetime.fromtimestamp(visit["date"], tz=timezone.utc), | date=datetime.fromtimestamp(visit["date"], tz=timezone.utc), | ||||
type="git", | type="git", | ||||
) | ) | ||||
] | ] | ||||
)[0].visit | )[0].visit | ||||
# add a snapshot with branches from the input file | # add a snapshot with branches from the input file | ||||
branches = { | branches = { | ||||
f"refs/heads/{name}".encode(): SnapshotBranch( | f"refs/heads/{name}".encode(): SnapshotBranch( | ||||
target=bytes.fromhex(all_branches[f"refs/heads/{name}"]), | target=hash_to_bytes(all_branches[f"refs/heads/{name}"]), | ||||
target_type=TargetType.REVISION, | target_type=TargetType.REVISION, | ||||
) | ) | ||||
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( | ||||
Show All 13 Lines |