Update this Package with data from the ``package_data`` PackageData. If a field does not have a value and the ``package_data`` field has a value, set this package field to the ``package_data`` field value. If there is a value on both side, update the value accordin
(
self,
package_data,
datafile_path,
check_compatible=True,
replace=False,
include_version=True,
include_qualifiers=False,
include_subpath=False,
ignore_name_check=False,
default_relation='AND',
licensing=Licensing(),
)
| 1705 | ) |
| 1706 | |
| 1707 | def update( |
| 1708 | self, |
| 1709 | package_data, |
| 1710 | datafile_path, |
| 1711 | check_compatible=True, |
| 1712 | replace=False, |
| 1713 | include_version=True, |
| 1714 | include_qualifiers=False, |
| 1715 | include_subpath=False, |
| 1716 | ignore_name_check=False, |
| 1717 | default_relation='AND', |
| 1718 | licensing=Licensing(), |
| 1719 | ): |
| 1720 | """ |
| 1721 | Update this Package with data from the ``package_data`` PackageData. |
| 1722 | |
| 1723 | If a field does not have a value and the ``package_data`` field has a |
| 1724 | value, set this package field to the ``package_data`` field value. |
| 1725 | |
| 1726 | If there is a value on both side, update the value according to the |
| 1727 | ``replace`` flag. |
| 1728 | |
| 1729 | If ``replace`` is True, replace a value with the ``package_data`` value. |
| 1730 | Otherwise existing, non-empty values are left unchanged. |
| 1731 | |
| 1732 | List of values are merged, keeping the original order and avoiding duplicates. |
| 1733 | |
| 1734 | Return True if update is successful. |
| 1735 | |
| 1736 | Return False if there is a type, name or version mismatch between this |
| 1737 | package and the provided ``package_data`` |
| 1738 | """ |
| 1739 | if not package_data: |
| 1740 | return |
| 1741 | |
| 1742 | if isinstance(package_data, dict): |
| 1743 | package_data = PackageData.from_dict(package_data) |
| 1744 | |
| 1745 | if check_compatible and not is_compatible( |
| 1746 | purl1=self, |
| 1747 | purl2=package_data, |
| 1748 | include_version=include_version, |
| 1749 | include_qualifiers=include_qualifiers, |
| 1750 | include_subpath=include_subpath, |
| 1751 | ignore_name_check=ignore_name_check, |
| 1752 | ): |
| 1753 | if TRACE_UPDATE: |
| 1754 | logger_debug(f'update: skipping: {self.purl} is not compatible with: {package_data.purl}') |
| 1755 | return False |
| 1756 | |
| 1757 | # always append these new items |
| 1758 | self.datasource_ids.append(package_data.datasource_id) |
| 1759 | self.datafile_paths.append(datafile_path) |
| 1760 | |
| 1761 | existing = self.to_package_data().to_dict() |
| 1762 | new_package_data = package_data.to_dict() |
| 1763 | |
| 1764 | # update for these means combining lists of items from both sides |
no test coverage detected