Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show All 13 Lines | |||||
from swh.indexer.ctags import CtagsIndexer | from swh.indexer.ctags import CtagsIndexer | ||||
from swh.indexer.storage import get_indexer_storage | from swh.indexer.storage import get_indexer_storage | ||||
from swh.model.model import Content, OriginVisitStatus | from swh.model.model import Content, OriginVisitStatus | ||||
from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | ||||
from swh.model.model import Directory, Origin, OriginVisit | from swh.model.model import Directory, Origin, OriginVisit | ||||
from swh.loader.git.from_disk import GitLoaderFromArchive | from swh.loader.git.from_disk import GitLoaderFromArchive | ||||
from swh.search import get_search | from swh.search import get_search | ||||
from swh.storage.algos.dir_iterators import dir_iterator | from swh.storage.algos.dir_iterators import dir_iterator | ||||
from swh.storage.algos.snapshot import snapshot_get_latest | |||||
from swh.web import config | from swh.web import config | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
get_mimetype_and_encoding_for_content, | get_mimetype_and_encoding_for_content, | ||||
prepare_content_for_display, | prepare_content_for_display, | ||||
_re_encode_content, | _re_encode_content, | ||||
) | ) | ||||
from swh.web.common import service | from swh.web.common import service | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def _init_tests_data(): | ||||
directories = set() | directories = set() | ||||
revisions = set() | revisions = set() | ||||
releases = set() | releases = set() | ||||
snapshots = set() | snapshots = set() | ||||
content_path = {} | content_path = {} | ||||
# Get all objects loaded into the test archive | # Get all objects loaded into the test archive | ||||
for origin in _TEST_ORIGINS: | for origin in _TEST_ORIGINS: | ||||
snp = storage.snapshot_get_latest(origin["url"]) | snp = snapshot_get_latest(storage, origin["url"]) | ||||
anlambert: Use the snapshot model instead of a dict here (as you did in the remaining of that diff) | |||||
Done Inline ActionsI recall not doing it everywhere because i fought a lot initially ;) The diff got simplified a lot once i found the right place to change. ardumont: I recall not doing it everywhere because i fought a lot initially ;)
The diff got simplified a… | |||||
snapshots.add(hash_to_hex(snp["id"])) | snapshots.add(hash_to_hex(snp.id)) | ||||
for branch_name, branch_data in snp["branches"].items(): | for branch_name, branch_data in snp.branches.items(): | ||||
if branch_data["target_type"] == "revision": | target_type = branch_data.target_type.value | ||||
revisions.add(branch_data["target"]) | if target_type == "revision": | ||||
elif branch_data["target_type"] == "release": | revisions.add(branch_data.target) | ||||
release = next(storage.release_get([branch_data["target"]])) | elif target_type == "release": | ||||
release = next(storage.release_get([branch_data.target])) | |||||
revisions.add(release["target"]) | revisions.add(release["target"]) | ||||
releases.add(hash_to_hex(branch_data["target"])) | releases.add(hash_to_hex(branch_data.target)) | ||||
for rev_log in storage.revision_shortlog(set(revisions)): | for rev_log in storage.revision_shortlog(set(revisions)): | ||||
rev_id = rev_log[0] | rev_id = rev_log[0] | ||||
revisions.add(rev_id) | revisions.add(rev_id) | ||||
for rev in storage.revision_get(revisions): | for rev in storage.revision_get(revisions): | ||||
dir_id = rev["directory"] | dir_id = rev["directory"] | ||||
directories.add(hash_to_hex(dir_id)) | directories.add(hash_to_hex(dir_id)) | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |
Use the snapshot model instead of a dict here (as you did in the remaining of that diff)