Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | if len(results) > origin_count: | ||||
origin_from = results.pop()['id'] | origin_from = results.pop()['id'] | ||||
response['headers']['link-next'] = reverse( | response['headers']['link-next'] = reverse( | ||||
'api-1-origins', | 'api-1-origins', | ||||
query_params={'origin_from': origin_from, | query_params={'origin_from': origin_from, | ||||
'origin_count': origin_count}) | 'origin_count': origin_count}) | ||||
return response | return response | ||||
@api_route(r'/origin/(?P<origin_type>[a-z]+)/url/(?P<origin_url>.+)/', | |||||
'api-1-origin') | |||||
@api_route(r'/origin/(?P<origin_url>.+)/get/', 'api-1-origin') | @api_route(r'/origin/(?P<origin_url>.+)/get/', 'api-1-origin') | ||||
@api_doc('/origin/') | @api_doc('/origin/') | ||||
@format_docstring(return_origin=DOC_RETURN_ORIGIN) | @format_docstring(return_origin=DOC_RETURN_ORIGIN) | ||||
def api_origin(request, origin_url, origin_type=None): | def api_origin(request, origin_url): | ||||
""" | """ | ||||
.. http:get:: /api/1/origin/(origin_url)/get/ | .. http:get:: /api/1/origin/(origin_url)/get/ | ||||
Get information about a software origin. | Get information about a software origin. | ||||
:param string origin_url: the origin url | :param string origin_url: the origin url | ||||
{return_origin} | {return_origin} | ||||
{common_headers} | {common_headers} | ||||
**Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | ||||
:http:method:`options` | :http:method:`options` | ||||
:statuscode 200: no error | :statuscode 200: no error | ||||
:statuscode 404: requested origin can not be found in the archive | :statuscode 404: requested origin can not be found in the archive | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`origin/git/url/https://github.com/python/cpython/` | :swh_web_api:`origin/https://github.com/python/cpython/get/` | ||||
.. http:get:: /api/1/origin/(origin_type)/url/(origin_url)/ | |||||
Get information about a software origin. | |||||
.. warning:: | |||||
All endpoints using an ``origin_type`` are | |||||
deprecated and will be removed in the near future. Only those | |||||
using only an ``origin_url`` will remain available. | |||||
You should use :http:get:`/api/1/origin/(origin_url)/get/` instead. | |||||
:param string origin_type: the origin type (possible values are | |||||
``git``, ``svn``, ``hg``, ``deb``, ``pypi``, ``npm``, ``ftp`` or | |||||
``deposit``) | |||||
:param string origin_url: the origin url | |||||
{return_origin} | |||||
{common_headers} | |||||
**Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | |||||
:http:method:`options` | |||||
:statuscode 200: no error | |||||
:statuscode 404: requested origin can not be found in the archive | |||||
**Example:** | |||||
.. parsed-literal:: | |||||
:swh_web_api:`origin/git/url/https://github.com/python/cpython/` | |||||
""" | """ | ||||
ori_dict = { | ori_dict = { | ||||
'type': origin_type, | |||||
'url': origin_url | 'url': origin_url | ||||
} | } | ||||
ori_dict = {k: v for k, v in ori_dict.items() if ori_dict[k]} | |||||
error_msg = 'Origin %s not found.' % \ | error_msg = 'Origin with url %s not found.' % ori_dict['url'] | ||||
(ori_dict.get('id') or ori_dict['url']) | |||||
return api_lookup( | return api_lookup( | ||||
service.lookup_origin, ori_dict, | service.lookup_origin, ori_dict, | ||||
notfound_msg=error_msg, | notfound_msg=error_msg, | ||||
enrich_fn=_enrich_origin) | enrich_fn=_enrich_origin) | ||||
@api_route(r'/origin/search/(?P<url_pattern>.+)/', | @api_route(r'/origin/search/(?P<url_pattern>.+)/', | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | return api_lookup( | ||||
service.lookup_origin_visit, origin_url, int(visit_id), | service.lookup_origin_visit, origin_url, int(visit_id), | ||||
notfound_msg=('No visit {} for origin {} found' | notfound_msg=('No visit {} for origin {} found' | ||||
.format(visit_id, origin_url)), | .format(visit_id, origin_url)), | ||||
enrich_fn=partial(_enrich_origin_visit, | enrich_fn=partial(_enrich_origin_visit, | ||||
with_origin_link=True, | with_origin_link=True, | ||||
with_origin_visit_link=False)) | with_origin_visit_link=False)) | ||||
@api_route(r'/origin/(?P<origin_type>[a-z]+)/url/(?P<origin_url>.+)' | @api_route(r'/origin/(?P<origin_url>.+)' | ||||
'/intrinsic-metadata', 'api-origin-intrinsic-metadata') | '/intrinsic-metadata', 'api-origin-intrinsic-metadata') | ||||
@api_doc('/origin/intrinsic-metadata/') | @api_doc('/origin/intrinsic-metadata/') | ||||
@format_docstring() | @format_docstring() | ||||
def api_origin_intrinsic_metadata(request, origin_type, origin_url): | def api_origin_intrinsic_metadata(request, origin_url): | ||||
""" | """ | ||||
.. http:get:: /api/1/origin/(origin_type)/url/(origin_url)/intrinsic-metadata | .. http:get:: /api/1/origin/(origin_url)/intrinsic-metadata | ||||
Get intrinsic metadata of a software origin (as a JSON-LD/CodeMeta dictionary). | Get intrinsic metadata of a software origin (as a JSON-LD/CodeMeta dictionary). | ||||
:param string origin_type: the origin type (possible values are ``git``, ``svn``, | |||||
``hg``, ``deb``, ``pypi``, ``npm``, ``ftp`` or ``deposit``) | |||||
:param string origin_url: the origin url | :param string origin_url: the origin url | ||||
:>json string ???: intrinsic metadata field of the origin | :>json string ???: intrinsic metadata field of the origin | ||||
{common_headers} | {common_headers} | ||||
**Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | ||||
:http:method:`options` | :http:method:`options` | ||||
:statuscode 200: no error | :statuscode 200: no error | ||||
:statuscode 404: requested origin can not be found in the archive | :statuscode 404: requested origin can not be found in the archive | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`origin/git/url/https://github.com/python/cpython/intrinsic-metadata` | :swh_web_api:`origin/https://github.com/python/cpython/intrinsic-metadata` | ||||
""" # noqa | """ # noqa | ||||
ori_dict = { | ori_dict = { | ||||
'type': origin_type, | |||||
'url': origin_url | 'url': origin_url | ||||
} | } | ||||
error_msg = 'Origin with URL %s not found' % ori_dict['url'] | error_msg = 'Origin with url %s not found' % ori_dict['url'] | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_origin_intrinsic_metadata, ori_dict, | service.lookup_origin_intrinsic_metadata, ori_dict, | ||||
notfound_msg=error_msg, | notfound_msg=error_msg, | ||||
enrich_fn=_enrich_origin) | enrich_fn=_enrich_origin) |