swh.deposit.utils module#
- swh.deposit.utils.normalize_date(date)[source]#
- Normalize date fields as expected by swh workers. - If date is a list, elect arbitrarily the first element of that list - If date is (then) a string, parse it through dateutil.parser.parse to extract a datetime. - Then normalize it through - swh.model.model.TimestampWithTimezone- Returns
- The swh date object 
 
- swh.deposit.utils.compute_metadata_context(swhid_reference: QualifiedSWHID) Dict[str, Any][source]#
- Given a SWHID object, determine the context as a dict. 
- swh.deposit.utils.parse_swh_metadata_provenance(metadata: Element) str | None[source]#
- Parse swh metadata-provenance within the metadata dict reference if found, None otherwise. - <swh:deposit> <swh:metadata-provenance> <schema:url>https://example.org/metadata/url</schema:url> </swh:metadata-provenance> </swh:deposit> - Parameters:
- metadata – result of parsing an Atom document with - parse_xml()
- Raises:
- ValidationError in case of invalid xml – 
 - Returns:QuerySet
- Either the metadata provenance url if any or None otherwise 
 
- swh.deposit.utils.parse_swh_deposit_origin(metadata: Element) Tuple[str | None, str | None][source]#
- Parses <swh:add_to_origin> and <swh:create_origin> from metadata document, if any. - <swh:deposit> <swh:create_origin> <swh:origin url='https://example.org/repo/software123/'/> </swh:reference> </swh:deposit> - <swh:deposit> <swh:add_to_origin> <swh:origin url='https://example.org/repo/software123/'/> </swh:add_to_origin> </swh:deposit> - Returns:
- tuple of (origin_to_create, origin_to_add). If both are non-None, this should typically be an error raised to the user. 
 
- swh.deposit.utils.parse_swh_reference(metadata: Element) QualifiedSWHID | str | None[source]#
- Parse <swh:reference> within the metadata document, if any. - <swh:deposit> <swh:reference> <swh:origin url='https://github.com/user/repo'/> </swh:reference> </swh:deposit> - or: - <swh:deposit> <swh:reference> <swh:object swhid="swh:1:dir:31b5c8cc985d190b5a7ef4878128ebfdc2358f49;origin=https://hal.archives-ouvertes.fr/hal-01243573;visit=swh:1:snp:4fc1e36fca86b2070204bedd51106014a614f321;anchor=swh:1:rev:9c5de20cfb54682370a398fcc733e829903c8cba;path=/moranegg-AffectationRO-df7f68b/" /> </swh:deposit> - Parameters:
- metadata – result of parsing an Atom document 
- Raises:
- ValidationError in case the swhid referenced (if any) is invalid – 
- Returns:
- Either swhid or origin reference if any. None otherwise. 
 
- swh.deposit.utils.extended_swhid_from_qualified(swhid: QualifiedSWHID) ExtendedSWHID[source]#
- Used to get the target of a metadata object from a <swh:reference>, as the latter uses a QualifiedSWHID. 
- swh.deposit.utils.to_header_link(link: str, link_name: str) str[source]#
- Build a single header link. - >>> link_next = to_header_link("next-url", "next") >>> link_next '<next-url>; rel="next"' >>> ','.join([link_next, to_header_link("prev-url", "prev")]) '<next-url>; rel="next",<prev-url>; rel="prev"' 
- swh.deposit.utils.get_element_text(element: Element, tag: str) str | None[source]#
- Get an XML element’s text. - Parameters:
- element – an XML element 
- tag – a tag name, namespaced if needed 
 
- Returns:
- The text property of the found element or None 
 
- class swh.deposit.utils.ReleaseData(software_version, release_notes)#
- Bases: - tuple- Create new instance of ReleaseData(software_version, release_notes) - release_notes#
- Alias for field number 1 
 - software_version#
- Alias for field number 0 
 
- swh.deposit.utils.extract_release_data(deposit: Deposit) ReleaseData | None[source]#
- Extract deposit release data from its last request. - This will get the latest deposit_request with metadata of this deposit and extract properties from it: - software_version uses codemeta:softwareVersion or the count of previous releases - release_notes comes from either codemeta:releaseNotes or schema:releaseNotes - Parameters:
- deposit – a Deposit instance 
- Returns:
- A namedtuple of software_version & release_notes 
 
- swh.deposit.utils.get_releases(deposit: Deposit) QuerySet[source]#
- List all completed deposits to the same origin as the given - deposit.- All releases share the same origin_url, are in status - doneand have a non- empty- software_version.- Deposits are grouped by - software_versionand ordered by- complete_dateso that if multiple deposits where made with the same software version only the last one (by date) will be returned by this query.- Parameters:
- deposit – a Deposit instance 
- Returns:
- A queryset of deposits