Re: Python apt: Multiple instances of Cache and DepCache
On Fri, Nov 22, 2024 at 01:20:29PM +0000, Karichery, Sreeraj wrote:
> Hi,
>
> I've started playing around python apt libraries and trying to see if we can have multiple instances of Cache and DepCache available as references living at the same time.
>
> I have reinit the DepCache and use that again, but I was looking for comparing the DepCache for different operations performed.
>
> Eg: I'm trying to implement something like this:
>
> # Setup cache using some set of sources
> c1 = apt_pkg.Cache()
> dc1 = apt_pkg.DepCache(c1)
> dc1.mark_install(pkg1)
> dc1.mark_install(pkg2)
>
> ....
> # Create a fresh cache again (using different set of aptsources)
> c2 = apt_pkg.Cache()
> dc2 = apt_pkg.DepCache(c2)
> dc2.mark_install(pkg1)
> dc2.mark_install(pkg2)
>
> # Custom build function
> compare_depcache(c1, c2, dc1, dc2)
It kind of works. In theory you should be able to use separate DepCache
for the same Cache even but we botched this a bit: DepCache doesn't
create a DepCache, it references the one inside the Cache (which
actually is a wrapper class around the real cache).
But that aside, your example should work and you should have found that
out already if you actually implement it. You'll need to keep matching
SourcesList objects around too after changing the options.
Some more caveats exist, you can't have different status files most
likely: that requires reinitializing init_system() and then things
are not particularly safe.
--
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer i speak de, en
Reply to: