Page MenuHomeSoftware Heritage

D3419.id12116.diff
No OneTemporary

D3419.id12116.diff

diff --git a/cypress/integration/deposit-admin.spec.js b/cypress/integration/deposit-admin.spec.js
--- a/cypress/integration/deposit-admin.spec.js
+++ b/cypress/integration/deposit-admin.spec.js
@@ -18,8 +18,8 @@
'reception_date': '2020-05-18T13:48:27Z',
'status': 'done',
'status_detail': null,
- 'swh_id': 'swh:1:dir:ef04a768',
- 'swh_id_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/'
+ 'swhid': 'swh:1:dir:ef04a768',
+ 'swhid_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/'
},
{
'id': 613,
@@ -27,8 +27,8 @@
'reception_date': '2020-05-18T11:20:16Z',
'status': 'done',
'status_detail': null,
- 'swh_id': 'swh:1:dir:181417fb',
- 'swh_id_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/'
+ 'swhid': 'swh:1:dir:181417fb',
+ 'swhid_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/'
},
{
'id': 612,
@@ -36,8 +36,8 @@
'reception_date': '2020-05-18T11:20:16Z',
'status': 'rejected',
'status_detail': 'incomplete deposit!',
- 'swh_id': null,
- 'swh_id_context': null
+ 'swhid': null,
+ 'swhid_context': null
}
];
// those are computed from the
@@ -93,8 +93,8 @@
expect(deposit.external_id).to.be.equal(responseDeposit['external_id']);
expect(deposit.status).to.be.equal(responseDeposit['status']);
expect(deposit.status_detail).to.be.equal(responseDeposit['status_detail']);
- expect(deposit.swh_id).to.be.equal(responseDeposit['swh_id']);
- expect(deposit.swh_id_context).to.be.equal(responseDeposit['swh_id_context']);
+ expect(deposit.swhid).to.be.equal(responseDeposit['swhid']);
+ expect(deposit.swhid_context).to.be.equal(responseDeposit['swhid_context']);
let expectedOrigin = expectedOrigins[deposit.id];
// ensure it's in the dom
@@ -111,9 +111,9 @@
}
// those are hidden by default
- if (deposit.swh_id !== null) {
- cy.contains(deposit.swh_id).should('not.be.visible');
- cy.contains(deposit.swh_id_context).should('not.be.visible');
+ if (deposit.swhid !== null) {
+ cy.contains(deposit.swhid).should('not.be.visible');
+ cy.contains(deposit.swhid_context).should('not.be.visible');
}
});
@@ -139,9 +139,9 @@
}
// those are hidden by default, so now they should be visible
- if (deposit.swh_id !== null) {
- cy.contains(deposit.swh_id).should('be.visible');
- cy.contains(deposit.swh_id_context).should('be.visible');
+ if (deposit.swhid !== null) {
+ cy.contains(deposit.swhid).should('be.visible');
+ cy.contains(deposit.swhid_context).should('be.visible');
}
});
});
diff --git a/cypress/integration/origin-search.spec.js b/cypress/integration/origin-search.spec.js
--- a/cypress/integration/origin-search.spec.js
+++ b/cypress/integration/origin-search.spec.js
@@ -105,8 +105,8 @@
cy.route({
method: 'GET',
- url: `${this.Urls.api_1_resolve_swh_pid('').slice(0, -1)}**`
- }).as('resolvePid');
+ url: `${this.Urls.api_1_resolve_swhid('').slice(0, -1)}**`
+ }).as('resolveSWHID');
cy.route({
method: 'GET',
@@ -120,7 +120,7 @@
cy.wait('@searchOrigin');
- cy.xhrShouldBeCalled('resolvePid', 0);
+ cy.xhrShouldBeCalled('resolveSWHID', 0);
cy.xhrShouldBeCalled('searchOrigin', 1);
});
@@ -341,43 +341,43 @@
});
});
- context('Test valid persistent ids', function() {
+ context('Test valid SWHIDs', function() {
it('should resolve directory', function() {
const redirectUrl = this.Urls.browse_directory(origin.content[0].directory);
- const persistentId = `swh:1:dir:${origin.content[0].directory}`;
+ const swhid = `swh:1:dir:${origin.content[0].directory}`;
- searchShouldRedirect(persistentId, redirectUrl);
+ searchShouldRedirect(swhid, redirectUrl);
});
it('should resolve revision', function() {
const redirectUrl = this.Urls.browse_revision(origin.revisions[0]);
- const persistentId = `swh:1:rev:${origin.revisions[0]}`;
+ const swhid = `swh:1:rev:${origin.revisions[0]}`;
- searchShouldRedirect(persistentId, redirectUrl);
+ searchShouldRedirect(swhid, redirectUrl);
});
it('should resolve snapshot', function() {
const redirectUrl = this.Urls.browse_snapshot_directory(origin.snapshot);
- const persistentId = `swh:1:snp:${origin.snapshot}`;
+ const swhid = `swh:1:snp:${origin.snapshot}`;
- searchShouldRedirect(persistentId, redirectUrl);
+ searchShouldRedirect(swhid, redirectUrl);
});
it('should resolve content', function() {
const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`);
- const persistentId = `swh:1:cnt:${origin.content[0].sha1git}`;
+ const swhid = `swh:1:cnt:${origin.content[0].sha1git}`;
- searchShouldRedirect(persistentId, redirectUrl);
+ searchShouldRedirect(swhid, redirectUrl);
});
it('should not send request to the search endpoint', function() {
cy.server();
- const persistentId = `swh:1:rev:${origin.revisions[0]}`;
+ const swhid = `swh:1:rev:${origin.revisions[0]}`;
cy.route({
method: 'GET',
- url: this.Urls.api_1_resolve_swh_pid(persistentId)
- }).as('resolvePid');
+ url: this.Urls.api_1_resolve_swhid(swhid)
+ }).as('resolveSWHID');
cy.route({
method: 'GET',
@@ -385,44 +385,44 @@
}).as('searchOrigin');
cy.get('#origins-url-patterns')
- .type(persistentId);
+ .type(swhid);
cy.get('.swh-search-icon')
.click();
- cy.wait('@resolvePid');
+ cy.wait('@resolveSWHID');
- cy.xhrShouldBeCalled('resolvePid', 1);
+ cy.xhrShouldBeCalled('resolveSWHID', 1);
cy.xhrShouldBeCalled('searchOrigin', 0);
});
});
- context('Test invalid persistent ids', function() {
+ context('Test invalid SWHIDs', function() {
it('should show not found for directory', function() {
- const persistentId = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`;
+ const swhid = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`;
const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`;
- searchShouldShowNotFound(persistentId, msg);
+ searchShouldShowNotFound(swhid, msg);
});
it('should show not found for snapshot', function() {
- const persistentId = `swh:1:snp:${this.unarchivedRepo.snapshot}`;
+ const swhid = `swh:1:snp:${this.unarchivedRepo.snapshot}`;
const msg = `Snapshot with id ${this.unarchivedRepo.snapshot} not found!`;
- searchShouldShowNotFound(persistentId, msg);
+ searchShouldShowNotFound(swhid, msg);
});
it('should show not found for revision', function() {
- const persistentId = `swh:1:rev:${this.unarchivedRepo.revision}`;
+ const swhid = `swh:1:rev:${this.unarchivedRepo.revision}`;
const msg = `Revision with sha1_git ${this.unarchivedRepo.revision} not found.`;
- searchShouldShowNotFound(persistentId, msg);
+ searchShouldShowNotFound(swhid, msg);
});
it('should show not found for content', function() {
- const persistentId = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`;
+ const swhid = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`;
const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`;
- searchShouldShowNotFound(persistentId, msg);
+ searchShouldShowNotFound(swhid, msg);
});
});
diff --git a/cypress/integration/persistent-identifiers.spec.js b/cypress/integration/persistent-identifiers.spec.js
--- a/cypress/integration/persistent-identifiers.spec.js
+++ b/cypress/integration/persistent-identifiers.spec.js
@@ -45,38 +45,38 @@
testsData = [
{
'objectType': 'content',
- 'objectPids': [cntSWHIDWithContext, cntSWHID],
+ 'objectSWHIDs': [cntSWHIDWithContext, cntSWHID],
'badgeUrl': this.Urls.swh_badge('content', swhids.content.object_id),
- 'badgePidUrl': this.Urls.swh_badge_pid(cntSWHID),
- 'browseUrl': this.Urls.browse_swh_id(cntSWHIDWithContext)
+ 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(cntSWHID),
+ 'browseUrl': this.Urls.browse_swhid(cntSWHIDWithContext)
},
{
'objectType': 'directory',
- 'objectPids': [dirSWHIDWithContext, dirSWHID],
+ 'objectSWHIDs': [dirSWHIDWithContext, dirSWHID],
'badgeUrl': this.Urls.swh_badge('directory', swhids.directory.object_id),
- 'badgePidUrl': this.Urls.swh_badge_pid(dirSWHID),
- 'browseUrl': this.Urls.browse_swh_id(dirSWHIDWithContext)
+ 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(dirSWHID),
+ 'browseUrl': this.Urls.browse_swhid(dirSWHIDWithContext)
},
{
'objectType': 'release',
- 'objectPids': [relSWHIDWithContext, relSWHID],
+ 'objectSWHIDs': [relSWHIDWithContext, relSWHID],
'badgeUrl': this.Urls.swh_badge('release', swhids.release.object_id),
- 'badgePidUrl': this.Urls.swh_badge_pid(relSWHID),
- 'browseUrl': this.Urls.browse_swh_id(relSWHIDWithContext)
+ 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(relSWHID),
+ 'browseUrl': this.Urls.browse_swhid(relSWHIDWithContext)
},
{
'objectType': 'revision',
- 'objectPids': [revSWHIDWithContext, revSWHID],
+ 'objectSWHIDs': [revSWHIDWithContext, revSWHID],
'badgeUrl': this.Urls.swh_badge('revision', swhids.revision.object_id),
- 'badgePidUrl': this.Urls.swh_badge_pid(revSWHID),
- 'browseUrl': this.Urls.browse_swh_id(revSWHIDWithContext)
+ 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(revSWHID),
+ 'browseUrl': this.Urls.browse_swhid(revSWHIDWithContext)
},
{
'objectType': 'snapshot',
- 'objectPids': [snpSWHIDWithContext, snpSWHID],
+ 'objectSWHIDs': [snpSWHIDWithContext, snpSWHID],
'badgeUrl': this.Urls.swh_badge('snapshot', swhids.snapshot.object_id),
- 'badgePidUrl': this.Urls.swh_badge_pid(snpSWHID),
- 'browseUrl': this.Urls.browse_swh_id(snpSWHIDWithContext)
+ 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(snpSWHID),
+ 'browseUrl': this.Urls.browse_swhid(snpSWHIDWithContext)
}
];
@@ -110,15 +110,15 @@
.click();
for (let td of testsData) {
- cy.get(`a[href="#swh-id-tab-${td.objectType}"]`)
+ cy.get(`a[href="#swhid-tab-${td.objectType}"]`)
.click();
- cy.get(`#swh-id-tab-${td.objectType}`)
+ cy.get(`#swhid-tab-${td.objectType}`)
.should('be.visible');
- cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
- .contains(td.objectPids[0])
- .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0]));
+ cy.get(`#swhid-tab-${td.objectType} .swhid`)
+ .contains(td.objectSWHIDs[0])
+ .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0]));
}
@@ -130,26 +130,26 @@
for (let td of testsData) {
- cy.get(`a[href="#swh-id-tab-${td.objectType}"]`)
+ cy.get(`a[href="#swhid-tab-${td.objectType}"]`)
.click();
- cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
- .contains(td.objectPids[0])
- .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0]));
+ cy.get(`#swhid-tab-${td.objectType} .swhid`)
+ .contains(td.objectSWHIDs[0])
+ .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0]));
- cy.get(`#swh-id-tab-${td.objectType} .swh-id-option`)
+ cy.get(`#swhid-tab-${td.objectType} .swhid-option`)
.click();
- cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
- .contains(td.objectPids[1])
- .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[1]));
+ cy.get(`#swhid-tab-${td.objectType} .swhid`)
+ .contains(td.objectSWHIDs[1])
+ .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[1]));
- cy.get(`#swh-id-tab-${td.objectType} .swh-id-option`)
+ cy.get(`#swhid-tab-${td.objectType} .swhid-option`)
.click();
- cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
- .contains(td.objectPids[0])
- .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0]));
+ cy.get(`#swhid-tab-${td.objectType} .swhid`)
+ .contains(td.objectSWHIDs[0])
+ .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0]));
}
});
@@ -161,13 +161,13 @@
const originBadgeUrl = this.Urls.swh_badge('origin', origin.url);
for (let td of testsData) {
- cy.get(`a[href="#swh-id-tab-${td.objectType}"]`)
+ cy.get(`a[href="#swhid-tab-${td.objectType}"]`)
.click();
- cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`)
+ cy.get(`#swhid-tab-${td.objectType} .swh-badge-origin`)
.should('have.attr', 'src', originBadgeUrl);
- cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`)
+ cy.get(`#swhid-tab-${td.objectType} .swh-badge-${td.objectType}`)
.should('have.attr', 'src', td.badgeUrl);
}
@@ -180,10 +180,10 @@
.click();
for (let td of testsData) {
- cy.get(`a[href="#swh-id-tab-${td.objectType}"]`)
+ cy.get(`a[href="#swhid-tab-${td.objectType}"]`)
.click();
- cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`)
+ cy.get(`#swhid-tab-${td.objectType} .swh-badge-origin`)
.click()
.wait(500);
@@ -197,14 +197,14 @@
.click()
.wait(500);
- cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`)
+ cy.get(`#swhid-tab-${td.objectType} .swh-badge-${td.objectType}`)
.click()
.wait(500);
for (let badgeType of ['html', 'md', 'rst']) {
cy.get(`.modal .swh-badge-${badgeType}`)
.contains(`${urlPrefix}${td.browseUrl}`)
- .contains(`${urlPrefix}${td.badgePidUrl}`);
+ .contains(`${urlPrefix}${td.badgeSWHIDUrl}`);
}
cy.get('.modal.show .close')
@@ -220,7 +220,7 @@
for (let testData of testsData) {
assert.isTrue(swhIdsContext.hasOwnProperty(testData.objectType));
assert.equal(swhIdsContext[testData.objectType].swhid,
- testData.objectPids.slice(-1)[0]);
+ testData.objectSWHIDs.slice(-1)[0]);
}
});
});
diff --git a/docs/developers-info.rst b/docs/developers-info.rst
--- a/docs/developers-info.rst
+++ b/docs/developers-info.rst
@@ -117,7 +117,7 @@
* :mod:`swh.web.browse.views.content`: Implementation of endpoints for browsing contents.
* :mod:`swh.web.browse.views.directory`: Implementation of endpoints for browsing directories.
* :mod:`swh.web.browse.views.identifiers`: Implementation of endpoints for browsing objects
- through persistent identifiers.
+ through :ref:`persistent-identifiers`.
* :mod:`swh.web.browse.views.origin`: Implementation of endpoints for browsing origins.
* :mod:`swh.web.browse.views.person`: Implementation of endpoints for browsing persons.
* :mod:`swh.web.browse.views.release`: Implementation of endpoints for browsing releases.
diff --git a/docs/uri-scheme-api-identifiers.rst b/docs/uri-scheme-api-identifiers.rst
--- a/docs/uri-scheme-api-identifiers.rst
+++ b/docs/uri-scheme-api-identifiers.rst
@@ -1,7 +1,7 @@
Persistent identifiers
----------------------
-.. autosimple:: swh.web.api.views.identifiers.api_resolve_swh_pid
+.. autosimple:: swh.web.api.views.identifiers.api_resolve_swhid
-.. autosimple:: swh.web.api.views.identifiers.api_swh_pid_known
+.. autosimple:: swh.web.api.views.identifiers.api_swhid_known
diff --git a/docs/uri-scheme-identifiers.rst b/docs/uri-scheme-identifiers.rst
--- a/docs/uri-scheme-identifiers.rst
+++ b/docs/uri-scheme-identifiers.rst
@@ -2,19 +2,18 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A subset of Software Heritage objects (contents, directories, releases and
-revisions) can be browsed using :ref:`SWHIDs <persistent-identifiers>`. Those
+revisions) can be browsed using :ref:`persistent-identifiers`. Those
identifiers are guaranteed to remain stable (persistent) over time.
-.. http:get:: /(swh_id)/
+.. http:get:: /(swhid)/
- End point to browse Software Heritage objects using their persistent identifiers.
+ Endpoint to browse Software Heritage objects using their SWHIDs.
A redirection to the adequate HTML view will be performed when
reaching it.
- :param string swh_id: a persistent identifier for a Software Heritage
- object, or SWHID (see :ref:`persistent identifiers
- <persistent-identifiers>` to learn more about its syntax)
+ :param string swhid: a SoftWare Heritage persistent IDentifier
+ object, or SWHID (see :ref:`persistent-identifiers` to learn more about its syntax)
:resheader Location: the redirection URL for browsing the Software Heritage object
associated to the provided identifier
:statuscode 302: no error
diff --git a/swh/web/admin/deposit.py b/swh/web/admin/deposit.py
--- a/swh/web/admin/deposit.py
+++ b/swh/web/admin/deposit.py
@@ -96,8 +96,8 @@
"reception_date": d["reception_date"],
"status": d["status"],
"status_detail": d["status_detail"],
- "swh_id": d["swh_id"],
- "swh_id_context": d["swh_id_context"],
+ "swhid": d["swh_id"],
+ "swhid_context": d["swh_id_context"],
}
for d in data
]
diff --git a/swh/web/api/views/identifiers.py b/swh/web/api/views/identifiers.py
--- a/swh/web/api/views/identifiers.py
+++ b/swh/web/api/views/identifiers.py
@@ -8,42 +8,38 @@
from swh.web.common import service
from swh.web.common.exc import LargePayloadExc
from swh.web.common.identifiers import (
- resolve_swh_persistent_id,
- get_persistent_identifier,
- group_swh_persistent_identifiers,
+ resolve_swhid,
+ get_swhid,
+ group_swhids,
)
-@api_route(r"/resolve/(?P<swh_id>.*)/", "api-1-resolve-swh-pid")
+@api_route(r"/resolve/(?P<swhid>.*)/", "api-1-resolve-swhid")
@api_doc("/resolve/")
@format_docstring()
-def api_resolve_swh_pid(request, swh_id):
+def api_resolve_swhid(request, swhid):
"""
- .. http:get:: /api/1/resolve/(swh_id)/
+ .. http:get:: /api/1/resolve/(swhid)/
- Resolve a Software Heritage persistent identifier.
+ Resolve :ref:`persistent-identifiers`.
- Try to resolve a provided `persistent identifier
- <https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html>`_
- into an url for browsing the pointed archive object. If the provided
- identifier is valid, the existence of the object in the archive
- will also be checked.
+ Try to resolve a provided SWHID into an url for browsing the
+ pointed archive object. If the provided identifier is valid,
+ the existence of the object in the archive will also be checked.
- :param string swh_id: a Software Heritage persistent identifier
+ :param string swhid: a SoftWare Heritage persistent IDentifier
:>json string browse_url: the url for browsing the pointed object
- :>json object metadata: object holding optional parts of the
- persistent identifier
- :>json string namespace: the persistent identifier namespace
+ :>json object metadata: object holding optional parts of the SWHID
+ :>json string namespace: the SWHID namespace
:>json string object_id: the hash identifier of the pointed object
:>json string object_type: the type of the pointed object
- :>json number scheme_version: the scheme version of the persistent
- identifier
+ :>json number scheme_version: the scheme version of the SWHID
{common_headers}
:statuscode 200: no error
- :statuscode 400: an invalid persistent identifier has been provided
+ :statuscode 400: an invalid SWHID has been provided
:statuscode 404: the pointed object does not exist in the archive
**Example:**
@@ -52,69 +48,65 @@
:swh_web_api:`resolve/swh:1:rev:96db9023b881d7cd9f379b0c154650d6c108e9a3;origin=https://github.com/openssl/openssl/`
"""
- # try to resolve the provided pid
- swh_id_resolved = resolve_swh_persistent_id(swh_id)
+ # try to resolve the provided swhid
+ swhid_resolved = resolve_swhid(swhid)
# id is well-formed, now check that the pointed
# object is present in the archive, NotFoundExc
# will be raised otherwise
- swh_id_parsed = swh_id_resolved["swh_id_parsed"]
- object_type = swh_id_parsed.object_type
- object_id = swh_id_parsed.object_id
+ swhid_parsed = swhid_resolved["swhid_parsed"]
+ object_type = swhid_parsed.object_type
+ object_id = swhid_parsed.object_id
service.lookup_object(object_type, object_id)
# id is well-formed and the pointed object exists
- swh_id_data = swh_id_parsed._asdict()
- swh_id_data["browse_url"] = request.build_absolute_uri(
- swh_id_resolved["browse_url"]
- )
- return swh_id_data
+ swhid_data = swhid_parsed._asdict()
+ swhid_data["browse_url"] = request.build_absolute_uri(swhid_resolved["browse_url"])
+ return swhid_data
@api_route(r"/known/", "api-1-known", methods=["POST"])
@api_doc("/known/")
@format_docstring()
-def api_swh_pid_known(request):
+def api_swhid_known(request):
"""
.. http:post:: /api/1/known/
Check if a list of objects are present in the Software Heritage
archive.
- The objects to check existence must be provided using Software Heritage
- `persistent identifiers
- <https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html>`_.
+ The objects to check existence must be provided using
+ :ref:`persistent-identifiers`.
- :<jsonarr string -: input array of Software Heritage persistent
- identifiers, its length can not exceed 1000.
+ :<jsonarr string -: input array of SWHIDs, its length can not exceed 1000.
- :>json object <swh_pid>: an object whose keys are input persistent
- identifiers and values objects with the following keys:
+ :>json object <swhid>: an object whose keys are input SWHIDs and values
+ objects with the following keys:
* **known (bool)**: whether the object was found
{common_headers}
:statuscode 200: no error
- :statuscode 400: an invalid persistent identifier was provided
- :statuscode 413: the input array of persistent identifiers is too large
+ :statuscode 400: an invalid SWHID was provided
+ :statuscode 413: the input array of SWHIDs is too large
"""
limit = 1000
if len(request.data) > limit:
raise LargePayloadExc(
- "The maximum number of PIDs this endpoint can " "receive is %s" % limit
+ "The maximum number of SWHIDs this endpoint can receive is %s" % limit
)
- persistent_ids = [get_persistent_identifier(pid) for pid in request.data]
+ swhids = [get_swhid(swhid) for swhid in request.data]
- response = {str(pid): {"known": False} for pid in persistent_ids}
+ response = {str(swhid): {"known": False} for swhid in swhids}
- # group pids by their type
- pids_by_type = group_swh_persistent_identifiers(persistent_ids)
+ # group swhids by their type
+ swhids_by_type = group_swhids(swhids)
# search for hashes not present in the storage
- missing_hashes = service.lookup_missing_hashes(pids_by_type)
+ missing_hashes = service.lookup_missing_hashes(swhids_by_type)
- for pid in persistent_ids:
- if pid.object_id not in missing_hashes:
- response[str(pid)]["known"] = True
+ for swhid in swhids:
+ if swhid.object_id not in missing_hashes:
+ response[str(swhid)]["known"] = True
return response
diff --git a/swh/web/assets/src/bundles/admin/deposit.js b/swh/web/assets/src/bundles/admin/deposit.js
--- a/swh/web/assets/src/bundles/admin/deposit.js
+++ b/swh/web/assets/src/bundles/admin/deposit.js
@@ -8,7 +8,7 @@
function genSwhLink(data, type) {
if (type === 'display') {
if (data && data.startsWith('swh')) {
- let browseUrl = Urls.browse_swh_id(data);
+ let browseUrl = Urls.browse_swhid(data);
return `<a href="${browseUrl}">${data}</a>`;
}
}
@@ -51,8 +51,8 @@
name: 'id'
},
{
- data: 'swh_id_context',
- name: 'swh_id_context',
+ data: 'swhid_context',
+ name: 'swhid_context',
render: (data, type, row) => {
if (data && type === 'display') {
let originPattern = ';origin=';
@@ -102,8 +102,8 @@
visible: false
},
{
- data: 'swh_id',
- name: 'swh_id',
+ data: 'swhid',
+ name: 'swhid',
render: (data, type, row) => {
return genSwhLink(data, type);
},
@@ -111,8 +111,8 @@
visible: false
},
{
- data: 'swh_id_context',
- name: 'swh_id_context',
+ data: 'swhid_context',
+ name: 'swhid_context',
render: (data, type, row) => {
return genSwhLink(data, type);
},
diff --git a/swh/web/assets/src/bundles/browse/index.js b/swh/web/assets/src/bundles/browse/index.js
--- a/swh/web/assets/src/bundles/browse/index.js
+++ b/swh/web/assets/src/bundles/browse/index.js
@@ -15,4 +15,4 @@
export * from './snapshot-navigation';
export * from './origin-search';
export * from './browse-utils';
-export * from './swh-ids-utils';
+export * from './swhid-utils';
diff --git a/swh/web/assets/src/bundles/browse/origin-search.js b/swh/web/assets/src/bundles/browse/origin-search.js
--- a/swh/web/assets/src/bundles/browse/origin-search.js
+++ b/swh/web/assets/src/bundles/browse/origin-search.js
@@ -156,18 +156,18 @@
inSearch = true;
if (searchQueryText.startsWith('swh:')) {
// searchQueryText may be a PID so sending search queries to PID resolve endpoint
- let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText);
- fetch(resolvePidUrl)
+ let resolveSWHIDUrl = Urls.api_1_resolve_swhid(searchQueryText);
+ fetch(resolveSWHIDUrl)
.then(handleFetchError)
.then(response => response.json())
.then(data => {
- // pid has been successfully resolved,
+ // SWHID has been successfully resolved,
// so redirect to browse page
window.location = data.browse_url;
})
.catch(response => {
// display a useful error message if the input
- // looks like a swh pid
+ // looks like a SWHID
response.json().then(data => {
$('#swh-origin-search-results').hide();
$('.swh-search-pagination').hide();
diff --git a/swh/web/assets/src/bundles/browse/swh-ids-utils.js b/swh/web/assets/src/bundles/browse/swhid-utils.js
rename from swh/web/assets/src/bundles/browse/swh-ids-utils.js
rename to swh/web/assets/src/bundles/browse/swhid-utils.js
--- a/swh/web/assets/src/bundles/browse/swh-ids-utils.js
+++ b/swh/web/assets/src/bundles/browse/swhid-utils.js
@@ -18,7 +18,7 @@
export function swhIdContextOptionToggled(event) {
event.stopPropagation();
- let swhIdElt = $(event.target).closest('.swh-id-ui').find('.swh-id');
+ let swhIdElt = $(event.target).closest('.swhid-ui').find('.swhid');
let swhIdWithContext = $(event.target).data('swhid-with-context');
let currentSwhId = swhIdElt.text();
if ($(event.target).prop('checked')) {
@@ -36,7 +36,7 @@
}
function addLinesInfo() {
- let swhIdElt = $('#swh-id-tab-content').find('.swh-id');
+ let swhIdElt = $('#swhid-tab-content').find('.swhid');
let currentSwhId = swhIdElt.text();
let lines = [];
let linesPart = ';lines=';
@@ -53,7 +53,7 @@
linesPart += '-' + lines[1];
}
- if ($('#swh-id-context-option-content').prop('checked')) {
+ if ($('#swhid-context-option-content').prop('checked')) {
currentSwhId = currentSwhId.replace(/;lines=\d+-*\d*/g, '');
if (lines.length > 0) {
currentSwhId += linesPart;
@@ -65,16 +65,16 @@
}
$(document).ready(() => {
- new ClipboardJS('.btn-swh-id-copy', {
+ new ClipboardJS('.btn-swhid-copy', {
text: trigger => {
- let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text();
+ let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text();
return swhId;
}
});
- new ClipboardJS('.btn-swh-id-url-copy', {
+ new ClipboardJS('.btn-swhid-url-copy', {
text: trigger => {
- let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text();
+ let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text();
return window.location.origin + '/' + swhId + '/';
}
});
@@ -105,7 +105,7 @@
// set the tab visible once the close animation is terminated
$('#swh-identifiers').css('display', 'block');
- $('.swh-id-context-option').trigger('click');
+ $('.swhid-context-option').trigger('click');
// highlighted code lines changed
$(window).on('hashchange', () => {
diff --git a/swh/web/assets/src/bundles/webapp/badges.js b/swh/web/assets/src/bundles/webapp/badges.js
--- a/swh/web/assets/src/bundles/webapp/badges.js
+++ b/swh/web/assets/src/bundles/webapp/badges.js
@@ -5,20 +5,20 @@
* See top-level LICENSE file for more information
*/
-export function showBadgeInfoModal(objectType, objectPid) {
+export function showBadgeInfoModal(objectType, objectSWHID) {
let badgeImageUrl;
let badgeLinkUrl;
if (objectType === 'origin') {
- badgeImageUrl = Urls.swh_badge(objectType, objectPid);
- badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectPid}`;
+ badgeImageUrl = Urls.swh_badge(objectType, objectSWHID);
+ badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectSWHID}`;
} else {
- const pos = objectPid.indexOf(';');
+ const pos = objectSWHID.indexOf(';');
if (pos !== -1) {
- badgeImageUrl = Urls.swh_badge_pid(objectPid.slice(0, pos));
+ badgeImageUrl = Urls.swh_badge_swhid(objectSWHID.slice(0, pos));
} else {
- badgeImageUrl = Urls.swh_badge_pid(objectPid);
+ badgeImageUrl = Urls.swh_badge_swhid(objectSWHID);
}
- badgeLinkUrl = Urls.browse_swh_id(objectPid);
+ badgeLinkUrl = Urls.browse_swhid(objectSWHID);
}
let urlPrefix = `${window.location.protocol}//${window.location.hostname}`;
if (window.location.port) {
diff --git a/swh/web/assets/src/bundles/webapp/webapp-utils.js b/swh/web/assets/src/bundles/webapp/webapp-utils.js
--- a/swh/web/assets/src/bundles/webapp/webapp-utils.js
+++ b/swh/web/assets/src/bundles/webapp/webapp-utils.js
@@ -307,11 +307,11 @@
// SWHID metadata contain the following keys:
// * object_type: type of archived object
// * object_id: sha1 object identifier
-// * swhid: SWH persistent identifier without contextual info
-// * swhid_url: URL to resolve SWH persistent identifier without contextual info
+// * swhid: SWHID without contextual info
+// * swhid_url: URL to resolve SWHID without contextual info
// * context: object describing SWHID context
-// * swhid_with_context: SWH persistent identifier with contextual info
-// * swhid_with_context_url: URL to resolve SWH persistent identifier with contextual info
+// * swhid_with_context: SWHID with contextual info
+// * swhid_with_context_url: URL to resolve SWHID with contextual info
let swhidsContext_ = {};
export function setSwhIdsContext(swhidsContext) {
diff --git a/swh/web/assets/src/bundles/webapp/webapp.css b/swh/web/assets/src/bundles/webapp/webapp.css
--- a/swh/web/assets/src/bundles/webapp/webapp.css
+++ b/swh/web/assets/src/bundles/webapp/webapp.css
@@ -394,11 +394,11 @@
padding-top: 4px;
}
-.swh-id {
+.swhid {
white-space: pre-wrap;
}
-.swh-id .swh-id-option {
+.swhid .swhid-option {
display: inline-block;
margin-right: 5px;
line-height: 1rem;
diff --git a/swh/web/browse/identifiers.py b/swh/web/browse/identifiers.py
--- a/swh/web/browse/identifiers.py
+++ b/swh/web/browse/identifiers.py
@@ -5,20 +5,19 @@
from django.shortcuts import redirect
-from swh.web.common.identifiers import resolve_swh_persistent_id
+from swh.web.common.identifiers import resolve_swhid
from swh.web.common.exc import handle_view_exception
-def swh_id_browse(request, swh_id):
+def swhid_browse(request, swhid):
"""
- Django view enabling to browse the archive using
- :ref:`SWHIDs <persistent-identifiers>`.
+ Django view enabling to browse the archive using :ref:`<persistent-identifiers>`.
- The url that points to it is :http:get:`/(swh_id)/`.
+ The url that points to it is :http:get:`/(swhid)/`.
"""
try:
- swh_id_resolved = resolve_swh_persistent_id(swh_id, query_params=request.GET)
+ swhid_resolved = resolve_swhid(swhid, query_params=request.GET)
except Exception as exc:
return handle_view_exception(request, exc)
- return redirect(swh_id_resolved["browse_url"])
+ return redirect(swhid_resolved["browse_url"])
diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py
--- a/swh/web/browse/snapshot_context.py
+++ b/swh/web/browse/snapshot_context.py
@@ -17,7 +17,7 @@
import sentry_sdk
from swh.model.identifiers import (
- persistent_identifier,
+ swhid,
snapshot_identifier,
CONTENT,
DIRECTORY,
@@ -499,7 +499,7 @@
is_empty = sum(snapshot_sizes.values()) == 0
- swh_snp_id = persistent_identifier("snapshot", snapshot_id)
+ swh_snp_id = swhid("snapshot", snapshot_id)
if visit_info:
timestamp = format_utc_iso_date(visit_info["date"])
diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py
--- a/swh/web/browse/urls.py
+++ b/swh/web/browse/urls.py
@@ -14,7 +14,7 @@
import swh.web.browse.views.snapshot # noqa
from swh.web.browse.browseurls import BrowseUrls
-from swh.web.browse.identifiers import swh_id_browse
+from swh.web.browse.identifiers import swhid_browse
from swh.web.common.utils import reverse
@@ -49,7 +49,7 @@
url(r"^vault/$", _browse_vault_view, name="browse-vault"),
# for backward compatibility
url(r"^origin/save/$", _browse_origin_save_view, name="browse-origin-save"),
- url(r"^(?P<swh_id>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", swh_id_browse),
+ url(r"^(?P<swhid>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", swhid_browse),
]
urlpatterns += BrowseUrls.get_url_patterns()
diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py
--- a/swh/web/browse/views/revision.py
+++ b/swh/web/browse/views/revision.py
@@ -13,7 +13,7 @@
from django.utils.safestring import mark_safe
from swh.model.identifiers import (
- persistent_identifier,
+ swhid,
CONTENT,
DIRECTORY,
REVISION,
@@ -281,7 +281,7 @@
revision_log_data = format_log_entries(revision_log, per_page)
- swh_rev_id = persistent_identifier("revision", sha1_git)
+ swh_rev_id = swhid("revision", sha1_git)
return render(
request,
diff --git a/swh/web/common/exc.py b/swh/web/common/exc.py
--- a/swh/web/common/exc.py
+++ b/swh/web/common/exc.py
@@ -50,8 +50,7 @@
class LargePayloadExc(Exception):
"""The input size is too large.
- Example: Asking to resolve 10000 persistent identifier when the limit
- is 1000.
+ Example: Asking to resolve 10000 SWHIDs when the limit is 1000.
"""
pass
diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py
--- a/swh/web/common/identifiers.py
+++ b/swh/web/common/identifiers.py
@@ -4,7 +4,7 @@
# See top-level LICENSE file for more information
from urllib.parse import quote
-from typing import Any, Dict, Iterable, List, Optional
+from typing import cast, Any, Dict, Iterable, List, Optional
from typing_extensions import TypedDict
from django.http import QueryDict
@@ -12,15 +12,15 @@
from swh.model.exceptions import ValidationError
from swh.model.hashutil import hash_to_bytes
from swh.model.identifiers import (
- persistent_identifier,
- parse_persistent_identifier,
+ swhid,
+ parse_swhid,
CONTENT,
DIRECTORY,
ORIGIN,
RELEASE,
REVISION,
SNAPSHOT,
- PersistentId,
+ SWHID,
)
from swh.web.common import service
@@ -35,73 +35,72 @@
from swh.web.common.utils import reverse
-def get_swh_persistent_id(
+def gen_swhid(
object_type: str,
object_id: str,
scheme_version: int = 1,
metadata: SWHIDContext = {},
) -> str:
"""
- Returns the persistent identifier for a swh object based on:
+ Returns the SoftWare Heritage persistent IDentifier for a swh object based on:
* the object type
* the object id
- * the swh identifiers scheme version
+ * the SWHID scheme version
Args:
object_type: the swh object type
(content/directory/release/revision/snapshot)
object_id: the swh object id (hexadecimal representation
of its hash value)
- scheme_version: the scheme version of the swh
- persistent identifiers
+ scheme_version: the scheme version of the SWHIDs
Returns:
- the swh object persistent identifier
+ the SWHID of the object
Raises:
BadInputExc: if the provided parameters do not enable to
generate a valid identifier
"""
try:
- swh_id = persistent_identifier(object_type, object_id, scheme_version, metadata)
- except ValidationError as e:
- raise BadInputExc(
- "Invalid object (%s) for swh persistent id. %s" % (object_id, e)
+ obj_swhid = swhid(
+ object_type, object_id, scheme_version, cast(Dict[str, Any], metadata)
)
+ except ValidationError as e:
+ raise BadInputExc("Invalid object (%s) for SWHID. %s" % (object_id, e))
else:
- return swh_id
+ return obj_swhid
-class ResolvedPersistentId(TypedDict):
+class ResolvedSWHID(TypedDict):
"""parsed SWHID with context"""
- swh_id_parsed: PersistentId
+ swhid_parsed: SWHID
"""URL to browse object according to SWHID context"""
browse_url: Optional[str]
-def resolve_swh_persistent_id(
- swh_id: str, query_params: Optional[QueryParameters] = None
-) -> ResolvedPersistentId:
+def resolve_swhid(
+ swhid: str, query_params: Optional[QueryParameters] = None
+) -> ResolvedSWHID:
"""
- Try to resolve a Software Heritage persistent id into an url for
+ Try to resolve a SoftWare Heritage persistent IDentifier into an url for
browsing the targeted object.
Args:
- swh_id: a Software Heritage persistent identifier
+ swhid: a SoftWare Heritage persistent IDentifier
query_params: optional dict filled with
query parameters to append to the browse url
Returns:
a dict with the following keys:
- * **swh_id_parsed**: the parsed identifier
+ * **swhid_parsed**: the parsed identifier
* **browse_url**: the url for browsing the targeted object
"""
- swh_id_parsed = get_persistent_identifier(swh_id)
- object_type = swh_id_parsed.object_type
- object_id = swh_id_parsed.object_id
+ swhid_parsed = get_swhid(swhid)
+ object_type = swhid_parsed.object_type
+ object_id = swhid_parsed.object_id
browse_url = None
url_args = {}
query_dict = QueryDict("", mutable=True)
@@ -113,16 +112,14 @@
for k in sorted(query_params.keys()):
query_dict[k] = query_params[k]
- if "origin" in swh_id_parsed.metadata:
- query_dict["origin_url"] = swh_id_parsed.metadata["origin"]
+ if "origin" in swhid_parsed.metadata:
+ query_dict["origin_url"] = swhid_parsed.metadata["origin"]
- if "anchor" in swh_id_parsed.metadata:
- anchor_swhid_parsed = get_persistent_identifier(
- swh_id_parsed.metadata["anchor"]
- )
+ if "anchor" in swhid_parsed.metadata:
+ anchor_swhid_parsed = get_swhid(swhid_parsed.metadata["anchor"])
- if "path" in swh_id_parsed.metadata and swh_id_parsed.metadata["path"] != "/":
- query_dict["path"] = swh_id_parsed.metadata["path"]
+ if "path" in swhid_parsed.metadata and swhid_parsed.metadata["path"] != "/":
+ query_dict["path"] = swhid_parsed.metadata["path"]
if anchor_swhid_parsed:
directory = ""
if anchor_swhid_parsed.object_type == DIRECTORY:
@@ -136,7 +133,7 @@
revision = service.lookup_revision(release["target"])
directory = revision["directory"]
if object_type == CONTENT:
- if "origin" not in swh_id_parsed.metadata:
+ if "origin" not in swhid_parsed.metadata:
# when no origin context, content objects need to have their
# path prefixed by root directory id for proper breadcrumbs display
query_dict["path"] = directory + query_dict["path"]
@@ -149,9 +146,9 @@
query_dict["path"] = query_dict["path"][1:-1]
# snapshot context
- if "visit" in swh_id_parsed.metadata:
+ if "visit" in swhid_parsed.metadata:
- snp_swhid_parsed = get_persistent_identifier(swh_id_parsed.metadata["visit"])
+ snp_swhid_parsed = get_swhid(swhid_parsed.metadata["visit"])
if snp_swhid_parsed.object_type != SNAPSHOT:
raise BadInputExc("Visit must be a snapshot SWHID.")
query_dict["snapshot"] = snp_swhid_parsed.object_id
@@ -202,14 +199,13 @@
elif object_type == ORIGIN:
raise BadInputExc(
(
- "Origin PIDs (Persistent Identifiers) are not "
- "publicly resolvable because they are for "
+ "Origin SWHIDs are not publicly resolvable because they are for "
"internal usage only"
)
)
- if "lines" in swh_id_parsed.metadata and process_lines:
- lines = swh_id_parsed.metadata["lines"].split("-")
+ if "lines" in swhid_parsed.metadata and process_lines:
+ lines = swhid_parsed.metadata["lines"].split("-")
fragment += "#L" + lines[0]
if len(lines) > 1:
fragment += "-L" + lines[1]
@@ -222,48 +218,44 @@
+ fragment
)
- return ResolvedPersistentId(swh_id_parsed=swh_id_parsed, browse_url=browse_url)
+ return ResolvedSWHID(swhid_parsed=swhid_parsed, browse_url=browse_url)
-def get_persistent_identifier(persistent_id: str) -> PersistentId:
- """Check if a persistent identifier is valid.
+def get_swhid(swhid: str) -> SWHID:
+ """Check if a SWHID is valid and return it parsed.
Args:
- persistent_id: A string representing a Software Heritage
- persistent identifier.
+ swhid: a SoftWare Heritage persistent IDentifier.
Raises:
- BadInputExc: if the provided persistent identifier can
- not be parsed.
+ BadInputExc: if the provided SWHID can not be parsed.
Return:
- A persistent identifier object.
+ A parsed SWHID.
"""
try:
- pid_object = parse_persistent_identifier(persistent_id)
+ swhid_parsed = parse_swhid(swhid)
except ValidationError as ve:
raise BadInputExc("Error when parsing identifier: %s" % " ".join(ve.messages))
else:
- return pid_object
+ return swhid_parsed
-def group_swh_persistent_identifiers(
- persistent_ids: Iterable[PersistentId],
-) -> Dict[str, List[bytes]]:
+def group_swhids(swhids: Iterable[SWHID],) -> Dict[str, List[bytes]]:
"""
- Groups many Software Heritage persistent identifiers into a
+ Groups many SoftWare Heritage persistent IDentifiers into a
dictionary depending on their type.
Args:
- persistent_ids: an iterable of Software Heritage persistent
- identifier objects
+ swhids: an iterable of SoftWare Heritage persistent
+ IDentifier objects
Returns:
A dictionary with:
- keys: persistent identifier types
- values: persistent identifiers id
+ keys: object types
+ values: object hashes
"""
- pids_by_type: Dict[str, List[bytes]] = {
+ swhids_by_type: Dict[str, List[bytes]] = {
CONTENT: [],
DIRECTORY: [],
REVISION: [],
@@ -271,12 +263,12 @@
SNAPSHOT: [],
}
- for pid in persistent_ids:
- obj_id = pid.object_id
- obj_type = pid.object_type
- pids_by_type[obj_type].append(hash_to_bytes(obj_id))
+ for obj_swhid in swhids:
+ obj_id = obj_swhid.object_id
+ obj_type = obj_swhid.object_type
+ swhids_by_type[obj_type].append(hash_to_bytes(obj_id))
- return pids_by_type
+ return swhids_by_type
def get_swhids_info(
@@ -285,8 +277,7 @@
extra_context: Optional[Dict[str, Any]] = None,
) -> List[SWHIDInfo]:
"""
- Returns a list of dict containing info related to persistent
- identifiers of swh objects.
+ Returns a list of dict containing info related to SWHIDs of objects.
Args:
swh_objects: an iterable of dict describing archived objects
@@ -296,7 +287,7 @@
the objects
Returns:
- a list of dict containing persistent identifiers info
+ a list of dict containing SWHIDs info
"""
swhids_info = []
@@ -323,16 +314,16 @@
snapshot_context["origin_info"]["url"], safe="/?:@&"
)
if object_type != SNAPSHOT:
- swhid_context["visit"] = get_swh_persistent_id(
+ swhid_context["visit"] = gen_swhid(
SNAPSHOT, snapshot_context["snapshot_id"]
)
if object_type in (CONTENT, DIRECTORY):
if snapshot_context["release_id"] is not None:
- swhid_context["anchor"] = get_swh_persistent_id(
+ swhid_context["anchor"] = gen_swhid(
RELEASE, snapshot_context["release_id"]
)
elif snapshot_context["revision_id"] is not None:
- swhid_context["anchor"] = get_swh_persistent_id(
+ swhid_context["anchor"] = gen_swhid(
REVISION, snapshot_context["revision_id"]
)
@@ -343,9 +334,7 @@
and extra_context["revision"]
and "anchor" not in swhid_context
):
- swhid_context["anchor"] = get_swh_persistent_id(
- REVISION, extra_context["revision"]
- )
+ swhid_context["anchor"] = gen_swhid(REVISION, extra_context["revision"])
elif (
extra_context
and "root_directory" in extra_context
@@ -356,7 +345,7 @@
or extra_context["root_directory"] != object_id
)
):
- swhid_context["anchor"] = get_swh_persistent_id(
+ swhid_context["anchor"] = gen_swhid(
DIRECTORY, extra_context["root_directory"]
)
path = None
@@ -367,17 +356,17 @@
if path:
swhid_context["path"] = quote(path, safe="/?:@&")
- swhid = get_swh_persistent_id(object_type, object_id)
- swhid_url = reverse("browse-swh-id", url_args={"swh_id": swhid})
+ swhid = gen_swhid(object_type, object_id)
+ swhid_url = reverse("browse-swhid", url_args={"swhid": swhid})
swhid_with_context = None
swhid_with_context_url = None
if swhid_context:
- swhid_with_context = get_swh_persistent_id(
+ swhid_with_context = gen_swhid(
object_type, object_id, metadata=swhid_context
)
swhid_with_context_url = reverse(
- "browse-swh-id", url_args={"swh_id": swhid_with_context}
+ "browse-swhid", url_args={"swhid": swhid_with_context}
)
swhids_info.append(
diff --git a/swh/web/common/service.py b/swh/web/common/service.py
--- a/swh/web/common/service.py
+++ b/swh/web/common/service.py
@@ -1286,20 +1286,20 @@
)
-def lookup_missing_hashes(grouped_pids: Dict[str, List[bytes]]) -> Set[str]:
+def lookup_missing_hashes(grouped_swhids: Dict[str, List[bytes]]) -> Set[str]:
"""Lookup missing Software Heritage persistent identifier hash, using
batch processing.
Args:
A dictionary with:
- keys: persistent identifier type
- values: list(bytes) persistent identifier hash
+ keys: object types
+ values: object hashes
Returns:
A set(hexadecimal) of the hashes not found in the storage
"""
missing_hashes = []
- for obj_type, obj_ids in grouped_pids.items():
+ for obj_type, obj_ids in grouped_swhids.items():
if obj_type == CONTENT:
missing_hashes.append(storage.content_missing_per_sha1_git(obj_ids))
elif obj_type == DIRECTORY:
diff --git a/swh/web/misc/badges.py b/swh/web/misc/badges.py
--- a/swh/web/misc/badges.py
+++ b/swh/web/misc/badges.py
@@ -14,8 +14,8 @@
from swh.model.exceptions import ValidationError
from swh.model.identifiers import (
- persistent_identifier,
- parse_persistent_identifier,
+ swhid,
+ parse_swhid,
CONTENT,
DIRECTORY,
ORIGIN,
@@ -25,7 +25,7 @@
)
from swh.web.common import service
from swh.web.common.exc import BadInputExc, NotFoundExc
-from swh.web.common.identifiers import resolve_swh_persistent_id
+from swh.web.common.identifiers import resolve_swhid
from swh.web.common.utils import reverse
@@ -65,7 +65,7 @@
request: HttpRequest,
object_type: str,
object_id: str,
- object_pid: Optional[str] = "",
+ object_swhid: Optional[str] = "",
) -> HttpResponse:
"""
Generate a Software Heritage badge for a given object type and id.
@@ -77,8 +77,7 @@
or *snapshot*
object_id: The id of the swh object, either an url for origin
type or a *sha1* for other object types
- object_pid: If provided, the object persistent
- identifier will not be recomputed
+ object_swhid: If provided, the object SWHID will not be recomputed
Returns:
HTTP response with content type *image/svg+xml* containing the SVG
@@ -98,21 +97,21 @@
"browse-origin", query_params={"origin_url": object_id}
)
else:
- # when pid is provided, object type and id will be parsed
+ # when SWHID is provided, object type and id will be parsed
# from it
- if object_pid:
- parsed_pid = parse_persistent_identifier(object_pid)
- object_type = parsed_pid.object_type
- object_id = parsed_pid.object_id
+ if object_swhid:
+ parsed_swhid = parse_swhid(object_swhid)
+ object_type = parsed_swhid.object_type
+ object_id = parsed_swhid.object_id
swh_object = service.lookup_object(object_type, object_id)
- if object_pid:
- right_text = object_pid
+ if object_swhid:
+ right_text = object_swhid
else:
- right_text = persistent_identifier(object_type, object_id)
+ right_text = swhid(object_type, object_id)
- whole_link = resolve_swh_persistent_id(right_text)["browse_url"]
- # remove pid metadata if any for badge text
- if object_pid:
+ whole_link = resolve_swhid(right_text)["browse_url"]
+ # remove SWHID metadata if any for badge text
+ if object_swhid:
right_text = right_text.split(";")[0]
# use release name for badge text
if object_type == RELEASE:
@@ -138,21 +137,20 @@
return HttpResponse(badge_data, content_type="image/svg+xml")
-def _swh_badge_pid(request: HttpRequest, object_pid: str) -> HttpResponse:
+def _swh_badge_swhid(request: HttpRequest, object_swhid: str) -> HttpResponse:
"""
- Generate a Software Heritage badge for a given object persistent
- identifier.
+ Generate a Software Heritage badge for a given object SWHID.
Args:
request (django.http.HttpRequest): input http request
- object_pid (str): A swh object persistent identifier
+ object_swhid (str): a SWHID of an archived object
Returns:
django.http.HttpResponse: An http response with content type
*image/svg+xml* containing the SVG badge data. If any error
occurs, a status code of 400 will be returned.
"""
- return _swh_badge(request, "", "", object_pid)
+ return _swh_badge(request, "", "", object_swhid)
urlpatterns = [
@@ -162,8 +160,8 @@
name="swh-badge",
),
url(
- r"^badge/(?P<object_pid>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$",
- _swh_badge_pid,
- name="swh-badge-pid",
+ r"^badge/(?P<object_swhid>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$",
+ _swh_badge_swhid,
+ name="swh-badge-swhid",
),
]
diff --git a/swh/web/templates/includes/origin-search-form.html b/swh/web/templates/includes/origin-search-form.html
--- a/swh/web/templates/includes/origin-search-form.html
+++ b/swh/web/templates/includes/origin-search-form.html
@@ -7,26 +7,26 @@
<form class="form-horizontal" id="swh-search-origins">
<div class="input-group">
- <input class="form-control" placeholder="Enter a persistent id to resolve or string pattern(s) to search for in origin urls" type="text" id="origins-url-patterns"/>
+ <input class="form-control" placeholder="Enter a SWHID to resolve or string pattern(s) to search for in origin urls" type="text" id="origins-url-patterns"/>
<div class="input-group-append">
<button class="btn btn-primary" type="submit"><i class="swh-search-icon mdi mdi-24px mdi-magnify" aria-hidden="true"></i></button>
</div>
</div>
- <div class="custom-control custom-checkbox swh-id-option">
+ <div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input" value="option-origins-with-visit" type="checkbox"
id="swh-search-origins-with-visit" checked>
<label class="custom-control-label font-weight-normal" for="swh-search-origins-with-visit">
only show origins visited at least once
</label>
</div>
- <div class="custom-control custom-checkbox swh-id-option">
+ <div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input" value="option-filter-empty-visits" type="checkbox"
id="swh-filter-empty-visits" checked>
<label class="custom-control-label font-weight-normal" for="swh-filter-empty-visits">
filter out origins with no archived content
</label>
</div>
- <div class="custom-control custom-checkbox swh-id-option">
+ <div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input" value="option-filter-empty-visits" type="checkbox"
id="swh-search-origin-metadata">
<label class="custom-control-label font-weight-normal" for="swh-search-origin-metadata">
diff --git a/swh/web/templates/includes/show-swh-ids.html b/swh/web/templates/includes/show-swhids.html
rename from swh/web/templates/includes/show-swh-ids.html
rename to swh/web/templates/includes/show-swhids.html
--- a/swh/web/templates/includes/show-swh-ids.html
+++ b/swh/web/templates/includes/show-swhids.html
@@ -17,25 +17,28 @@
{% endif %}
<div id="swh-identifiers-content">
<p>
- To reference or cite the objects present in the Software Heritage archive, permalinks based on <a href="https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html">persistent identifiers</a>
+ To reference or cite the objects present in the Software Heritage archive, permalinks based on
+ <a href="https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html">
+ SoftWare Heritage persistent IDentifiers (SWHIDs)
+ </a>
must be used instead of copying and pasting the url from the address bar of the browser (as there is no guarantee the current URI
scheme will remain the same over time).
<br/>
<br/>
- Select below a type of object currently browsed in order to display its associated persistent identifier and permalink.
+ Select below a type of object currently browsed in order to display its associated SWHID and permalink.
</p>
<ul class="nav nav-pills ml-auto p-2">
{% for swhid_info in swhids_info %}
{% if forloop.first %}
<li class="nav-item">
- <a class="nav-link active" href="#swh-id-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
+ <a class="nav-link active" href="#swhid-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
<i class="{{ swh_object_icons|key_value:swhid_info.object_type }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type }}
</a>
</li>
{% else %}
<li class="nav-item">
- <a class="nav-link" href="#swh-id-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
+ <a class="nav-link" href="#swhid-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
<i class="{{ swh_object_icons|key_value:swhid_info.object_type }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type }}
</a>
</li>
@@ -46,12 +49,12 @@
<div class="tab-content">
{% for swhid_info in swhids_info %}
{% if forloop.first %}
- <div class="tab-pane active" id="swh-id-tab-{{ swhid_info.object_type }}">
+ <div class="tab-pane active" id="swhid-tab-{{ swhid_info.object_type }}">
{% else %}
- <div class="tab-pane" id="swh-id-tab-{{ swhid_info.object_type }}">
+ <div class="tab-pane" id="swhid-tab-{{ swhid_info.object_type }}">
{% endif %}
<div class="card">
- <div class="card-body swh-id-ui">
+ <div class="card-body swhid-ui">
{% if snapshot_context and snapshot_context.origin_info %}
<img class="swh-badge swh-badge-origin" src="{% url 'swh-badge' 'origin' snapshot_context.origin_info.url %}"
onclick="swh.webapp.showBadgeInfoModal('origin', '{{ snapshot_context.origin_info.url }}')"
@@ -59,29 +62,29 @@
{% endif %}
{% if swhid_info.object_id %}
<img class="swh-badge swh-badge-{{ swhid_info.object_type }}" src="{% url 'swh-badge' swhid_info.object_type swhid_info.object_id %}"
- onclick="swh.webapp.showBadgeInfoModal('{{ swhid_info.object_type }}', $(this).parent().find('.swh-id').text())"
+ onclick="swh.webapp.showBadgeInfoModal('{{ swhid_info.object_type }}', $(this).parent().find('.swhid').text())"
title="Click to display badge integration info">
- <pre><a class="swh-id" id="{{ swhid_info.swhid }}" href="{{ swhid_info.swhid_url }}">{{ swhid_info.swhid }}</a></pre>
+ <pre><a class="swhid" id="{{ swhid_info.swhid }}" href="{{ swhid_info.swhid_url }}">{{ swhid_info.swhid }}</a></pre>
{% endif %}
{% if swhid_info.swhid_with_context is not None %}
<div class="float-left">
- <form id="swh-id-options">
- <div class="custom-control custom-checkbox swh-id-option">
- <input class="custom-control-input swh-id-context-option" value="option-origin" type="checkbox"
- id="swh-id-context-option-{{ swhid_info.object_type }}"
+ <form id="swhid-options">
+ <div class="custom-control custom-checkbox swhid-option">
+ <input class="custom-control-input swhid-context-option" value="option-origin" type="checkbox"
+ id="swhid-context-option-{{ swhid_info.object_type }}"
data-swhid-with-context="{{ swhid_info.swhid_with_context }}"
onclick="swh.browse.swhIdContextOptionToggled(event)">
- <label class="custom-control-label font-weight-normal" for="swh-id-context-option-{{ swhid_info.object_type }}">Add contextual information</label>
+ <label class="custom-control-label font-weight-normal" for="swhid-context-option-{{ swhid_info.object_type }}">Add contextual information</label>
</div>
</form>
</div>
{% endif %}
<div class="float-right">
- <button type="button" class="btn btn-default btn-sm btn-swh-id-copy"
- title="Copy persistent identifier to clipboard">
+ <button type="button" class="btn btn-default btn-sm btn-swhid-copy"
+ title="Copy SWHID to clipboard">
<i class="mdi mdi-content-copy mdi-fw" aria-hidden="true"></i>Copy identifier
- <button type="button" class="btn btn-default btn-sm btn-swh-id-url-copy"
- title="Copy url resolving the persistent identifier to clipboard">
+ <button type="button" class="btn btn-default btn-sm btn-swhid-url-copy"
+ title="Copy url resolving the SWHID to clipboard">
<i class="mdi mdi-content-copy mdi-fw" aria-hidden="true"></i>Copy permalink
</button>
</div>
diff --git a/swh/web/templates/includes/snapshot-context.html b/swh/web/templates/includes/snapshot-context.html
--- a/swh/web/templates/includes/snapshot-context.html
+++ b/swh/web/templates/includes/snapshot-context.html
@@ -20,7 +20,7 @@
{% endif %}
{% else %}
<i class="{{ swh_object_icons.snapshot }} mdi-fw" aria-hidden="true" title="Snapshot"></i>
- <a class="swh-heading-color" href="{% url 'browse-swh-id' snapshot_context.snapshot_swhid %}">
+ <a class="swh-heading-color" href="{% url 'browse-swhid' snapshot_context.snapshot_swhid %}">
{{ snapshot_context.snapshot_swhid }}
</a>
{% endif %}
diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html
--- a/swh/web/templates/includes/top-navigation.html
+++ b/swh/web/templates/includes/top-navigation.html
@@ -118,7 +118,7 @@
</div>
</div>
-{% include "includes/show-swh-ids.html" %}
+{% include "includes/show-swhids.html" %}
<script>
var snapshotContext = false;
diff --git a/swh/web/tests/api/test_apidoc.py b/swh/web/tests/api/test_apidoc.py
--- a/swh/web/tests/api/test_apidoc.py
+++ b/swh/web/tests/api/test_apidoc.py
@@ -359,10 +359,10 @@
Endpoint documentation
- :<jsonarr string -: Input array of pids
+ :<jsonarr string -: Input array of SWHIDs
- :>json object <swh_pid>: an object whose keys are input persistent
- identifiers and values objects with the following keys:
+ :>json object <swhid>: an object whose keys are input SWHIDs
+ and values objects with the following keys:
* **known (bool)**: whether the object was found
@@ -384,7 +384,7 @@
" </dt>\n"
' <dd class="col col-md-9">\n'
" <p>\n"
- " Input array of pids\n"
+ " Input array of SWHIDs\n"
" </p>\n"
" </dd>\n"
"</dl>\n"
@@ -408,9 +408,9 @@
" <li>\n"
" <p>\n"
" <strong>\n"
- " &lt;swh_pid&gt; (object)\n"
+ " &lt;swhid&gt; (object)\n"
" </strong>\n"
- " : an object whose keys are input persistent identifiers"
+ " : an object whose keys are input SWHIDs"
" and values objects with the following keys:\n"
" </p>\n"
" <blockquote>\n"
diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py
--- a/swh/web/tests/api/views/test_identifiers.py
+++ b/swh/web/tests/api/views/test_identifiers.py
@@ -25,7 +25,7 @@
@given(origin(), content(), directory(), release(), revision(), snapshot())
-def test_swh_id_resolve_success(
+def test_swhid_resolve_success(
api_client, origin, content, directory, release, revision, snapshot
):
@@ -37,8 +37,8 @@
("snp", SNAPSHOT, snapshot),
):
- swh_id = "swh:1:%s:%s;origin=%s" % (obj_type_short, obj_id, origin["url"])
- url = reverse("api-1-resolve-swh-pid", url_args={"swh_id": swh_id})
+ swhid = "swh:1:%s:%s;origin=%s" % (obj_type_short, obj_id, origin["url"])
+ url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid})
resp = api_client.get(url)
@@ -69,10 +69,10 @@
assert resp.data == expected_result
-def test_swh_id_resolve_invalid(api_client):
+def test_swhid_resolve_invalid(api_client):
rev_id_invalid = "96db9023b8_foo_50d6c108e9a3"
- swh_id = "swh:1:rev:%s" % rev_id_invalid
- url = reverse("api-1-resolve-swh-pid", url_args={"swh_id": swh_id})
+ swhid = "swh:1:rev:%s" % rev_id_invalid
+ url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid})
resp = api_client.get(url)
@@ -86,7 +86,7 @@
unknown_revision(),
unknown_snapshot(),
)
-def test_swh_id_resolve_not_found(
+def test_swhid_resolve_not_found(
api_client,
unknown_content,
unknown_directory,
@@ -103,9 +103,9 @@
("snp", unknown_snapshot),
):
- swh_id = "swh:1:%s:%s" % (obj_type_short, obj_id)
+ swhid = "swh:1:%s:%s" % (obj_type_short, obj_id)
- url = reverse("api-1-resolve-swh-pid", url_args={"swh_id": swh_id})
+ url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid})
resp = api_client.get(url)
@@ -113,21 +113,21 @@
def test_swh_origin_id_not_resolvable(api_client):
- ori_pid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb"
- url = reverse("api-1-resolve-swh-pid", url_args={"swh_id": ori_pid})
+ ori_swhid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb"
+ url = reverse("api-1-resolve-swhid", url_args={"swhid": ori_swhid})
resp = api_client.get(url)
assert resp.status_code == 400, resp.data
@given(content(), directory())
-def test_api_known_swhpid_some_present(api_client, content, directory):
+def test_api_known_swhid_some_present(api_client, content, directory):
content_ = "swh:1:cnt:%s" % content["sha1_git"]
directory_ = "swh:1:dir:%s" % directory
unknown_revision_ = "swh:1:rev:%s" % random_sha1()
unknown_release_ = "swh:1:rel:%s" % random_sha1()
unknown_snapshot_ = "swh:1:snp:%s" % random_sha1()
- input_pids = [
+ input_swhids = [
content_,
directory_,
unknown_revision_,
@@ -138,7 +138,7 @@
url = reverse("api-1-known")
resp = api_client.post(
- url, data=input_pids, format="json", HTTP_ACCEPT="application/json"
+ url, data=input_swhids, format="json", HTTP_ACCEPT="application/json"
)
assert resp.status_code == 200, resp.data
@@ -152,35 +152,35 @@
}
-def test_api_known_invalid_swhpid(api_client):
- invalid_pid_sha1 = ["swh:1:cnt:8068d0075010b590762c6cb5682ed53cb3c13de;"]
- invalid_pid_type = ["swh:1:cnn:8068d0075010b590762c6cb5682ed53cb3c13deb"]
+def test_api_known_invalid_swhid(api_client):
+ invalid_swhid_sha1 = ["swh:1:cnt:8068d0075010b590762c6cb5682ed53cb3c13de;"]
+ invalid_swhid_type = ["swh:1:cnn:8068d0075010b590762c6cb5682ed53cb3c13deb"]
url = reverse("api-1-known")
resp = api_client.post(
- url, data=invalid_pid_sha1, format="json", HTTP_ACCEPT="application/json"
+ url, data=invalid_swhid_sha1, format="json", HTTP_ACCEPT="application/json"
)
assert resp.status_code == 400, resp.data
resp2 = api_client.post(
- url, data=invalid_pid_type, format="json", HTTP_ACCEPT="application/json"
+ url, data=invalid_swhid_type, format="json", HTTP_ACCEPT="application/json"
)
assert resp2.status_code == 400, resp.data
def test_api_known_raises_large_payload_error(api_client):
- random_pid = "swh:1:cnt:8068d0075010b590762c6cb5682ed53cb3c13deb"
+ random_swhid = "swh:1:cnt:8068d0075010b590762c6cb5682ed53cb3c13deb"
limit = 10000
- err_msg = "The maximum number of PIDs this endpoint can receive is 1000"
+ err_msg = "The maximum number of SWHIDs this endpoint can receive is 1000"
- pids = [random_pid for i in range(limit)]
+ swhids = [random_swhid for i in range(limit)]
url = reverse("api-1-known")
resp = api_client.post(
- url, data=pids, format="json", HTTP_ACCEPT="application/json"
+ url, data=swhids, format="json", HTTP_ACCEPT="application/json"
)
assert resp.status_code == 413, resp.data
diff --git a/swh/web/tests/browse/test_snapshot_context.py b/swh/web/tests/browse/test_snapshot_context.py
--- a/swh/web/tests/browse/test_snapshot_context.py
+++ b/swh/web/tests/browse/test_snapshot_context.py
@@ -14,7 +14,7 @@
_get_release,
)
from swh.web.browse.utils import gen_revision_url
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.origin_visits import get_origin_visit, get_origin_visits
from swh.web.common.typing import (
SnapshotBranchInfo,
@@ -125,7 +125,7 @@
branches_url = reverse("browse-snapshot-branches", url_args=url_args)
releases_url = reverse("browse-snapshot-releases", url_args=url_args)
is_empty = not branches and not releases
- snapshot_swhid = get_swh_persistent_id("snapshot", snapshot)
+ snapshot_swhid = gen_swhid("snapshot", snapshot)
snapshot_sizes = {"revision": len(branches), "release": len(releases)}
expected = SnapshotContext(
@@ -216,7 +216,7 @@
"browse-origin-visits", query_params={"origin_url": kwargs["origin_url"]}
)
is_empty = not branches and not releases
- snapshot_swhid = get_swh_persistent_id("snapshot", snapshot)
+ snapshot_swhid = gen_swhid("snapshot", snapshot)
snapshot_sizes = {"revision": len(branches), "release": len(releases)}
visit_info["url"] = reverse(
diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py
--- a/swh/web/tests/browse/views/test_content.py
+++ b/swh/web/tests/browse/views/test_content.py
@@ -17,7 +17,7 @@
_re_encode_content,
)
from swh.web.common.exc import NotFoundExc
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import gen_path_info, reverse
from swh.web.tests.django_asserts import (
assert_contains,
@@ -63,8 +63,8 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
- swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -88,8 +88,8 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
- swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -107,8 +107,8 @@
assert resp.status_code == 200
assert_template_used(resp, "browse/content.html")
- swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
- swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id_url)
assert_contains(resp, escape(content_display["content_data"]))
@@ -182,14 +182,12 @@
path = path.replace(root_dir_sha1 + "/", "").replace(filename, "")
swhid_context = {
- "anchor": get_swh_persistent_id(DIRECTORY, root_dir_sha1),
+ "anchor": gen_swhid(DIRECTORY, root_dir_sha1),
"path": f"/{path}{filename}",
}
- swh_cnt_id = get_swh_persistent_id(
- CONTENT, content["sha1_git"], metadata=swhid_context
- )
- swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ swh_cnt_id = gen_swhid(CONTENT, content["sha1_git"], metadata=swhid_context)
+ swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -442,43 +440,38 @@
assert_contains(resp, directory_file["name"])
assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>")
- cnt_swhid = get_swh_persistent_id(
+ cnt_swhid = gen_swhid(
CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(REVISION, branch_info["revision"]),
"path": f"/{directory_file['name']}",
},
)
assert_contains(resp, cnt_swhid)
- dir_swhid = get_swh_persistent_id(
+ dir_swhid = gen_swhid(
DIRECTORY,
directory,
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(REVISION, branch_info["revision"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
- rev_swhid = get_swh_persistent_id(
+ rev_swhid = gen_swhid(
REVISION,
branch_info["revision"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rev_swhid)
- snp_swhid = get_swh_persistent_id(
- SNAPSHOT, snapshot, metadata={"origin": origin["url"],},
- )
+ snp_swhid = gen_swhid(SNAPSHOT, snapshot, metadata={"origin": origin["url"],},)
assert_contains(resp, snp_swhid)
@@ -513,53 +506,45 @@
assert_contains(resp, directory_file["name"])
assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>")
- cnt_swhid = get_swh_persistent_id(
+ cnt_swhid = gen_swhid(
CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(RELEASE, release_info["id"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(RELEASE, release_info["id"]),
"path": f"/{directory_file['name']}",
},
)
assert_contains(resp, cnt_swhid)
- dir_swhid = get_swh_persistent_id(
+ dir_swhid = gen_swhid(
DIRECTORY,
release_info["directory"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(RELEASE, release_info["id"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(RELEASE, release_info["id"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
- rev_swhid = get_swh_persistent_id(
+ rev_swhid = gen_swhid(
REVISION,
release_info["target"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rev_swhid)
- rel_swhid = get_swh_persistent_id(
+ rel_swhid = gen_swhid(
RELEASE,
release_info["id"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rel_swhid)
- snp_swhid = get_swh_persistent_id(
- SNAPSHOT, snapshot, metadata={"origin": origin["url"],},
- )
+ snp_swhid = gen_swhid(SNAPSHOT, snapshot, metadata={"origin": origin["url"],},)
assert_contains(resp, snp_swhid)
diff --git a/swh/web/tests/browse/views/test_directory.py b/swh/web/tests/browse/views/test_directory.py
--- a/swh/web/tests/browse/views/test_directory.py
+++ b/swh/web/tests/browse/views/test_directory.py
@@ -10,7 +10,7 @@
from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT
from swh.web.browse.snapshot_context import process_snapshot_branches
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import gen_path_info, reverse
from swh.web.tests.django_asserts import assert_contains, assert_template_used
from swh.web.tests.strategies import (
@@ -76,7 +76,7 @@
resp = client.get(url)
assert resp.status_code == 200
- assert_contains(resp, 'id="swh-id-context-option-directory"')
+ assert_contains(resp, 'id="swhid-context-option-directory"')
@given(origin_with_multiple_visits())
@@ -112,31 +112,26 @@
assert_contains(resp, directory_subdir["name"])
assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>")
- dir_swhid = get_swh_persistent_id(
+ dir_swhid = gen_swhid(
DIRECTORY,
directory_subdir["target"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(REVISION, branch_info["revision"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
- rev_swhid = get_swh_persistent_id(
+ rev_swhid = gen_swhid(
REVISION,
branch_info["revision"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rev_swhid)
- snp_swhid = get_swh_persistent_id(
- SNAPSHOT, snapshot, metadata={"origin": origin["url"],},
- )
+ snp_swhid = gen_swhid(SNAPSHOT, snapshot, metadata={"origin": origin["url"],},)
assert_contains(resp, snp_swhid)
@@ -172,41 +167,33 @@
assert_contains(resp, directory_subdir["name"])
assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>")
- dir_swhid = get_swh_persistent_id(
+ dir_swhid = gen_swhid(
DIRECTORY,
directory_subdir["target"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(RELEASE, release_info["id"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(RELEASE, release_info["id"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
- rev_swhid = get_swh_persistent_id(
+ rev_swhid = gen_swhid(
REVISION,
release_info["target"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rev_swhid)
- rel_swhid = get_swh_persistent_id(
+ rel_swhid = gen_swhid(
RELEASE,
release_info["id"],
- metadata={
- "origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- },
+ metadata={"origin": origin["url"], "visit": gen_swhid(SNAPSHOT, snapshot),},
)
assert_contains(resp, rel_swhid)
- snp_swhid = get_swh_persistent_id(
- SNAPSHOT, snapshot, metadata={"origin": origin["url"],},
- )
+ snp_swhid = gen_swhid(SNAPSHOT, snapshot, metadata={"origin": origin["url"],},)
assert_contains(resp, snp_swhid)
@@ -310,21 +297,21 @@
assert_contains(resp, "vault-cook-directory")
- swh_dir_id = get_swh_persistent_id(DIRECTORY, directory_entries[0]["dir_id"])
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id = gen_swhid(DIRECTORY, directory_entries[0]["dir_id"])
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
swhid_context = {}
if root_directory_sha1 != directory_entries[0]["dir_id"]:
- swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1)
+ swhid_context["anchor"] = gen_swhid(DIRECTORY, root_directory_sha1)
swhid_context["path"] = f"/{path}/" if path else "/"
if root_directory_sha1 != directory_entries[0]["dir_id"]:
- swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1)
+ swhid_context["anchor"] = gen_swhid(DIRECTORY, root_directory_sha1)
- swh_dir_id = get_swh_persistent_id(
+ swh_dir_id = gen_swhid(
DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
)
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
diff --git a/swh/web/tests/browse/views/test_identifiers.py b/swh/web/tests/browse/views/test_identifiers.py
--- a/swh/web/tests/browse/views/test_identifiers.py
+++ b/swh/web/tests/browse/views/test_identifiers.py
@@ -8,7 +8,7 @@
from hypothesis import given
from swh.model.identifiers import CONTENT, REVISION, SNAPSHOT
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import reverse
from swh.web.tests.django_asserts import assert_contains
from swh.web.tests.strategies import (
@@ -20,14 +20,14 @@
snapshot,
)
-swh_id_prefix = "swh:1:"
+swhid_prefix = "swh:1:"
@given(content())
def test_content_id_browse(client, content):
cnt_sha1_git = content["sha1_git"]
- swh_id = swh_id_prefix + "cnt:" + cnt_sha1_git
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "cnt:" + cnt_sha1_git
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
query_string = "sha1_git:" + cnt_sha1_git
content_browse_url = reverse(
@@ -42,8 +42,8 @@
@given(directory())
def test_directory_id_browse(client, directory):
- swh_id = swh_id_prefix + "dir:" + directory
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "dir:" + directory
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
directory_browse_url = reverse("browse-directory", url_args={"sha1_git": directory})
@@ -55,8 +55,8 @@
@given(revision())
def test_revision_id_browse(client, revision):
- swh_id = swh_id_prefix + "rev:" + revision
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "rev:" + revision
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
revision_browse_url = reverse("browse-revision", url_args={"sha1_git": revision})
@@ -67,9 +67,7 @@
query_params = {"origin_url": "https://github.com/user/repo"}
- url = reverse(
- "browse-swh-id", url_args={"swh_id": swh_id}, query_params=query_params
- )
+ url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params)
revision_browse_url = reverse(
"browse-revision", url_args={"sha1_git": revision}, query_params=query_params
@@ -82,8 +80,8 @@
@given(release())
def test_release_id_browse(client, release):
- swh_id = swh_id_prefix + "rel:" + release
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "rel:" + release
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
release_browse_url = reverse("browse-release", url_args={"sha1_git": release})
@@ -94,9 +92,7 @@
query_params = {"origin_url": "https://github.com/user/repo"}
- url = reverse(
- "browse-swh-id", url_args={"swh_id": swh_id}, query_params=query_params
- )
+ url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params)
release_browse_url = reverse(
"browse-release", url_args={"sha1_git": release}, query_params=query_params
@@ -109,8 +105,8 @@
@given(snapshot())
def test_snapshot_id_browse(client, snapshot):
- swh_id = swh_id_prefix + "snp:" + snapshot
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "snp:" + snapshot
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
snapshot_browse_url = reverse("browse-snapshot", url_args={"snapshot_id": snapshot})
@@ -121,9 +117,7 @@
query_params = {"origin_url": "https://github.com/user/repo"}
- url = reverse(
- "browse-swh-id", url_args={"swh_id": swh_id}, query_params=query_params
- )
+ url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params)
release_browse_url = reverse(
"browse-snapshot", url_args={"snapshot_id": snapshot}, query_params=query_params
@@ -136,8 +130,8 @@
@given(release())
def test_bad_id_browse(client, release):
- swh_id = swh_id_prefix + "foo:" + release
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "foo:" + release
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
resp = client.get(url)
assert resp.status_code == 400
@@ -147,8 +141,8 @@
def test_content_id_optional_parts_browse(client, content):
cnt_sha1_git = content["sha1_git"]
optional_parts = ";lines=4-20;origin=https://github.com/user/repo"
- swh_id = swh_id_prefix + "cnt:" + cnt_sha1_git + optional_parts
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = swhid_prefix + "cnt:" + cnt_sha1_git + optional_parts
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
query_string = "sha1_git:" + cnt_sha1_git
content_browse_url = reverse(
@@ -166,8 +160,8 @@
@given(release())
def test_origin_id_not_resolvable(client, release):
- swh_id = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb"
- url = reverse("browse-swh-id", url_args={"swh_id": swh_id})
+ swhid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb"
+ url = reverse("browse-swhid", url_args={"swhid": swhid})
resp = client.get(url)
assert resp.status_code == 400
@@ -181,25 +175,25 @@
directory_file = random.choice(
[e for e in directory_content if e["type"] == "file"]
)
- legacy_swhid = get_swh_persistent_id(
+ legacy_swhid = gen_swhid(
CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={"origin": origin["url"]},
)
- url = reverse("browse-swh-id", url_args={"swh_id": legacy_swhid})
+ url = reverse("browse-swhid", url_args={"swhid": legacy_swhid})
resp = client.get(url)
assert resp.status_code == 302
resp = client.get(resp["location"])
- swhid = get_swh_persistent_id(
+ swhid = gen_swhid(
CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot),
- "anchor": get_swh_persistent_id(REVISION, revision),
+ "visit": gen_swhid(SNAPSHOT, snapshot),
+ "anchor": gen_swhid(REVISION, revision),
},
)
diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py
--- a/swh/web/tests/browse/views/test_origin.py
+++ b/swh/web/tests/browse/views/test_origin.py
@@ -24,7 +24,7 @@
)
from swh.web.browse.snapshot_context import process_snapshot_branches
from swh.web.common.exc import NotFoundExc
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import (
reverse,
gen_path_info,
@@ -787,15 +787,15 @@
swhid_context = {
"origin": origin["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
- "anchor": get_swh_persistent_id(RELEASE, release_data["id"]),
+ "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(RELEASE, release_data["id"]),
"path": "/",
}
- swh_dir_id = get_swh_persistent_id(
+ swh_dir_id = gen_swhid(
DIRECTORY, revision_data["directory"], metadata=swhid_context
)
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
@@ -1007,15 +1007,13 @@
swhid_context = {
"origin": origin_info["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
- "anchor": get_swh_persistent_id(REVISION, head_rev_id),
+ "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(REVISION, head_rev_id),
"path": f"/{content_path}",
}
- swh_cnt_id = get_swh_persistent_id(
- CONTENT, content["sha1_git"], metadata=swhid_context
- )
- swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ swh_cnt_id = gen_swhid(CONTENT, content["sha1_git"], metadata=swhid_context)
+ swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -1151,15 +1149,15 @@
swhid_context = {
"origin": origin_info["url"],
- "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
- "anchor": get_swh_persistent_id(REVISION, head_rev_id),
+ "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(REVISION, head_rev_id),
"path": f"/{path}" if path else "/",
}
- swh_dir_id = get_swh_persistent_id(
+ swh_dir_id = gen_swhid(
DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
)
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py
--- a/swh/web/tests/browse/views/test_release.py
+++ b/swh/web/tests/browse/views/test_release.py
@@ -8,7 +8,7 @@
from django.utils.html import escape
from hypothesis import given
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import reverse, format_utc_iso_date
from swh.web.tests.django_asserts import assert_contains, assert_template_used
from swh.web.tests.strategies import release, origin_with_releases, unknown_release
@@ -105,8 +105,8 @@
assert_contains(resp, target_type)
assert_contains(resp, '<a href="%s">%s</a>' % (escape(target_url), target))
- swh_rel_id = get_swh_persistent_id("release", release_id)
- swh_rel_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rel_id})
+ swh_rel_id = gen_swhid("release", release_id)
+ swh_rel_id_url = reverse("browse-swhid", url_args={"swhid": swh_rel_id})
assert_contains(resp, swh_rel_id)
assert_contains(resp, swh_rel_id_url)
@@ -116,8 +116,8 @@
)
assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot_id:
- swh_snp_id = get_swh_persistent_id("snapshot", snapshot_id)
- swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id})
+ swh_snp_id = gen_swhid("snapshot", snapshot_id)
+ swh_snp_id_url = reverse("browse-swhid", url_args={"swhid": swh_snp_id})
assert_contains(resp, f'href="{swh_snp_id_url}"')
if release_data["target_type"] == "revision":
diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py
--- a/swh/web/tests/browse/views/test_revision.py
+++ b/swh/web/tests/browse/views/test_revision.py
@@ -9,7 +9,7 @@
from hypothesis import given
from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT
-from swh.web.common.identifiers import get_swh_persistent_id
+from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import reverse, format_utc_iso_date, parse_timestamp
from swh.web.tests.django_asserts import assert_contains, assert_template_used
from swh.web.tests.strategies import origin, revision, unknown_revision, new_origin
@@ -248,21 +248,21 @@
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")
- swh_rev_id = get_swh_persistent_id("revision", revision)
- swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
+ swh_rev_id = gen_swhid("revision", revision)
+ swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
assert_contains(resp, swh_rev_id)
assert_contains(resp, swh_rev_id_url)
- swh_dir_id = get_swh_persistent_id("directory", dir_id)
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id = gen_swhid("directory", dir_id)
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
if origin_url:
assert_contains(resp, "swh-take-new-snapshot")
- swh_rev_id = get_swh_persistent_id(REVISION, revision)
- swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
+ swh_rev_id = gen_swhid(REVISION, revision)
+ swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
if origin_url:
browse_origin_url = reverse(
@@ -270,25 +270,25 @@
)
assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot:
- swh_snp_id = get_swh_persistent_id("snapshot", snapshot["id"])
- swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id})
+ swh_snp_id = gen_swhid("snapshot", snapshot["id"])
+ swh_snp_id_url = reverse("browse-swhid", url_args={"swhid": swh_snp_id})
assert_contains(resp, f'href="{swh_snp_id_url}"')
swhid_context = {}
if origin_url:
swhid_context["origin"] = origin_url
if snapshot:
- swhid_context["visit"] = get_swh_persistent_id(SNAPSHOT, snapshot["id"])
+ swhid_context["visit"] = gen_swhid(SNAPSHOT, snapshot["id"])
- swh_rev_id = get_swh_persistent_id(REVISION, revision, metadata=swhid_context)
- swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
+ swh_rev_id = gen_swhid(REVISION, revision, metadata=swhid_context)
+ swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
assert_contains(resp, swh_rev_id)
assert_contains(resp, swh_rev_id_url)
- swhid_context["anchor"] = get_swh_persistent_id(REVISION, revision)
+ swhid_context["anchor"] = gen_swhid(REVISION, revision)
swhid_context["path"] = "/"
- swh_dir_id = get_swh_persistent_id(DIRECTORY, dir_id, metadata=swhid_context)
- swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ swh_dir_id = gen_swhid(DIRECTORY, dir_id, metadata=swhid_context)
+ swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
diff --git a/swh/web/tests/common/test_identifiers.py b/swh/web/tests/common/test_identifiers.py
--- a/swh/web/tests/common/test_identifiers.py
+++ b/swh/web/tests/common/test_identifiers.py
@@ -16,15 +16,15 @@
RELEASE,
REVISION,
SNAPSHOT,
- PersistentId,
+ SWHID,
)
from swh.web.common.exc import BadInputExc
from swh.web.common.identifiers import (
- get_swh_persistent_id,
- resolve_swh_persistent_id,
- get_persistent_identifier,
- group_swh_persistent_identifiers,
+ gen_swhid,
+ resolve_swhid,
+ get_swhid,
+ group_swhids,
get_swhids_info,
)
from swh.web.browse.snapshot_context import get_snapshot_context
@@ -44,27 +44,25 @@
@given(content())
-def test_get_swh_persistent_id(content):
+def test_gen_swhid(content):
swh_object_type = CONTENT
sha1_git = content["sha1_git"]
- expected_swh_id = "swh:1:cnt:" + sha1_git
+ expected_swhid = "swh:1:cnt:" + sha1_git
- assert get_swh_persistent_id(swh_object_type, sha1_git) == expected_swh_id
+ assert gen_swhid(swh_object_type, sha1_git) == expected_swhid
with pytest.raises(BadInputExc) as e:
- get_swh_persistent_id("foo", sha1_git)
+ gen_swhid("foo", sha1_git)
assert e.match("Invalid object")
with pytest.raises(BadInputExc) as e:
- get_swh_persistent_id(swh_object_type, "not a valid id")
+ gen_swhid(swh_object_type, "not a valid id")
assert e.match("Invalid object")
@given(content(), directory(), release(), revision(), snapshot())
-def test_resolve_swh_persistent_id_legacy(
- content, directory, release, revision, snapshot
-):
+def test_resolve_swhid_legacy(content, directory, release, revision, snapshot):
for obj_type, obj_id in (
(CONTENT, content["sha1_git"]),
(DIRECTORY, directory),
@@ -73,7 +71,7 @@
(SNAPSHOT, snapshot),
):
- swh_pid = get_swh_persistent_id(obj_type, obj_id)
+ swhid = gen_swhid(obj_type, obj_id)
url_args = {}
if obj_type == CONTENT:
@@ -87,18 +85,18 @@
f"browse-{obj_type}", url_args=url_args, query_params=query_params
)
- resolved_pid = resolve_swh_persistent_id(swh_pid, query_params)
+ resolved_swhid = resolve_swhid(swhid, query_params)
- assert isinstance(resolved_pid["swh_id_parsed"], PersistentId)
- assert str(resolved_pid["swh_id_parsed"]) == swh_pid
- assert resolved_pid["browse_url"] == browse_url
+ assert isinstance(resolved_swhid["swhid_parsed"], SWHID)
+ assert str(resolved_swhid["swhid_parsed"]) == swhid
+ assert resolved_swhid["browse_url"] == browse_url
- with pytest.raises(BadInputExc, match="Origin PIDs"):
- resolve_swh_persistent_id(f"swh:1:ori:{random_sha1()}")
+ with pytest.raises(BadInputExc, match="Origin SWHIDs"):
+ resolve_swhid(f"swh:1:ori:{random_sha1()}")
@given(content(), directory(), release(), revision(), snapshot())
-def test_get_persistent_identifier(content, directory, release, revision, snapshot):
+def test_get_swhid(content, directory, release, revision, snapshot):
for obj_type, obj_id in (
(CONTENT, content["sha1_git"]),
(DIRECTORY, directory),
@@ -106,19 +104,19 @@
(REVISION, revision),
(SNAPSHOT, snapshot),
):
- swh_pid = get_swh_persistent_id(obj_type, obj_id)
- swh_parsed_pid = get_persistent_identifier(swh_pid)
+ swhid = gen_swhid(obj_type, obj_id)
+ swh_parsed_swhid = get_swhid(swhid)
- assert isinstance(swh_parsed_pid, PersistentId)
- assert str(swh_parsed_pid) == swh_pid
+ assert isinstance(swh_parsed_swhid, SWHID)
+ assert str(swh_parsed_swhid) == swhid
with pytest.raises(BadInputExc, match="Error when parsing identifier"):
- get_persistent_identifier("foo")
+ get_swhid("foo")
@given(content(), directory(), release(), revision(), snapshot())
-def test_group_persistent_identifiers(content, directory, release, revision, snapshot):
- swh_pids = []
+def test_group_swhids(content, directory, release, revision, snapshot):
+ swhids = []
expected = {}
for obj_type, obj_id in (
(CONTENT, content["sha1_git"]),
@@ -127,14 +125,14 @@
(REVISION, revision),
(SNAPSHOT, snapshot),
):
- swh_pid = get_swh_persistent_id(obj_type, obj_id)
- swh_pid = get_persistent_identifier(swh_pid)
- swh_pids.append(swh_pid)
+ swhid = gen_swhid(obj_type, obj_id)
+ swhid = get_swhid(swhid)
+ swhids.append(swhid)
expected[obj_type] = [hash_to_bytes(obj_id)]
- pid_groups = group_swh_persistent_identifiers(swh_pids)
+ swhid_groups = group_swhids(swhids)
- assert pid_groups == expected
+ assert swhid_groups == expected
@given(directory_with_subdirs())
@@ -145,7 +143,7 @@
snapshot_context=None,
extra_context=extra_context,
)[0]
- swhid_dir_parsed = get_persistent_identifier(swhid["swhid_with_context"])
+ swhid_dir_parsed = get_swhid(swhid["swhid_with_context"])
assert swhid_dir_parsed.metadata == extra_context
@@ -179,9 +177,9 @@
swh_objects_info, snapshot_context=None, extra_context=extra_context,
)
- swhid_dir_parsed = get_persistent_identifier(swhids[0]["swhid_with_context"])
+ swhid_dir_parsed = get_swhid(swhids[0]["swhid_with_context"])
- anchor = get_swh_persistent_id(DIRECTORY, directory)
+ anchor = gen_swhid(DIRECTORY, directory)
assert swhid_dir_parsed.metadata == {
"anchor": anchor,
@@ -189,7 +187,7 @@
}
if dir_subdir_files:
- swhid_cnt_parsed = get_persistent_identifier(swhids[1]["swhid_with_context"])
+ swhid_cnt_parsed = get_swhid(swhids[1]["swhid_with_context"])
assert swhid_cnt_parsed.metadata == {
"anchor": anchor,
@@ -223,9 +221,9 @@
)
assert swhids[0]["context"] == {}
- swhid_dir_parsed = get_persistent_identifier(swhids[1]["swhid_with_context"])
+ swhid_dir_parsed = get_swhid(swhids[1]["swhid_with_context"])
- anchor = get_swh_persistent_id(REVISION, revision)
+ anchor = gen_swhid(REVISION, revision)
assert swhid_dir_parsed.metadata == {
"anchor": anchor,
@@ -233,7 +231,7 @@
}
if dir_entry["type"] == "file":
- swhid_cnt_parsed = get_persistent_identifier(swhids[2]["swhid_with_context"])
+ swhid_cnt_parsed = get_swhid(swhids[2]["swhid_with_context"])
assert swhid_cnt_parsed.metadata == {
"anchor": anchor,
"path": f'/{dir_entry["name"]}',
@@ -353,34 +351,24 @@
extra_context={"path": "/", "filename": dir_file["name"]},
)
- swhid_cnt_parsed = get_persistent_identifier(
- swhids[0]["swhid_with_context"]
- )
- swhid_dir_parsed = get_persistent_identifier(
- swhids[1]["swhid_with_context"]
- )
- swhid_rev_parsed = get_persistent_identifier(
- swhids[2]["swhid_with_context"]
- )
+ swhid_cnt_parsed = get_swhid(swhids[0]["swhid_with_context"])
+ swhid_dir_parsed = get_swhid(swhids[1]["swhid_with_context"])
+ swhid_rev_parsed = get_swhid(swhids[2]["swhid_with_context"])
- swhid_snp_parsed = get_persistent_identifier(
+ swhid_snp_parsed = get_swhid(
swhids[3]["swhid_with_context"] or swhids[3]["swhid"]
)
swhid_rel_parsed = None
if "release_name" in snp_ctx_params:
- swhid_rel_parsed = get_persistent_identifier(
- swhids[4]["swhid_with_context"]
- )
+ swhid_rel_parsed = get_swhid(swhids[4]["swhid_with_context"])
- anchor = get_swh_persistent_id(
+ anchor = gen_swhid(
object_type=anchor_info["anchor_type"],
object_id=anchor_info["anchor_id"],
)
- snapshot_swhid = get_swh_persistent_id(
- object_type=SNAPSHOT, object_id=snapshot_id
- )
+ snapshot_swhid = gen_swhid(object_type=SNAPSHOT, object_id=snapshot_id)
expected_cnt_context = {
"visit": snapshot_swhid,
@@ -531,19 +519,15 @@
obj_context["origin"] = origin_url
query_params["origin_url"] = origin_url
- obj_context["visit"] = get_swh_persistent_id(SNAPSHOT, snapshot_id)
+ obj_context["visit"] = gen_swhid(SNAPSHOT, snapshot_id)
query_params["snapshot"] = snapshot_id
if object_type in (CONTENT, DIRECTORY, REVISION):
if snapshot_context["release"]:
- obj_context["anchor"] = get_swh_persistent_id(
- RELEASE, snapshot_context["release_id"]
- )
+ obj_context["anchor"] = gen_swhid(RELEASE, snapshot_context["release_id"])
query_params["release"] = snapshot_context["release"]
else:
- obj_context["anchor"] = get_swh_persistent_id(
- REVISION, snapshot_context["revision_id"]
- )
+ obj_context["anchor"] = gen_swhid(REVISION, snapshot_context["revision_id"])
if (
snapshot_context["branch"]
and snapshot_context["branch"] != snapshot_context["revision_id"]
@@ -576,9 +560,9 @@
if lines:
obj_context["lines"] = lines
- obj_swhid = get_swh_persistent_id(object_type, object_id, metadata=obj_context)
+ obj_swhid = gen_swhid(object_type, object_id, metadata=obj_context)
- obj_swhid_resolved = resolve_swh_persistent_id(obj_swhid)
+ obj_swhid_resolved = resolve_swhid(obj_swhid)
url_args = {"sha1_git": object_id}
if object_type == CONTENT:
diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py
--- a/swh/web/tests/common/test_service.py
+++ b/swh/web/tests/common/test_service.py
@@ -901,7 +901,7 @@
missing_rel = random_sha1()
missing_snp = random_sha1()
- grouped_pids = {
+ grouped_swhids = {
CONTENT: [hash_to_bytes(missing_cnt)],
DIRECTORY: [hash_to_bytes(missing_dir)],
REVISION: [hash_to_bytes(missing_rev)],
@@ -909,7 +909,7 @@
SNAPSHOT: [hash_to_bytes(missing_snp)],
}
- actual_result = service.lookup_missing_hashes(grouped_pids)
+ actual_result = service.lookup_missing_hashes(grouped_swhids)
assert actual_result == {
missing_cnt,
@@ -926,7 +926,7 @@
missing_rel = random_sha1()
missing_snp = random_sha1()
- grouped_pids = {
+ grouped_swhids = {
CONTENT: [hash_to_bytes(content["sha1_git"])],
DIRECTORY: [hash_to_bytes(directory)],
REVISION: [hash_to_bytes(missing_rev)],
@@ -934,7 +934,7 @@
SNAPSHOT: [hash_to_bytes(missing_snp)],
}
- actual_result = service.lookup_missing_hashes(grouped_pids)
+ actual_result = service.lookup_missing_hashes(grouped_swhids)
assert actual_result == {missing_rev, missing_rel, missing_snp}
diff --git a/swh/web/tests/misc/test_badges.py b/swh/web/tests/misc/test_badges.py
--- a/swh/web/tests/misc/test_badges.py
+++ b/swh/web/tests/misc/test_badges.py
@@ -7,7 +7,7 @@
from hypothesis import given
from swh.model.identifiers import (
- persistent_identifier,
+ swhid,
CONTENT,
DIRECTORY,
ORIGIN,
@@ -16,7 +16,7 @@
SNAPSHOT,
)
from swh.web.common import service
-from swh.web.common.identifiers import resolve_swh_persistent_id
+from swh.web.common.identifiers import resolve_swhid
from swh.web.common.utils import reverse
from swh.web.misc.badges import _badge_config, _get_logo_data
from swh.web.tests.django_asserts import assert_contains
@@ -100,8 +100,8 @@
_check_generated_badge(resp, **url_args, error="not found")
if object_type != ORIGIN:
- object_pid = persistent_identifier(object_type, object_id)
- url = reverse("swh-badge-pid", url_args={"object_pid": object_pid})
+ object_swhid = swhid(object_type, object_id)
+ url = reverse("swh-badge-swhid", url_args={"object_swhid": object_swhid})
resp = client.get(url)
_check_generated_badge(resp, **url_args, error="not found")
@@ -117,8 +117,8 @@
resp = client.get(url)
_check_generated_badge(resp, **url_args, error="invalid id")
- object_pid = f"swh:1:{object_type[:3]}:{object_id}"
- url = reverse("swh-badge-pid", url_args={"object_pid": object_pid})
+ object_swhid = f"swh:1:{object_type[:3]}:{object_id}"
+ url = reverse("swh-badge-swhid", url_args={"object_swhid": object_swhid})
resp = client.get(url)
_check_generated_badge(resp, "", "", error="invalid id")
@@ -132,8 +132,8 @@
assert resp.status_code == 200, resp.content
assert ACCESS_CONTROL_ALLOW_ORIGIN in resp
- release_pid = persistent_identifier(RELEASE, release)
- url = reverse("swh-badge-pid", url_args={"object_pid": release_pid})
+ release_swhid = swhid(RELEASE, release)
+ url = reverse("swh-badge-swhid", url_args={"object_swhid": release_swhid})
resp = client.get(url, HTTP_ORIGIN="https://example.org")
assert resp.status_code == 200, resp.content
assert ACCESS_CONTROL_ALLOW_ORIGIN in resp
@@ -145,8 +145,8 @@
resp = client.get(url)
_check_generated_badge(resp, **url_args)
if object_type != ORIGIN:
- pid = persistent_identifier(object_type, object_id)
- url = reverse("swh-badge-pid", url_args={"object_pid": pid})
+ obj_swhid = swhid(object_type, object_id)
+ url = reverse("swh-badge-swhid", url_args={"object_swhid": obj_swhid})
resp = client.get(url)
_check_generated_badge(resp, **url_args)
@@ -162,8 +162,8 @@
link = reverse("browse-origin", query_params={"origin_url": object_id})
text = "repository"
elif error is None:
- text = persistent_identifier(object_type, object_id)
- link = resolve_swh_persistent_id(text)["browse_url"]
+ text = swhid(object_type, object_id)
+ link = resolve_swhid(text)["browse_url"]
if object_type == RELEASE:
release = service.lookup_release(object_id)
text = release["name"]
diff --git a/swh/web/urls.py b/swh/web/urls.py
--- a/swh/web/urls.py
+++ b/swh/web/urls.py
@@ -21,7 +21,7 @@
from django_js_reverse.views import urls_js
-from swh.web.browse.identifiers import swh_id_browse
+from swh.web.browse.identifiers import swhid_browse
from swh.web.config import get_config
from swh.web.common.exc import (
swh_handle400,
@@ -49,9 +49,9 @@
url(r"^$", _default_view, name="swh-web-homepage"),
url(r"^jsreverse/$", urls_js, name="js_reverse"),
url(
- r"^(?P<swh_id>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$",
- swh_id_browse,
- name="browse-swh-id",
+ r"^(?P<swhid>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$",
+ swhid_browse,
+ name="browse-swhid",
),
url(r"^", include("swh.web.misc.urls")),
url(r"^", include("swh.web.auth.views")),

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 18, 4:38 PM (4 h, 50 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3227349

Event Timeline