Using python-apt's apt_pkg with a chroot
Using python-apt's apt_pkg with a chroot turns out to be non-trivial unlike apt.cache.
I'm running a script [0] on a trixie system and need to interact with the cache in a testing chroot.
The chroot is created with mmdebstrap --mode=unshare, and the script is run via unshare as well.
Setting RootDir in the config does not result in the chroot paths to be used:
$ unshare --map-auto --map-user=65536 --map-group=65536 --keep-caps -- ./bin/resolve-dependencies.py -vdp opencv -u 2>&1 | tee /tmp/resolve-dependencies.log
Resolving dependencies for: opencv
Chroot already exists: /var/tmp/testing-chroot
config:
RootDir "/var/tmp/testing-chroot";
list:
[<apt_pkg.MetaIndex object: type='deb', uri:'http://ftp.nl.debian.org/debian/' dist='trixie' is_trusted='1'>,
<apt_pkg.MetaIndex object: type='deb', uri:'http://ftp.nl.debian.org/debian/' dist='trixie-updates' is_trusted='1'>,
<apt_pkg.MetaIndex object: type='deb', uri:'http://security.debian.org/debian-security/' dist='trixie-security' is_trusted='1'>,
<apt_pkg.MetaIndex object: type='deb', uri:'http://ftp.nl.debian.org/debian/' dist='trixie-backports' is_trusted='1'>,
<apt_pkg.MetaIndex object: type='deb', uri:'http://debug.mirrors.debian.org/debian-debug/' dist='trixie-debug' is_trusted='1'>]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Traceback (most recent call last):
File "/home/bas/git/release-team/release.debian.org/bin/resolve-dependencies.py", line 216, in <module>
sys.exit(main())
~~~~^^
File "/home/bas/git/release-team/release.debian.org/bin/resolve-dependencies.py", line 212, in main
return resolve_dependencies()
File "/home/bas/git/release-team/release.debian.org/bin/resolve-dependencies.py", line 97, in resolve_dependencies
cache.update(apt.progress.text, source_list)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
apt_pkg.Error: E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied), E:Unable to lock directory /var/lib/apt/lists/
How can apt_pkg be used with a chroot?
apt.Cache(rootdir) works, but it does not provide access to source packages like apt_pkg.SourceRecords.
[0] https://salsa.debian.org/sebastic/release.debian.org/-/blob/ce71f7e543283c7fcca0a701fe22667ae7a188a2/bin/resolve-dependencies.py
Kind Regards,
Bas
Please CC me as I'm not subscribed to the list.
--
PGP Key ID: 4096R/6750F10AE88D4AF1
Fingerprint: 8182 DE41 7056 408D 6146 50D1 6750 F10A E88D 4AF1
Reply to: