Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/algos/snapshot.py
Show All 35 Lines | def snapshot_get_all_branches(storage, snapshot_id): | ||||
return ret | return ret | ||||
def snapshot_get_latest( | def snapshot_get_latest( | ||||
storage, | storage, | ||||
origin: str, | origin: str, | ||||
allowed_statuses: Optional[Iterable[str]] = None, | allowed_statuses: Optional[Iterable[str]] = None, | ||||
branches_count: Optional[int] = None, | branches_count: Optional[int] = None, | ||||
limit: Optional[int] = 100, | |||||
) -> Optional[Snapshot]: | ) -> Optional[Snapshot]: | ||||
"""Get the latest snapshot for the given origin, optionally only from visits that have | """Get the latest snapshot for the given origin, optionally only from visits that have | ||||
one of the given allowed_statuses. | one of the given allowed_statuses. | ||||
The branches of the snapshot are iterated in the lexicographical | The branches of the snapshot are iterated in the lexicographical | ||||
order of their names. | order of their names. | ||||
Args: | Args: | ||||
storage: Storage instance | storage: Storage instance | ||||
origin: the origin's URL | origin: the origin's URL | ||||
allowed_statuses: list of visit statuses considered | allowed_statuses: list of visit statuses considered | ||||
to find the latest snapshot for the visit. For instance, | to find the latest snapshot for the visit. For instance, | ||||
``allowed_statuses=['full']`` will only consider visits that | ``allowed_statuses=['full']`` will only consider visits that | ||||
have successfully run to completion. | have successfully run to completion. | ||||
branches_count: Optional parameter to retrieve snapshot with all branches | branches_count: Optional parameter to retrieve snapshot with all branches | ||||
(default behavior when None) or not. If set to positive number, the snapshot | (default behavior when None) or not. If set to positive number, the snapshot | ||||
will be partial with only that number of branches. | will be partial with only that number of branches. | ||||
limit: Bound the search to a given limit | |||||
Raises: | Raises: | ||||
ValueError if branches_count is not a positive value | ValueError if branches_count is not a positive value | ||||
Returns: | Returns: | ||||
The snapshot object if one is found matching the criteria or None. | The snapshot object if one is found matching the criteria or None. | ||||
""" | """ | ||||
visit_and_status = origin_get_latest_visit_status( | visit_and_status = origin_get_latest_visit_status( | ||||
storage, origin, allowed_statuses=allowed_statuses, require_snapshot=True | storage, | ||||
origin, | |||||
allowed_statuses=allowed_statuses, | |||||
limit=limit, | |||||
require_snapshot=True, | |||||
) | ) | ||||
if not visit_and_status: | if not visit_and_status: | ||||
return None | return None | ||||
_, visit_status = visit_and_status | _, visit_status = visit_and_status | ||||
snapshot_id = visit_status.snapshot | snapshot_id = visit_status.snapshot | ||||
if not snapshot_id: | if not snapshot_id: | ||||
Show All 17 Lines |