Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/content.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/content/[(hash_type):](hash)/filetype/ | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/filetype/` | :swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/filetype/` | ||||
""" # noqa | """ # noqa | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_content_filetype, q, | service.lookup_content_filetype, q, | ||||
notfound_msg='No filetype information found for content {}.'.format(q), | notfound_msg='No filetype information found for content {}.'.format(q), | ||||
enrich_fn=utils.enrich_metadata_endpoint) | enrich_fn=utils.enrich_metadata_endpoint, | ||||
request=request) | |||||
@api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/language/', | @api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/language/', | ||||
'api-1-content-language', checksum_args=['q']) | 'api-1-content-language', checksum_args=['q']) | ||||
@api_doc('/content/language/') | @api_doc('/content/language/') | ||||
@format_docstring() | @format_docstring() | ||||
def api_content_language(request, q): | def api_content_language(request, q): | ||||
""" | """ | ||||
Show All 28 Lines | .. http:get:: /api/1/content/[(hash_type):](hash)/language/ | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/language/` | :swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/language/` | ||||
""" # noqa | """ # noqa | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_content_language, q, | service.lookup_content_language, q, | ||||
notfound_msg='No language information found for content {}.'.format(q), | notfound_msg='No language information found for content {}.'.format(q), | ||||
enrich_fn=utils.enrich_metadata_endpoint) | enrich_fn=utils.enrich_metadata_endpoint, | ||||
request=request) | |||||
@api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/license/', | @api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/license/', | ||||
'api-1-content-license', checksum_args=['q']) | 'api-1-content-license', checksum_args=['q']) | ||||
@api_doc('/content/license/') | @api_doc('/content/license/') | ||||
@format_docstring() | @format_docstring() | ||||
def api_content_license(request, q): | def api_content_license(request, q): | ||||
""" | """ | ||||
Show All 26 Lines | .. http:get:: /api/1/content/[(hash_type):](hash)/license/ | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/license/` | :swh_web_api:`content/sha1:dc2830a9e72f23c1dfebef4413003221baa5fb62/license/` | ||||
""" # noqa | """ # noqa | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_content_license, q, | service.lookup_content_license, q, | ||||
notfound_msg='No license information found for content {}.'.format(q), | notfound_msg='No license information found for content {}.'.format(q), | ||||
enrich_fn=utils.enrich_metadata_endpoint) | enrich_fn=utils.enrich_metadata_endpoint, | ||||
request=request) | |||||
@api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/ctags/', | @api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/ctags/', | ||||
'api-1-content-ctags') | 'api-1-content-ctags') | ||||
@api_doc('/content/ctags/', tags=['hidden']) | @api_doc('/content/ctags/', tags=['hidden']) | ||||
def api_content_ctags(request, q): | def api_content_ctags(request, q): | ||||
""" | """ | ||||
Get information about all `Ctags <http://ctags.sourceforge.net/>`_-style | Get information about all `Ctags <http://ctags.sourceforge.net/>`_-style | ||||
symbols defined in a content object. | symbols defined in a content object. | ||||
""" | """ | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_content_ctags, q, | service.lookup_content_ctags, q, | ||||
notfound_msg='No ctags symbol found for content {}.'.format(q), | notfound_msg='No ctags symbol found for content {}.'.format(q), | ||||
enrich_fn=utils.enrich_metadata_endpoint) | enrich_fn=utils.enrich_metadata_endpoint, | ||||
request=request) | |||||
@api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/raw/', 'api-1-content-raw', | @api_route(r'/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/raw/', 'api-1-content-raw', | ||||
checksum_args=['q']) | checksum_args=['q']) | ||||
@api_doc('/content/raw/', handle_response=True) | @api_doc('/content/raw/', handle_response=True) | ||||
def api_content_raw(request, q): | def api_content_raw(request, q): | ||||
""" | """ | ||||
.. http:get:: /api/1/content/[(hash_type):](hash)/raw/ | .. http:get:: /api/1/content/[(hash_type):](hash)/raw/ | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | def api_content_symbol(request, q=None): | ||||
def lookup_exp(exp, last_sha1=last_sha1, per_page=per_page): | def lookup_exp(exp, last_sha1=last_sha1, per_page=per_page): | ||||
exp = list(service.lookup_expression(exp, last_sha1, per_page)) | exp = list(service.lookup_expression(exp, last_sha1, per_page)) | ||||
return exp if exp else None | return exp if exp else None | ||||
symbols = api_lookup( | symbols = api_lookup( | ||||
lookup_exp, q, | lookup_exp, q, | ||||
notfound_msg="No indexed raw content match expression '{}'.".format(q), | notfound_msg="No indexed raw content match expression '{}'.".format(q), | ||||
enrich_fn=functools.partial(utils.enrich_content, top_url=True)) | enrich_fn=functools.partial(utils.enrich_content, top_url=True), | ||||
request=request) | |||||
if symbols: | if symbols: | ||||
nb_symbols = len(symbols) | nb_symbols = len(symbols) | ||||
if nb_symbols == per_page: | if nb_symbols == per_page: | ||||
query_params = {} | query_params = {} | ||||
new_last_sha1 = symbols[-1]['sha1'] | new_last_sha1 = symbols[-1]['sha1'] | ||||
query_params['last_sha1'] = new_last_sha1 | query_params['last_sha1'] = new_last_sha1 | ||||
if request.query_params.get('per_page'): | if request.query_params.get('per_page'): | ||||
query_params['per_page'] = per_page | query_params['per_page'] = per_page | ||||
result['headers'] = { | result['headers'] = { | ||||
'link-next': reverse('api-1-content-symbol', url_args={'q': q}, | 'link-next': reverse('api-1-content-symbol', url_args={'q': q}, | ||||
query_params=query_params) | query_params=query_params, | ||||
request=request) | |||||
} | } | ||||
result.update({ | result.update({ | ||||
'results': symbols | 'results': symbols | ||||
}) | }) | ||||
return result | return result | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/content/[(hash_type):](hash)/ | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
curl -i :swh_web_api:`content/sha1_git:fe95a46679d128ff167b7c55df5d02356c5a1ae1/` | curl -i :swh_web_api:`content/sha1_git:fe95a46679d128ff167b7c55df5d02356c5a1ae1/` | ||||
""" # noqa | """ # noqa | ||||
return api_lookup( | return api_lookup( | ||||
service.lookup_content, q, | service.lookup_content, q, | ||||
notfound_msg='Content with {} not found.'.format(q), | notfound_msg='Content with {} not found.'.format(q), | ||||
enrich_fn=functools.partial(utils.enrich_content, query_string=q)) | enrich_fn=functools.partial(utils.enrich_content, query_string=q), | ||||
request=request) |