Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | def lookup_content_license(q): | ||||
return converters.from_swh({'id': sha1, 'facts': lic[sha1]}, | return converters.from_swh({'id': sha1, 'facts': lic[sha1]}, | ||||
hashess={'id'}) | hashess={'id'}) | ||||
def lookup_origin(origin): | def lookup_origin(origin): | ||||
"""Return information about the origin matching dict origin. | """Return information about the origin matching dict origin. | ||||
Args: | Args: | ||||
origin: origin's dict with keys either 'id' or 'url' | origin: origin's dict with 'url' key | ||||
Returns: | Returns: | ||||
origin information as dict. | origin information as dict. | ||||
""" | """ | ||||
origin_info = storage.origin_get(origin) | origin_info = storage.origin_get(origin) | ||||
if not origin_info: | if not origin_info: | ||||
msg = 'Origin %s not found!' % \ | msg = 'Origin with url %s not found!' % origin['url'] | ||||
(origin.get('id') or origin['url']) | |||||
raise NotFoundExc(msg) | raise NotFoundExc(msg) | ||||
return converters.from_origin(origin_info) | return converters.from_origin(origin_info) | ||||
def lookup_origins(origin_from=1, origin_count=100): | def lookup_origins(origin_from=1, origin_count=100): | ||||
"""Get list of archived software origins in a paginated way. | """Get list of archived software origins in a paginated way. | ||||
Origins are sorted by id before returning them | Origins are sorted by id before returning them | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | Args: | ||||
origin_dict: origin's dict with keys ('type' AND 'url') | origin_dict: origin's dict with keys ('type' AND 'url') | ||||
Returns: | Returns: | ||||
origin metadata. | origin metadata. | ||||
""" | """ | ||||
origin_info = storage.origin_get(origin_dict) | origin_info = storage.origin_get(origin_dict) | ||||
if not origin_info: | if not origin_info: | ||||
msg = 'Origin with type %s and url %s not found!' % \ | msg = 'Origin with url %s not found!' % origin_dict['url'] | ||||
(origin_dict['type'], origin_dict['url']) | |||||
raise NotFoundExc(msg) | raise NotFoundExc(msg) | ||||
origins = [origin_info['url']] | origins = [origin_info['url']] | ||||
match = _first_element( | match = _first_element( | ||||
idx_storage.origin_intrinsic_metadata_get(origins)) | idx_storage.origin_intrinsic_metadata_get(origins)) | ||||
result = {} | result = {} | ||||
if match: | if match: | ||||
result = match['metadata'] | result = match['metadata'] | ||||
▲ Show 20 Lines • Show All 780 Lines • Show Last 20 Lines |