Beispiel #1
0
def lookup_snapshot(snapshot_id, branches_from='', branches_count=1000,
                    target_types=None):
    """Return information about a snapshot, aka the list of named
    branches found during a specific visit of an origin.

    Args:
        snapshot_id (str): sha1 identifier of the snapshot
        branches_from (str): optional parameter used to skip branches
            whose name is lesser than it before returning them
        branches_count (int): optional parameter used to restrain
            the amount of returned branches
        target_types (list): optional parameter used to filter the
            target types of branch to return (possible values that can be
            contained in that list are `'content', 'directory',
            'revision', 'release', 'snapshot', 'alias'`)

    Returns:
        A dict filled with the snapshot content.
    """
    snapshot_id_bin = _to_sha1_bin(snapshot_id)
    snapshot = storage.snapshot_get_branches(snapshot_id_bin,
                                             branches_from.encode(),
                                             branches_count, target_types)
    if not snapshot:
        raise NotFoundExc('Snapshot with id %s not found!' % snapshot_id)
    return converters.from_snapshot(snapshot)
Beispiel #2
0
def lookup_latest_origin_snapshot(origin_id, allowed_statuses=None):
    """Return information about the latest snapshot of an origin.

    .. warning:: At most 1000 branches contained in the snapshot
        will be returned for performance reasons.

    Args:
        origin_id: integer identifier of the origin
        allowed_statuses: list of visit statuses considered
            to find the latest snapshot for the visit. For instance,
            ``allowed_statuses=['full']`` will only consider visits that
            have successfully run to completion.

    Returns:
        A dict filled with the snapshot content.
    """
    snapshot = storage.snapshot_get_latest(origin_id, allowed_statuses)
    return converters.from_snapshot(snapshot)
Beispiel #3
0
def lookup_latest_origin_snapshot(
        origin: str,
        allowed_statuses: List[str] = None) -> Optional[Dict[str, Any]]:
    """Return information about the latest snapshot of an origin.

    .. warning:: At most 1000 branches contained in the snapshot
        will be returned for performance reasons.

    Args:
        origin: URL or integer identifier of the origin
        allowed_statuses: list of visit statuses considered
            to find the latest snapshot for the visit. For instance,
            ``allowed_statuses=['full']`` will only consider visits that
            have successfully run to completion.

    Returns:
        A dict filled with the snapshot content.
    """
    snp = snapshot_get_latest(storage,
                              origin,
                              allowed_statuses=allowed_statuses,
                              branches_count=1000)
    return converters.from_snapshot(snp.to_dict()) if snp is not None else None
Beispiel #4
0
 def snapshot_get(self, snapshot_id):
     snp = snapshot_get_all_branches(self.storage,
                                     hash_to_bytes(snapshot_id))
     return converters.from_snapshot(snp.to_dict())
Beispiel #5
0
 def snapshot_get_latest(self, origin_url):
     snp = snapshot_get_latest(self.storage, origin_url)
     return converters.from_snapshot(snp.to_dict())
Beispiel #6
0
 def snapshot_get_branches(cls, snapshot_id, branches_from='',
                           branches_count=1000, target_types=None):
     snp = cls.storage.snapshot_get_branches(hash_to_bytes(snapshot_id),
                                             branches_from.encode(),
                                             branches_count, target_types)
     return converters.from_snapshot(snp)
Beispiel #7
0
 def snapshot_get(cls, snapshot_id):
     snp = cls.storage.snapshot_get(hash_to_bytes(snapshot_id))
     return converters.from_snapshot(snp)
Beispiel #8
0
 def snapshot_get_latest(cls, origin_id):
     snp = cls.storage.snapshot_get_latest(origin_id)
     return converters.from_snapshot(snp)