Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/backends/archive.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 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 typing import List | |||||
from swh.graphql import server | from swh.graphql import server | ||||
from swh.model.swhids import CoreSWHID | |||||
class Archive: | class Archive: | ||||
def __init__(self): | def __init__(self): | ||||
self.storage = server.get_storage() | self.storage = server.get_storage() | ||||
def get_origin(self, url): | def get_origin(self, url): | ||||
return self.storage.origin_get([url])[0] | return self.storage.origin_get([url])[0] | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | class Archive: | ||||
def get_directory_entries(self, directory_id, after=None, first=50): | def get_directory_entries(self, directory_id, after=None, first=50): | ||||
return self.storage.directory_get_entries( | return self.storage.directory_get_entries( | ||||
directory_id, limit=first, page_token=after | directory_id, limit=first, page_token=after | ||||
) | ) | ||||
def get_content(self, content_id): | def get_content(self, content_id): | ||||
# FIXME, only for tests | # FIXME, only for tests | ||||
return self.storage.content_find({"sha1_git": content_id}) | return self.storage.content_find({"sha1_git": content_id}) | ||||
def search_in_swhids(self, swhid) -> List: | |||||
# query iff a valid swhid | |||||
swhid = CoreSWHID.from_string(swhid) | |||||
return self.get_revisions([swhid.object_id]) | |||||
def search_in_metadata(self, query) -> List: | |||||
# validate the query language as a key expression in the utils | |||||
return [] | |||||
def search_in_origins(self, query) -> List: | |||||
# use this with the get_origins method | |||||
# validate the query language as a key expression in the utils | |||||
return [] |