Exemple #1
0
    def open(self, progress):
        """ Open the package cache, after that it can be used like
            a dictionary
        """
        self._runCallbacks("cache_pre_open")
        self._cache = apt_pkg.GetCache(progress)
        self._depcache = apt_pkg.GetDepCache(self._cache)
        self._records = apt_pkg.GetPkgRecords(self._cache)
        self._list = apt_pkg.GetPkgSourceList()
        self._list.ReadMainList()
        self._dict = {}

        # build the packages dict
        if progress != None:
            progress.Op = "Building data structures"
        i = last = 0
        size = len(self._cache.Packages)
        for pkg in self._cache.Packages:
            if progress != None and last + 100 < i:
                progress.update(i / float(size) * 100)
                last = i
            # drop stuff with no versions (cruft)
            if len(pkg.VersionList) > 0:
                self._dict[pkg.Name] = Package(self._cache, self._depcache,
                                               self._records, self._list, self,
                                               pkg)

            i += 1
        if progress != None:
            progress.done()
        self._runCallbacks("cache_post_open")
Exemple #2
0
def main():
    apt_pkg.init()
    cache = apt_pkg.GetCache()
    depcache = apt_pkg.GetDepCache(cache)
    depcache.Init()
    i = 0
    print "Running PkgRecords test on all packages:"
    for pkg in cache.Packages:
        i += 1
        records = apt_pkg.GetPkgRecords(cache)
        if len(pkg.VersionList) == 0:
            #print "no available version, cruft"
            continue
        version = depcache.GetCandidateVer(pkg)
        if not version:
            continue
        file, index = version.FileList.pop(0)
        if records.Lookup((file, index)):
            #print records.FileName
            x = records.FileName
            y = records.LongDesc
            pass
        print "\r%i/%i=%.3f%%    " % (i, cache.PackageCount,
                                      (float(i) / float(cache.PackageCount) *
                                       100)),
def main():
	apt_pkg.init()
	cache = apt_pkg.GetCache()
	depcache = apt_pkg.GetDepCache(cache)
	depcache.Init()
	i=0
	all=cache.PackageCount
	print "Running DepCache test on all packages"
	print "(trying to install each and then mark it keep again):"
	# first, get all pkgs
	for pkg in cache.Packages:
		i += 1
		x = pkg.Name
		# then get each version
		ver =depcache.GetCandidateVer(pkg)
		if ver != None:
			depcache.MarkInstall(pkg)
			if depcache.BrokenCount > 0:
				fixer = apt_pkg.GetPkgProblemResolver(depcache)
				fixer.Clear(pkg)
				fixer.Protect(pkg)
				# we first try to resolve the problem
				# with the package that should be installed
				# protected 
				try:
					fixer.Resolve(True)
				except SystemError:
					# the pkg seems to be broken, the
					# returns a exception
					fixer.Clear(pkg)
					fixer.Resolve(True)
					if not depcache.MarkedInstall(pkg):
						print "broken in archive: %s " % pkg.Name
				fixer = None
			if depcache.InstCount == 0:
				if depcache.IsUpgradable(pkg):
					print "Error marking %s for install" % x
			for p in cache.Packages:
				if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p):
					depcache.MarkKeep(p)
			if depcache.InstCount != 0:
				print "Error undoing the selection for %s" % x
		print "\r%i/%i=%.3f%%    " % (i,all,(float(i)/float(all)*100)),

	print
	print "Trying Upgrade:"
	depcache.Upgrade()
	print "To install: %s " % depcache.InstCount
	print "To remove: %s " % depcache.DelCount
	print "Kept back: %s " % depcache.KeepCount

	print "Trying DistUpgrade:"
	depcache.Upgrade(True)
	print "To install: %s " % depcache.InstCount
	print "To remove: %s " % depcache.DelCount
	print "Kept back: %s " % depcache.KeepCount
Exemple #4
0
 def get_single_package(name):
     if type(package) != str:
         raise TypeError("Expected string")
     cache = apt_pkg.GetCache()
     depcache = apt_pkg.GetDepCache(cache)
     records = apt_pkg.GetPkgRecords(cache)
     sourcelist = apt_pkg.GetPkgSourceList()
     pkg = apt.package.Package(cache, depcache, records, sourcelist, None,
                               cache[sys.argv[1]])
     return pkg
Exemple #5
0
 def getVersion(self, packageName):
     if not self.cache:
         import apt_pkg
         apt_pkg.init()
         self.cache = apt_pkg.GetCache()
     packages = self.cache.Packages
     for package in packages:
         if package.Name == packageName:
             verString = re.match('.*Ver:\'(.*)-.*\' Section:',
                                  str(package.CurrentVer)).group(1)
             return Version.fromString(verString)
     raise PackageNotFoundError(packageName)
Exemple #6
0
    def load(self):
        """
        Regenerates the fake configuration and load the packages server.
        """
        if not self.loaded:
            log.msg("Loading Packages database for "+self.status_dir,'apt_pkg')
            
            shutil.rmtree(self.status_dir+'/apt/lists/')
            os.makedirs(self.status_dir+'/apt/lists/partial')
            sources = open(self.status_dir+'/'+'apt/etc/sources.list', 'w')
            for file in self.packages.keys():
                # we should probably clear old entries from self.packages and
                # take into account the recorded mtime as optimization
                fake_uri='http://apt-proxy:'+file
                source_line='deb '+dirname(fake_uri)+'/ /'
                listpath=(self.status_dir+'/apt/lists/'
                          +apt_pkg.URItoFileName(fake_uri))
                sources.write(source_line+'\n')

                try:
                    #we should empty the directory instead
                    os.unlink(listpath)
                except:
                    pass
                os.symlink('../../../../../'+file, listpath)
            sources.close()
            for key, value in self.local_config.items():
                apt_pkg.Config[key] = value
            apt_pkg.InitSystem()

            if log.isEnabled('apt'):
                self.cache = apt_pkg.GetCache()
            else:
                # apt_pkg prints progress messages to stdout, disable
                self.__save_stdout()
                self.cache = apt_pkg.GetCache()
                self.__restore_stdout()

            self.records = apt_pkg.GetPkgRecords(self.cache)
            self.loaded = 1
Exemple #7
0
def main():
    apt_pkg.init()
    cache = apt_pkg.GetCache()
    i = 0
    print "Running PkgSrcRecords test on all packages:"
    for x in cache.Packages:
        i += 1
        src = apt_pkg.GetPkgSrcRecords()
        if src.Lookup(x.Name):
            #print src.Package
            pass
        print "\r%i/%i=%.3f%%    " % (i, cache.PackageCount,
                                      (float(i) / float(cache.PackageCount) *
                                       100)),
Exemple #8
0
    def check(self, pkg_list):
        """
        Return True if all packages in pkg_list are installed. False in other
        case.
        """
        #Collect the packages by name
        packages = apt_pkg.GetCache().Packages
        packages_dict = {}
        for pkg in packages:
            packages_dict[pkg.Name] = pkg

        #Check state
        for pkg_name in pkg_list:
            if (not packages_dict.has_key(pkg_name)) or \
                    (not packages_dict[pkg_name].CurrentVer):
                return False
        return True
Exemple #9
0
    def check(self, pkg_list):
        """ 
        [es] Devolvemos Verdadero si todos los paquetes de la lista
             pkg_list estan instalado. Falso en otro caso.
        -------------------------------------------------------------------
        [en] Return True if all packages in pkg_list are installed. False
             in other case.
        """
        #Collect the packages by name
        packages = apt_pkg.GetCache().Packages
        packages_dict = {}
        for pkg in packages:
            packages_dict[pkg.Name] = pkg

        #Check state
        for pkg_name in pkg_list:
            if (not packages_dict.has_key(pkg_name)) or \
                    (not packages_dict[pkg_name].CurrentVer):
                return False
        return True
Exemple #10
0
 def getDependencies(self, packageName):
     # Simulate a set using a hash (to a dummy value);
     # sets were only added in Python 2.4
     result = {}
     if not self.cache:
         import apt_pkg
         apt_pkg.init()
         self.cache = apt_pkg.GetCache()
     packages = self.cache.Packages
     for package in packages:
         if package.Name == packageName:
             current = package.CurrentVer
             if not current:
                 raise PackageNotFoundError(packageName)
             depends = current.DependsList
             list = depends['Depends']
             for dependency in list:
                 name = dependency[0].TargetPkg.Name
                 # Add to the hash using a dummy value
                 result[name] = None
     return result.keys()
    def get_updatesApt(self, input_data):
        import apt_pkg
        action = input_data['action']
        upgrade_list = []
        skipped_list = []
        upgrade_count = 0
        skipped_count = 0

        apt_pkg.init()

        if os.path.exists("/etc/apt/apt.conf"):
            apt_pkg.read_config_file(apt_pkg.config,
                                     "/etc/apt/apt.conf")
        if os.path.isdir("/etc/apt/apt.conf.d"):
            apt_pkg.read_config_dir(apt_pkg.config,
                                    "/etc/apt/apt.conf.d")
        apt_pkg.init_system()

        cache = apt_pkg.GetCache(None)

        depcache = apt_pkg.GetDepCache(cache)
        depcache.ReadPinFile()
        depcache.Init(None)

        for i in cache.packages:
            if i.current_state is apt_pkg.CURSTATE_INSTALLED:
                if depcache.is_upgradable(i):
                    if depcache.marked_keep(i):
                        skipped_list.append(i.name)
                        skipped_count += 1
                    else:
                        upgrade_list.append(i.name)
                        upgrade_count += 1
        return(retval(0, "Package Update List", {
            "consequences": [
                'attrs.AvailablePackages := %s' % cache.PackageCount,
                'attrs.UpgradablePackageCount := %s' % upgrade_count,
                'attrs.SkippedPackageCount := %s' % skipped_count,
                'attrs.UpgradablePackages := %s' % json.dumps(upgrade_list),
                'attrs.SkippedPackageList := %s' % json.dumps(skipped_list)]}))
Exemple #12
0
def main():
    apt_pkg.init()
    cache = apt_pkg.GetCache()
    depcache = apt_pkg.GetDepCache(cache)
    depcache.Init()
    i = 0
    all = cache.PackageCount
    print "Running DepCache test on all packages"
    print "(trying to install each and then mark it keep again):"
    # first, get all pkgs
    for pkg in cache.Packages:
        i += 1
        x = pkg.Name
        # then get each version
        ver = depcache.GetCandidateVer(pkg)
        if ver != None:
            depcache.MarkInstall(pkg)
            if depcache.InstCount == 0:
                if depcache.IsUpgradable(pkg):
                    print "Error marking %s for install" % x
            for p in cache.Packages:
                if depcache.MarkedInstall(p):
                    depcache.MarkKeep(p)
            if depcache.InstCount != 0:
                print "Error undoing the selection for %s (InstCount: %s)" % (
                    x, depcache.InstCount)
        print "\r%i/%i=%.3f%%    " % (i, all, (float(i) / float(all) * 100)),

    print
    print "Trying Upgrade:"
    depcache.Upgrade()
    print "To install: %s " % depcache.InstCount
    print "To remove: %s " % depcache.DelCount
    print "Kept back: %s " % depcache.KeepCount

    print "Trying DistUpgrade:"
    depcache.Upgrade(True)
    print "To install: %s " % depcache.InstCount
    print "To remove: %s " % depcache.DelCount
    print "Kept back: %s " % depcache.KeepCount
Exemple #13
0
def linux_ubuntu_check(package_name):
    import apt_pkg
    apt_pkg.init()
    cache = apt_pkg.GetCache()
    depcache = apt_pkg.GetDepCache(cache)

    def get_single_package(name):
        if type(package) != str:
            raise TypeError("Expected string")
        cache = apt_pkg.GetCache()
        depcache = apt_pkg.GetDepCache(cache)
        records = apt_pkg.GetPkgRecords(cache)
        sourcelist = apt_pkg.GetPkgSourceList()
        pkg = apt.package.Package(cache, depcache, records, sourcelist, None,
                                  cache[sys.argv[1]])
        return pkg

    if type(package_name) == str:
        return get_single_package(package_name).candidateVersion
    elif type(package_name) == list:
        return [
            get_single_package(name).candidateVersion for name in package_name
        ]
Exemple #14
0
class Foo:
    pass


if __name__ == '__main__':
    import apt_pkg as Apt
    Apt.init()
    c = Apt.GetCache()
    print c.Packages
Exemple #15
0
import apt_pkg

apt_pkg.init()

apt_pkg.Config.Set("APT::Acquire::Translation","de")

cache = apt_pkg.GetCache()
depcache = apt_pkg.GetDepCache(cache)

pkg = cache["gcc"]
cand = depcache.GetCandidateVer(pkg)
print cand

desc = cand.TranslatedDescription
print desc
print desc.FileList
(f,index) = desc.FileList.pop(0)

records = apt_pkg.GetPkgRecords(cache)
records.Lookup((f,index))
desc = records.LongDesc
print len(desc)
print desc

Exemple #16
0
#!/usr/bin/python
# example how to deal with the depcache

import apt_pkg
import sys
import copy
from apt.progress import OpTextProgress
from progress import TextFetchProgress

# init
apt_pkg.init()

progress = OpTextProgress()
cache = apt_pkg.GetCache(progress)
print "Available packages: %s " % cache.PackageCount

print "Fetching"
progress = TextFetchProgress()
cache.Update(progress)

print "Exiting"
sys.exit(0)

iter = cache["base-config"]
print "example package iter: %s" % iter

# get depcache
print "\n\n depcache"
depcache = apt_pkg.GetDepCache(cache, progress)
depcache.ReadPinFile()
print "got a depcache: %s " % depcache