On Mon, May 15, 2006 at 06:48:04AM +1000, Graham Williams wrote:
> Received Sat 13 May 2006 5:51am +1000 from Michael Vogt:
> > I looked into wajigs code and it turns out that the problem is that
> > the latest apt uses MMap inside the pkgTagFile that is used on a pipe
> > from wajig. This obviously does no longer work. I'll investigate what
> > can be done about it. See #350025 for the rational of that change.
> >
> > There are better (and faster) ways in python-apt nowdays to read the
> > description for packages btw (no need to pipe from apt-cache
> > dumpavail).
[..]
> Looks a bit of a problem with the new apt. I've not had a look at the
> newer python-apt, so any specific pointers are most welcome!
I was not aware that the pkgTagFile code was used on things like
pipes, otherwise I would have not done the mmap modification in
libapt. If more applications use it this way (and break because of
it), I'll revert it.
I attach a patch that switches a bit of wajig to use more recent
python-apt code. This is only a example and should not go "as-is" into
wajig. But it is (hopefully) enough to give you a idea how things work
in newer python-apt. The apt cache needs to be put in a more central
place probably because rebuilding it is expensive. You can easily add
(pre-done) progress with apt.progress.OpTextProgress when the cache is
opened. See /usr/share/doc/python-apt/examples for more examples.
I'm happy to help with python-apt if you have questions (mail, irc
whatever you want).
Cheers,
Michael
--
Linux is not The Answer. Yes is the answer. Linux is The Question. - Neo
=== modified file 'src/commands.py'
--- src/commands.py
+++ src/commands.py
@@ -35,6 +35,7 @@
#
# APT module
#
+import apt
import apt_pkg
#
@@ -204,22 +205,15 @@
packages = package_names
else:
return
- command = "apt-cache dumpavail"
- packages_pipe = perform.execute(command, noquiet=True, pipe=True)
- avail = apt_pkg.ParseTagFile(packages_pipe)
- #
- # Record the descriptions
- #
+
describe_list = {}
- #
- # Check for information in the Available list
- #
- while avail.Step():
- if (avail.Section.get("Package") in packages):
- package_name = avail.Section.get("Package")
- package_description = avail.Section.get("Description")
- if not describe_list.has_key(package_name):
- describe_list[package_name] = package_description
+ # mvo: its probably a good idea to keep the cache around in all of wajig
+ # because getting it may be expensive
+ cache = apt.Cache()
+ for pkgname in packages:
+ if cache.has_key(pkgname):
+ describe_list[pkgname] = cache[pkgname].description
+
#
# Print out the one line descriptions. Should it be sorted?
# If not sorted it should be same order as on the command line.
@@ -251,7 +245,8 @@
# "| head -1 | cut -d' ' -f2- "
# command += ") | sort"
# perform.execute(command)
-
+
+ # mvo: apt.Package.summary may be helpful here
for pkg in pkgs:
# Only print that first line, but check that there
# is a description available.
@@ -268,9 +263,19 @@
# TODO is there a way of doing this using apt_pkg easily?
# Otherwise "apt-cache show" seems okay if a little slower.
#
- package_names = perform.concat(packages)
- command = "apt-cache show " + package_names
- perform.execute(command)
+ #package_names = perform.concat(packages)
+ #command = "apt-cache show " + package_names
+ #perform.execute(command)
+ for pkgname in filter(lambda pkgname: cache.has_key(pkgname),
packages):
+ pkg = cache[pkgname]
+ for ver in pkg._pkg.VersionList:
+ if ver == None or ver.FileList == None:
+ print "no ver or ver.FileList"
+ continue
+ f, index = ver.FileList.pop(0)
+ cache._records.Lookup((f,index))
+ print cache._records.Record
+
#------------------------------------------------------------------------
#