[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

python-apt



Dear Friends,

I looked into python-apt and played around with it a bit. The lack of
documentation is obviously a problem. I was able to understand the easy
stuff (init, ParseSection, ParseTagFile, ParseDepends,
debExtractControl, debExtract). 

But the "GetCache()" and "GetPkgRecords(Cache)" looks incomplete to me.
Is this right? If not, can someone please give me a hint howto work with
pkgCache and pkgRecord objects (and what argument pkgRecord.Lookup()
takes)?

Another question:
Is it possible to do a "real" extract of the data with debExtract? I was
only able to view the content of the deb file but not to extract it (e.g. to
a given directory).

I wrote two extremly simple example python scripts. Maybe someone can
polish them a bit and include them into the examples dir of python-apt
(I attached both).


thanks,
 Michael

P.S. Please CC me, as I'm not on the list (it's closed, isn't it).
-- 
GPG Fingerprint = EA71 B296 4597 4D8B 343E  821E 9624 83E1 5662 C734
You Know You've Been Playing Too Much Nethack When...
You look both ways down the corridor, start to sweat... 
then realise you're looking at your EMail address
#!/usr/bin/env python
#
# extract demonstrates howto work with debExtract and debExtractControl

import apt_pkg, apt_inst, sys,getopt;

file = "testdata/toshset_1.52-1_i386.deb"               # -f filename


#-------------------------------------------------------------------------
def Ent(Kind,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
    """ callback for debExtract """
    
    print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\
          % (Kind,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor);
#-------------------------------------------------------------------------


opts, args = getopt.getopt(sys.argv[1:], "f:")
for option, argument in opts:
	if option == "-f":
		file = argument


if file == "":
    print "need filename argumnet"

print "Working on: %s" % file
print "Displaying data.tar.gz:"
apt_inst.debExtract(open(file), Ent, "data.tar.gz")

print "Now extracting the control file:"
print apt_inst.debExtractControl(open(file))

print "Maintainer is: "
print apt_pkg.ParseSection(apt_inst.debExtractControl(open(file)))["Maintainer"]

print
print "DependsOn: "
depends = apt_pkg.ParseSection(apt_inst.debExtractControl(open(file)))["Depends"]
print apt_pkg.ParseDepends(depends)


#!/usr/bin/env python
#
# Tag is a generic method for parsing RFC 822 conform tagfiles (like
# the debian Package files)
#
import apt_pkg, apt_inst, sys,getopt;

file = "testdata/Packages"               # -f filename

opts, args = getopt.getopt(sys.argv[1:], "f:")
for option, argument in opts:
	if option == "-f":
		file = argument

print "Working on: %s" % file

print "All Packages in the file:"
# get "parser" 
Packages = apt_pkg.ParseTagFile(open(file))
# iterate over "Packages"
while Packages.Step():
	print Packages.Section.Find('Package') + " (size: " \
	      +  Packages.Section.Find('Size') + ")"


Reply to: