Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 1,558 Lines • ▼ Show 20 Lines | def to_dict(self): | ||||
) | ) | ||||
for context_key in context_keys: | for context_key in context_keys: | ||||
if d[context_key] is None: | if d[context_key] is None: | ||||
del d[context_key] | del d[context_key] | ||||
return d | return d | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
if "type" in d: | |||||
# Convert from old schema | |||||
type_ = d.pop("type") | |||||
if type_ == "origin": | |||||
d["target"] = str(Origin(d["target"]).swhid()) | |||||
d = { | d = { | ||||
**d, | **d, | ||||
"target": ExtendedSWHID.from_string(d["target"]), | "target": ExtendedSWHID.from_string(d["target"]), | ||||
"authority": MetadataAuthority.from_dict(d["authority"]), | "authority": MetadataAuthority.from_dict(d["authority"]), | ||||
"fetcher": MetadataFetcher.from_dict(d["fetcher"]), | "fetcher": MetadataFetcher.from_dict(d["fetcher"]), | ||||
} | } | ||||
swhid_keys = ("snapshot", "release", "revision", "directory") | swhid_keys = ("snapshot", "release", "revision", "directory") | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |