The python binding to libapt-pkg does not offer any way to do the rough
equivalent of apt-get's "upgrade --with-new-pkgs".
The Cache.upgade method allows doing a "full/dist upgrade" or a
"partial/safe upgrade":
Cache.upgrade(self, dist_upgrade: bool = False) -> None
That forwards the call to apt_pkg.DepCache.upgrade which is implemented
by PkgDepCacheUpgrade:
static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args)
{
[...]
char distUpgrade=0;
if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0)
return 0;
[...]
if (distUpgrade)
res = APT::Upgrade::Upgrade(*depcache, 0);
else
res = APT::Upgrade::Upgrade(*depcache, APT::Upgrade::FORBID_REMOVE_PACKAGES |
APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
[...]
}
What's missing is allowing python to call Upgrade with
FORBID_REMOVE_PACKAGES but without FORBID_INSTALL_NEW_PACKAGES
(pseudocode):
int mode_flags = (upgrade_mode == FULL)
? 0
: (upgrade_mode == WITH_NEW_PKGS)
? APT::Upgrade::FORBID_REMOVE_PACKAGES
: APT::Upgrade::FORBID_REMOVE_PACKAGES |
APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES;
res = APT::Upgrade::Upgrade(*depcache, mode_flags);
Plus the API adjustments to expose this feature.