Exemplo n.º 1
0
    def parsePackages(self, f, pkgtype):
        """Parse a Packages file and get the information we need."""
        p = apt_pkg.ParseTagFile(f)
        while p.Step() == 1:
            pkg = p.Section["Package"]
            self.packages[pkg] = {}
            self.packagetype[pkg] = pkgtype
            self.pruned[pkg] = set()

            self.packages[pkg]["Maintainer"] = \
                unicode(p.Section.get("Maintainer", ""), "utf8", "replace")

            for field in "Pre-Depends", "Depends", "Recommends", "Suggests":
                value = p.Section.get(field, "")
                self.packages[pkg][field] = apt_pkg.ParseDepends(value)

            for field in "Size", "Installed-Size":
                value = p.Section.get(field, "0")
                self.packages[pkg][field] = int(value)

            src = p.Section.get("Source", pkg)
            idx = src.find("(")
            if idx != -1:
                src = src[:idx].strip()
            self.packages[pkg]["Source"] = src

            provides = apt_pkg.ParseDepends(p.Section.get("Provides", ""))
            for prov in provides:
                if prov[0][0] not in self.provides:
                    self.provides[prov[0][0]] = []
                    if prov[0][0] in self.packages:
                        self.provides[prov[0][0]].append(prov[0][0])
                self.provides[prov[0][0]].append(pkg)
            self.packages[pkg]["Provides"] = provides

            if pkg in self.provides:
                self.provides[pkg].append(pkg)

            self.packages[pkg]["Kernel-Version"] = p.Section.get(
                "Kernel-Version", "")
        f.close()
Exemplo n.º 2
0
    def __parsePackages__(self, f):
        """
		Most info are raw info. This method parses the needed fields.
		"""

        p = apt_pkg.ParseTagFile(f)

        # Just load into memory the fields that are going to be useful
        while p.Step() == 1:
            pkg = p.Section['Package']

            self.packages[pkg] = {}

            for field in p.Section.keys():
                if field == 'Package':
                    pass
                elif [
                        'Depends', 'Recommends', 'Suggests', 'Enhances',
                        'Pre-Depends', 'Conflicts', 'Provides'
                ].count(field):
                    value = p.Section.get(field, "")
                    self.packages[pkg][field] = apt_pkg.ParseDepends(value)
                elif ['Size', 'Installed-Size'].count(field):
                    value = p.Section.get(field, "0")
                    self.packages[pkg][field] = int(value)
                elif field == 'Source':
                    src = p.Section.get(field, pkg)
                    idx = src.find('(')
                    if idx != -1:
                        src = src[:idx].strip()
                    self.packages[pkg][field] = src
                elif field == 'Provides':
                    self.packages[pkg]["Provides"] = apt_pkg.ParseDepends(
                        p.Section.get("Provides", ""))
                else:
                    self.packages[pkg][field] = p.Section.get(field, '')

        f.close()
Exemplo n.º 3
0
 def testParseDepends(self):
     """dependencies: Test apt_pkg.ParseDepends()."""
     if not hasattr(apt_pkg, 'ParseDepends'):
         return
     # Check that the type of comparison is parsed correctly.
     self.assertEqual("<<", apt_pkg.ParseDepends("p1 (<< 1)")[0][0][2])
     self.assertEqual("<=", apt_pkg.ParseDepends("p1 (< 1)")[0][0][2])
     self.assertEqual("<=", apt_pkg.ParseDepends("p1 (<= 1)")[0][0][2])
     self.assertEqual("=", apt_pkg.ParseDepends("p1 (= 1)")[0][0][2])
     self.assertEqual(">=", apt_pkg.ParseDepends("p1 (>= 1)")[0][0][2])
     self.assertEqual(">=", apt_pkg.ParseDepends("p1 (> 1)")[0][0][2])
     self.assertEqual(">>", apt_pkg.ParseDepends("p1 (>> 1)")[0][0][2])
Exemplo n.º 4
0
    def parseSources(self, f):
        """Parse a Sources file and get the information we need."""
        p = apt_pkg.ParseTagFile(f)
        while p.Step() == 1:
            src = p.Section["Package"]
            self.sources[src] = {}

            self.sources[src]["Maintainer"] = \
                unicode(p.Section.get("Maintainer", ""), "utf8", "replace")
            self.sources[src]["IPv6"] = "Unknown"

            for field in "Build-Depends", "Build-Depends-Indep":
                value = p.Section.get(field, "")
                self.sources[src][field] = apt_pkg.ParseSrcDepends(value)

            binaries = apt_pkg.ParseDepends(p.Section.get("Binary", src))
            self.sources[src]["Binaries"] = [bin[0][0] for bin in binaries]

        f.close()
Exemplo n.º 5
0
        sys.exit(1)
    file = sys.argv[1]

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

    print "Now extracting the control file:"
    control = apt_inst.debExtractControl(open(file))
    sections = apt_pkg.ParseSection(control)

    print "Maintainer is: "
    print sections["Maintainer"]

    print
    print "DependsOn: "
    depends = sections["Depends"]
    print apt_pkg.ParseDepends(depends)

    print "extracting archive"
    dir = "/tmp/deb"
    os.mkdir(dir)
    apt_inst.debExtractArchive(open(file), dir)

    def visit(arg, dirname, names):
        print "%s/" % dirname
        for file in names:
            print "\t%s" % file

    os.path.walk(dir, visit, None)
Exemplo n.º 6
0
#!/usr/bin/env python
import apt_pkg

Parse = apt_pkg.TagFile(open("/var/lib/dpkg/status", "r"))

while Parse.Step() == 1:
    print Parse.Section.get("Package")
    print apt_pkg.ParseDepends(Parse.Section.get("Depends", ""))