diff options
author | Jeroen Dekkers <jeroen@dekkers.ch> | 2011-11-23 22:35:07 +0100 |
---|---|---|
committer | Jeroen Dekkers <jeroen@dekkers.ch> | 2011-11-23 22:35:07 +0100 |
commit | 19c3aceac953491ecacb9b44e743412c99eb7968 (patch) | |
tree | e6f039c02ca5ab5bdc1a52c5b4997bc17d217ac0 /src/lib/Client/Tools/APT.py | |
parent | c3f2470c4d6d9594764d2cd312f9733dbce77791 (diff) | |
download | bcfg2-19c3aceac953491ecacb9b44e743412c99eb7968.tar.gz bcfg2-19c3aceac953491ecacb9b44e743412c99eb7968.tar.bz2 bcfg2-19c3aceac953491ecacb9b44e743412c99eb7968.zip |
Use new python-apt API and fall back to the old API when new API isn't available
Diffstat (limited to 'src/lib/Client/Tools/APT.py')
-rw-r--r-- | src/lib/Client/Tools/APT.py | 75 |
1 files changed, 52 insertions, 23 deletions
diff --git a/src/lib/Client/Tools/APT.py b/src/lib/Client/Tools/APT.py index 338ec98fd..db8cd56e7 100644 --- a/src/lib/Client/Tools/APT.py +++ b/src/lib/Client/Tools/APT.py @@ -5,13 +5,6 @@ __revision__ = '$Revision$' import warnings warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning) -warnings.filterwarnings("ignore", "Accessed deprecated property Package.installedVersion, please see the Version class for alternatives.", DeprecationWarning) -warnings.filterwarnings("ignore", "Accessed deprecated property Package.candidateVersion, please see the Version class for alternatives.", DeprecationWarning) -warnings.filterwarnings("ignore", "Deprecated, please use 'is_installed' instead", DeprecationWarning) -warnings.filterwarnings("ignore", "Deprecated, please use 'mark_delete()' instead", DeprecationWarning) -warnings.filterwarnings("ignore", "Attribute 'IsUpgradable' of the 'apt_pkg.DepCache' object is deprecated, use 'is_upgradable' instead.", DeprecationWarning) -warnings.filterwarnings("ignore", "Attribute 'VersionList' of the 'apt_pkg.Package' object is deprecated, use 'version_list' instead.", DeprecationWarning) -warnings.filterwarnings("ignore", "Attribute 'VerStr' of the 'apt_pkg.Version' object is deprecated, use 'ver_str' instead.", DeprecationWarning) import apt.cache import os @@ -84,12 +77,20 @@ class APT(Bcfg2.Client.Tools.Tool): raise Bcfg2.Client.Tools.toolInstantiationError self.pkg_cache.update() self.pkg_cache = apt.cache.Cache() + if 'req_reinstall_pkgs' in dir(self.pkg_cache): + self._newapi = True + else: + self._newapi = False def FindExtra(self): """Find extra packages.""" packages = [entry.get('name') for entry in self.getSupportedEntries()] - extras = [(p.name, p.installedVersion) for p in self.pkg_cache - if p.isInstalled and p.name not in packages] + if self._newapi: + extras = [(p.name, p.installed.version) for p in self.pkg_cache + if p.is_installed and p.name not in packages] + else: + extras = [(p.name, p.installedVersion) for p in self.pkg_cache + if p.isInstalled and p.name not in packages] return [Bcfg2.Client.XML.Element('Package', name=name, \ type='deb', version=version) \ for (name, version) in extras] @@ -149,24 +150,38 @@ class APT(Bcfg2.Client.Tools.Tool): (entry.attrib['name'])) return False pkgname = entry.get('name') - if not self.pkg_cache.has_key(pkgname) \ - or not self.pkg_cache[pkgname].isInstalled: + if self.pkg_cache.has_key(pkgname): + if self._newapi: + is_installed = self.pkg_cache[pkgname].is_installed + else: + is_installed = self.pkg_cache[pkgname].isInstalled + if not self.pkg_cache.has_key(pkgname) or not is_installed: self.logger.info("Package %s not installed" % (entry.get('name'))) entry.set('current_exists', 'false') return False pkg = self.pkg_cache[pkgname] + if self._newapi: + installed_version = pkg.installed.version + candidate_version = pkg.candidate.version + else: + installed_version = pkg.installedVersion + candidate_version = pkg.candidateVersion if entry.get('version') == 'auto': - if self.pkg_cache._depcache.IsUpgradable(pkg._pkg): - desiredVersion = pkg.candidateVersion + if self._newapi: + is_upgradable = self.pkg_cache._depcache.is_upgradable(pkg._pkg) + else: + is_upgradable = self.pkg_cache._depcache.IsUpgradable(pkg._pkg) + if is_upgradable: + desiredVersion = candidate_version else: - desiredVersion = pkg.installedVersion + desiredVersion = installed_version elif entry.get('version') == 'any': - desiredVersion = pkg.installedVersion + desiredVersion = installed_version else: desiredVersion = entry.get('version') - if desiredVersion != pkg.installedVersion: - entry.set('current_version', pkg.installedVersion) + if desiredVersion != installed_version: + entry.set('current_version', installed_version) entry.set('qtext', "Modify Package %s (%s -> %s)? (y/N) " % \ (entry.get('name'), entry.get('current_version'), desiredVersion)) @@ -188,9 +203,15 @@ class APT(Bcfg2.Client.Tools.Tool): self.logger.info(pkgnames) for pkg in pkgnames.split(" "): try: - self.pkg_cache[pkg].markDelete(purge=True) + if self._newapi: + self.pkg_cache[pkg].mark_delete(purge=True) + else: + self.pkg_cache[pkg].markDelete(purge=True) except: - self.pkg_cache[pkg].markDelete() + if self._newapi: + self.pkg_cache[pkg].mark_delete() + else: + self.pkg_cache[pkg].markDelete() try: self.pkg_cache.commit() except SystemExit: @@ -210,11 +231,19 @@ class APT(Bcfg2.Client.Tools.Tool): self.logger.error("APT has no information about package %s" % (pkg.get('name'))) continue if pkg.get('version') in ['auto', 'any']: - ipkgs.append("%s=%s" % (pkg.get('name'), - self.pkg_cache[pkg.get('name')].candidateVersion)) + if self._newapi: + ipkgs.append("%s=%s" % (pkg.get('name'), + self.pkg_cache[pkg.get('name')].candidate.version)) + else: + ipkgs.append("%s=%s" % (pkg.get('name'), + self.pkg_cache[pkg.get('name')].candidateVersion)) continue - avail_vers = [x.VerStr for x in \ - self.pkg_cache[pkg.get('name')]._pkg.VersionList] + if self._newapi: + avail_vers = [x.ver_str for x in \ + self.pkg_cache[pkg.get('name')]._pkg.version_list] + else: + avail_vers = [x.VerStr for x in \ + self.pkg_cache[pkg.get('name')]._pkg.VersionList] if pkg.get('version') in avail_vers: ipkgs.append("%s=%s" % (pkg.get('name'), pkg.get('version'))) continue |