I don't know if anyone has attempted this before (and the list archive search function seems to be broken), but I've done some work on getting SWIG to build scripting language wrappers for libapt-pkg. I know that some work has been done on perl-apt and python-apt, but I hope that if this project works out, both of these (and more) will be able to be generated from common source, which will hopefully be automatically generated from the APT headers. Currently, SWIG can't parse APT's header files as they are, due to its incomplete C++ support. The changes are too extensive for it to be practical to wrap them in #ifdef SWIG, so the SWIG interface files have to be maintained separately. However, I hope to minimize maintenance by automating merging of the changes where possible. As SWIG's C++ support improves, hopefully the modifications will get down to a few lines and be able to be merged into the headers themselves. Currently, I've gotten things to the point where both of the attached scripts run and produce the following (correct) output: libapt-pkg version: 3.2.0 DPkg::Build-Options: -b -uc -rfakeroot A package: mpg123-alsa Much more of the functionality should work, now that I finally got SWIG to digest the stuff, but I haven't done any further testing yet. Before I put any more time into this, do you folks think that this would be something useful? -- - mdz
Attachment:
test.pl
Description: Perl program
#!/usr/bin/python import apt_pkg print "libapt-pkg version: %s.%s.%s" % (apt_pkg.APT_PKG_MAJOR, apt_pkg.APT_PKG_MINOR, apt_pkg.APT_PKG_RELEASE) apt_pkg.pkgInitConfig(apt_pkg._config) apt_pkg.pkgInitSystem(apt_pkg._config) print "DPkg::Build-Options: %s" % apt_pkg._config.Find("DPkg::Build-Options") file = apt_pkg._config.FindFile("Dir::Cache::pkgcache"); print "pkgcache: ", file mmap = apt_pkg.MMap(apt_pkg.FileFd(file, apt_pkg.FileFd.ReadOnly), apt_pkg.MMap.Public|apt_pkg.MMap.ReadOnly) pkgcache = apt_pkg.pkgCache(mmap) pkgiterator = pkgcache.PkgBegin() print "A package: ", pkgiterator.Name()
Attachment:
pgpNQe58D4Nvr.pgp
Description: PGP signature