swh.deposit.utils module¶
-
swh.deposit.utils.
merge
(*dicts)[source]¶ Given an iterator of dicts, merge them losing no information.
- Parameters
*dicts – arguments are all supposed to be dict to merge into one
- Returns
dict merged without losing information
-
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.identifiers.normalize_timestamp.
- Returns
The swh date object
-
swh.deposit.utils.
compute_metadata_context
(swhid_reference: Union[swh.model.identifiers.SWHID, str]) → Tuple[swh.model.model.MetadataTargetType, Dict[str, Any]][source]¶ Given a SWHID object, determine the context as a dict.
The parse_swhid calls within are not expected to raise (because they should have been caught early on).
-
swh.deposit.utils.
parse_swh_reference
(metadata: Dict) → Optional[Union[str, swh.model.identifiers.SWHID]][source]¶ Parse swh reference within the metadata dict (or origin) reference if found, None otherwise.
- <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>
- Raises
ValidationError in case the swhid referenced (if any) is invalid –
- Returns
Either swhid or origin reference if any. None otherwise.