MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / update

Method update

etc/scripts/utils_thirdparty.py:958–1005  ·  view source on GitHub ↗

Update self with a mapping of `data`. Keep unknown data as extra_data if `keep_extra` is True. If `overwrite` is True, overwrite self with `data` Return True if any data was updated, False otherwise. Raise an exception if there are key data conflicts.

(self, data, overwrite=False, keep_extra=True)

Source from the content-addressed store, hash-verified

956 return {k: v for k, v in data.items() if v and k in self.updatable_fields}
957
958 def update(self, data, overwrite=False, keep_extra=True):
959 """
960 Update self with a mapping of `data`. Keep unknown data as extra_data if
961 `keep_extra` is True. If `overwrite` is True, overwrite self with `data`
962 Return True if any data was updated, False otherwise. Raise an exception
963 if there are key data conflicts.
964 """
965 package_url = data.get("package_url")
966 if package_url:
967 purl_from_data = packageurl.PackageURL.from_string(package_url)
968 purl_from_self = packageurl.PackageURL.from_string(self.package_url)
969 if purl_from_data != purl_from_self:
970 print(
971 f"Invalid dist update attempt, no same same purl with dist: "
972 f"{self} using data {data}."
973 )
974 return
975
976 data.pop("about_resource", None)
977 dl = data.pop("download_url", None)
978 if dl:
979 data["path_or_url"] = dl
980
981 updated = False
982 extra = {}
983 for k, v in data.items():
984 if isinstance(v, str):
985 v = v.strip()
986 if not v:
987 continue
988
989 if hasattr(self, k):
990 value = getattr(self, k, None)
991 if not value or (overwrite and value != v):
992 try:
993 setattr(self, k, v)
994 except Exception as e:
995 raise Exception(f"{self}, {k}, {v}") from e
996 updated = True
997
998 elif keep_extra:
999 # note that we always overwrite extra
1000 extra[k] = v
1001 updated = True
1002
1003 self.extra_data.update(extra)
1004
1005 return updated
1006
1007
1008def get_license_link_for_filename(filename, urls):

Callers 15

load_about_dataMethod · 0.95
set_checksumsMethod · 0.95
load_pkginfo_dataMethod · 0.95
to_aboutMethod · 0.45
fetch_thirdpartyFunction · 0.45
as_jsonFunction · 0.45
jsonschema_for_fieldsFunction · 0.45
to_jsonschemaFunction · 0.45

Calls 2

getMethod · 0.65
popMethod · 0.45

Tested by

no test coverage detected