Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show All 18 Lines | |||||
from swh.model.from_disk import Directory | from swh.model.from_disk import Directory | ||||
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 | ||||
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.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, prepare_content_for_display | get_mimetype_and_encoding_for_content, prepare_content_for_display, | ||||
_re_encode_content | |||||
) | ) | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.highlightjs import get_hljs_language_from_filename | from swh.web.common.highlightjs import get_hljs_language_from_filename | ||||
# Module used to initialize data that will be provided as tests input | # Module used to initialize data that will be provided as tests input | ||||
# Configuration for git loader | # Configuration for git loader | ||||
_TEST_LOADER_CONFIG = { | _TEST_LOADER_CONFIG = { | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | for sha1, contents_metadata in result.items(): | ||||
contents.append({ | contents.append({ | ||||
algo: hash_to_hex(content_metadata[algo]) | algo: hash_to_hex(content_metadata[algo]) | ||||
for algo in DEFAULT_ALGORITHMS | for algo in DEFAULT_ALGORITHMS | ||||
}) | }) | ||||
path = content_path[sha1] | path = content_path[sha1] | ||||
cnt = next(storage.content_get([sha1])) | cnt = next(storage.content_get([sha1])) | ||||
mimetype, encoding = get_mimetype_and_encoding_for_content( | mimetype, encoding = get_mimetype_and_encoding_for_content( | ||||
cnt['data']) | cnt['data']) | ||||
_, _, cnt['data'] = _re_encode_content( | |||||
mimetype, encoding, cnt['data']) | |||||
content_display_data = prepare_content_for_display( | content_display_data = prepare_content_for_display( | ||||
cnt['data'], mimetype, path) | cnt['data'], mimetype, path) | ||||
contents[-1]['path'] = path | contents[-1]['path'] = path | ||||
contents[-1]['mimetype'] = mimetype | contents[-1]['mimetype'] = mimetype | ||||
contents[-1]['encoding'] = encoding | contents[-1]['encoding'] = encoding | ||||
contents[-1]['hljs_language'] = content_display_data['language'] | contents[-1]['hljs_language'] = content_display_data['language'] | ||||
contents[-1]['data'] = content_display_data['content_data'] | contents[-1]['data'] = content_display_data['content_data'] | ||||
_contents[contents[-1]['sha1']] = contents[-1] | _contents[contents[-1]['sha1']] = contents[-1] | ||||
▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines |