Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/archive.py
Show First 20 Lines • Show All 1,062 Lines • ▼ Show 20 Lines | def lookup_snapshot( | |||||||||||
snapshot_id: str, | snapshot_id: str, | |||||||||||
branches_from: str = "", | branches_from: str = "", | |||||||||||
branches_count: int = 1000, | branches_count: int = 1000, | |||||||||||
target_types: Optional[List[str]] = None, | target_types: Optional[List[str]] = None, | |||||||||||
branch_name_include_substring: Optional[str] = None, | branch_name_include_substring: Optional[str] = None, | |||||||||||
branch_name_exclude_prefix: Optional[str] = "refs/pull/", | branch_name_exclude_prefix: Optional[str] = "refs/pull/", | |||||||||||
) -> Dict[str, Any]: | ) -> Dict[str, Any]: | |||||||||||
"""Return information about a snapshot, aka the list of named | """Return information about a snapshot, aka the list of named | |||||||||||
branches found during a specific visit of an origin. | branches found during a specific visit of an origin. | |||||||||||
ardumontUnsubmitted Not Done Inline Actions
ardumont: | ||||||||||||
Not Done Inline ActionsThis should be formatted as follow and moved under the Args section: Raises: NotFoundExc if the given snapshot_id is missing anlambert: This should be formatted as follow and moved under the `Args` section:
```
Raises… | ||||||||||||
Args: | Args: | |||||||||||
snapshot_id: sha1 identifier of the snapshot | snapshot_id: sha1 identifier of the snapshot | |||||||||||
branches_from: optional parameter used to skip branches | branches_from: optional parameter used to skip branches | |||||||||||
whose name is lesser than it before returning them | whose name is lesser than it before returning them | |||||||||||
branches_count: optional parameter used to restrain | branches_count: optional parameter used to restrain | |||||||||||
the amount of returned branches | the amount of returned branches | |||||||||||
target_types: optional parameter used to filter the | target_types: optional parameter used to filter the | |||||||||||
target types of branch to return (possible values that can be | target types of branch to return (possible values that can be | |||||||||||
contained in that list are `'content', 'directory', | contained in that list are `'content', 'directory', | |||||||||||
'revision', 'release', 'snapshot', 'alias'`) | 'revision', 'release', 'snapshot', 'alias'`) | |||||||||||
branch_name_include_substring: if provided, only return branches whose name | branch_name_include_substring: if provided, only return branches whose name | |||||||||||
contains given substring | contains given substring | |||||||||||
branch_name_exclude_prefix: if provided, do not return branches whose name | branch_name_exclude_prefix: if provided, do not return branches whose name | |||||||||||
starts with given pattern | starts with given pattern | |||||||||||
Raises: | ||||||||||||
NotFoundException if the given snapshot_id is missing | ||||||||||||
anlambertUnsubmitted Not Done Inline Actionss/NotFoundException/NotFoundExc/ anlambert: s/NotFoundException/NotFoundExc/ | ||||||||||||
Returns: | Returns: | |||||||||||
A dict filled with the snapshot content. | A dict filled with the snapshot content. | |||||||||||
""" | """ | |||||||||||
snapshot_id_bin = _to_sha1_bin(snapshot_id) | snapshot_id_bin = _to_sha1_bin(snapshot_id) | |||||||||||
if storage.snapshot_missing([snapshot_id_bin]): | ||||||||||||
raise NotFoundExc(f"Snapshot with id {snapshot_id} not found!") | ||||||||||||
partial_branches = storage.snapshot_get_branches( | partial_branches = storage.snapshot_get_branches( | |||||||||||
snapshot_id_bin, | snapshot_id_bin, | |||||||||||
branches_from.encode(), | branches_from.encode(), | |||||||||||
branches_count, | branches_count, | |||||||||||
target_types, | target_types, | |||||||||||
branch_name_include_substring.encode() | branch_name_include_substring.encode() | |||||||||||
if branch_name_include_substring | if branch_name_include_substring | |||||||||||
else None, | else None, | |||||||||||
branch_name_exclude_prefix.encode() if branch_name_exclude_prefix else None, | branch_name_exclude_prefix.encode() if branch_name_exclude_prefix else None, | |||||||||||
) | ) | |||||||||||
if not partial_branches: | return ( | |||||||||||
raise NotFoundExc(f"Snapshot with id {snapshot_id} not found!") | converters.from_partial_branches(partial_branches) if partial_branches else None | |||||||||||
) | ||||||||||||
return converters.from_partial_branches(partial_branches) | ||||||||||||
def lookup_latest_origin_snapshot( | def lookup_latest_origin_snapshot( | |||||||||||
origin: str, allowed_statuses: List[str] = None | origin: str, allowed_statuses: List[str] = None | |||||||||||
) -> Optional[Dict[str, Any]]: | ) -> Optional[Dict[str, Any]]: | |||||||||||
"""Return information about the latest snapshot of an origin. | """Return information about the latest snapshot of an origin. | |||||||||||
.. warning:: At most 1000 branches contained in the snapshot | .. warning:: At most 1000 branches contained in the snapshot | |||||||||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |