Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 790 Lines • ▼ Show 20 Lines | def snapshot_get_latest(self, origin, allowed_statuses=None): | ||||
order of their names. | order of their names. | ||||
.. warning:: At most 1000 branches contained in the snapshot will be | .. warning:: At most 1000 branches contained in the snapshot will be | ||||
returned for performance reasons. In order to browse the whole | returned for performance reasons. In order to browse the whole | ||||
set of branches, the method :meth:`snapshot_get_branches` | set of branches, the method :meth:`snapshot_get_branches` | ||||
should be used instead. | should be used instead. | ||||
Args: | Args: | ||||
origin (int): the origin's identifier | origin (Union[str,int]): the origin's URL or identifier | ||||
allowed_statuses (list of str): list of visit statuses considered | allowed_statuses (list of str): 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. | ||||
Returns: | Returns: | ||||
dict: a dict with three keys: | dict: a dict with three keys: | ||||
* **id**: identifier of the snapshot | * **id**: identifier of the snapshot | ||||
* **branches**: a dict of branches contained in the snapshot | * **branches**: a dict of branches contained in the snapshot | ||||
whose keys are the branches' names. | whose keys are the branches' names. | ||||
* **next_branch**: the name of the first branch not returned | * **next_branch**: the name of the first branch not returned | ||||
or :const:`None` if the snapshot has less than 1000 | or :const:`None` if the snapshot has less than 1000 | ||||
branches. | branches. | ||||
""" | """ | ||||
if isinstance(origin, str): | |||||
origin = self.origin_get({'url': origin})['id'] | |||||
visits = self._origin_visits[origin-1] | visits = self._origin_visits[origin-1] | ||||
if allowed_statuses is not None: | if allowed_statuses is not None: | ||||
visits = [visit for visit in visits | visits = [visit for visit in visits | ||||
if visit['status'] in allowed_statuses] | if visit['status'] in allowed_statuses] | ||||
snapshot = None | snapshot = None | ||||
for visit in sorted(visits, key=lambda v: (v['date'], v['visit']), | for visit in sorted(visits, key=lambda v: (v['date'], v['visit']), | ||||
reverse=True): | reverse=True): | ||||
snapshot_id = visit['snapshot'] | snapshot_id = visit['snapshot'] | ||||
▲ Show 20 Lines • Show All 743 Lines • Show Last 20 Lines |