Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 copy import deepcopy | from copy import deepcopy | ||||
import os | import os | ||||
import random | import random | ||||
import time | |||||
from swh.indexer.fossology_license import FossologyLicenseIndexer | from swh.indexer.fossology_license import FossologyLicenseIndexer | ||||
from swh.indexer.mimetype import MimetypeIndexer | from swh.indexer.mimetype import MimetypeIndexer | ||||
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.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.identifiers import directory_identifier | from swh.model.identifiers import directory_identifier | ||||
from swh.loader.git.from_disk import GitLoaderFromArchive | from swh.loader.git.from_disk import GitLoaderFromArchive | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
# Lightweight git repositories that will be loaded to generate | # Lightweight git repositories that will be loaded to generate | ||||
# input data for tests | # input data for tests | ||||
_TEST_ORIGINS = [ | _TEST_ORIGINS = [ | ||||
{ | { | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'https://github.com/wcoder/highlightjs-line-numbers.js', | 'url': 'https://github.com/wcoder/highlightjs-line-numbers.js', | ||||
'archives': ['highlightjs-line-numbers.js.zip', | 'archives': ['highlightjs-line-numbers.js.zip', | ||||
'highlightjs-line-numbers.js_visit2.zip'] | 'highlightjs-line-numbers.js_visit2.zip'], | ||||
'visit_date': ['Dec 1 2018, 01:00 UTC', | |||||
'Jan 20 2019, 15:00 UTC'] | |||||
}, | }, | ||||
{ | { | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'https://github.com/memononen/libtess2', | 'url': 'https://github.com/memononen/libtess2', | ||||
'archives': ['libtess2.zip'] | 'archives': ['libtess2.zip'], | ||||
'visit_date': ['May 25 2018, 01:00 UTC'] | |||||
}, | }, | ||||
{ | { | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'repo_with_submodules', | 'url': 'repo_with_submodules', | ||||
'archives': ['repo_with_submodules.tgz'] | 'archives': ['repo_with_submodules.tgz'], | ||||
'visit_date': ['Jan 1 2019, 01:00 UTC'] | |||||
} | } | ||||
] | ] | ||||
_contents = {} | _contents = {} | ||||
# Tests data initialization | # Tests data initialization | ||||
def _init_tests_data(): | def _init_tests_data(): | ||||
# Load git repositories from archives | # Load git repositories from archives | ||||
loader = GitLoaderFromArchive(config=_TEST_LOADER_CONFIG) | loader = GitLoaderFromArchive(config=_TEST_LOADER_CONFIG) | ||||
# Get reference to the memory storage | # Get reference to the memory storage | ||||
storage = loader.storage | storage = loader.storage | ||||
for origin in _TEST_ORIGINS: | for origin in _TEST_ORIGINS: | ||||
nb_visits = len(origin['archives']) | |||||
for i, archive in enumerate(origin['archives']): | for i, archive in enumerate(origin['archives']): | ||||
origin_repo_archive = \ | origin_repo_archive = \ | ||||
os.path.join(os.path.dirname(__file__), | os.path.join(os.path.dirname(__file__), | ||||
'resources/repos/%s' % archive) | 'resources/repos/%s' % archive) | ||||
loader.load(origin['url'], origin_repo_archive, None) | loader.load(origin['url'], origin_repo_archive, | ||||
if nb_visits > 1 and i != nb_visits - 1: | origin['visit_date'][i]) | ||||
time.sleep(1) | |||||
origin.update(storage.origin_get(origin)) # add an 'id' key if enabled | origin.update(storage.origin_get(origin)) # add an 'id' key if enabled | ||||
contents = set() | contents = set() | ||||
directories = set() | directories = set() | ||||
revisions = set() | revisions = set() | ||||
releases = set() | releases = set() | ||||
snapshots = set() | snapshots = set() | ||||
persons = set() | persons = set() | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |