user de...@lists.debian.org
usertag 567137 python-apt-0-8-api
thanks

On Wed, Jan 27, 2010 at 05:21:27PM +0100, Jakub Wilk wrote:
> Package: apt-forktracer
> Version: 0.2
> Severity: minor
> 
> $ apt-forktracer > /dev/null
> /usr/share/apt-forktracer/apt_forktracer/apt_pkg_adapter.py:70: 
> DeprecationWarning: apt_pkg.GetCache() is deprecated. Please see 
> apt_pkg.Cache() for the replacement.
>   self.apt_cache = self.apt_pkg.GetCache(progress)
> /usr/share/apt-forktracer/apt_forktracer/apt_pkg_adapter.py:82: 
> DeprecationWarning: apt_pkg.GetDepCache() is deprecated. Please see 
> apt_pkg.DepCache() for the replacement.
>   apt_depcache = self.apt_pkg.GetDepCache(self.apt_cache)
> 
> 
As part of the python-apt API transition mass bug filing[1],
I would like to ask you to update your package for the new
API using the attached patch.

Please make sure to adjust your dependencies to require
at least version 0.7.93.2 of python-apt; because older
versions may not provide all needed functions.

The first python-apt upload after the Squeeze release will
drop the old API and will get a 'Breaks' for all packages
which have not been adjusted yet. All not-fixed bugs will 
become release critical then.

You can run
        /usr/share/python-apt/migrate-0.8.py
on your files to find places which may need to be
changed (add -c as first parameter for colorized output).

The attached patch is incomplete and does not take care
of the tests. But the tests use pmock which has been
removed and thus need other (perhaps larger) changes
anyway.


[1] http://lists.debian.org/debian-devel/2010/02/msg00424.html

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
From 95de4fabe811f320c52cf4fbff0ee63a5d118ace Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <j...@debian.org>
Date: Mon, 1 Mar 2010 13:40:23 +0100
Subject: [PATCH] Upgrade to the new python-apt API.

This patch changes the code to use the new python-apt API. The
tests are not updated.
---
 debian/control                             |    2 +-
 lib/apt_forktracer/apt_pkg_adapter.py      |   26 ++++++++++----------------
 lib/apt_forktracer/cache_adapter.py        |    6 +++---
 lib/apt_forktracer/depcache_adapter.py     |    2 +-
 lib/apt_forktracer/package_adapter.py      |    8 ++++----
 lib/apt_forktracer/package_file_adapter.py |   16 ++++++++--------
 lib/apt_forktracer/version_adapter.py      |    4 ++--
 7 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/debian/control b/debian/control
index 95482f5..8b57d61 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,7 @@ XS-Python-Version: >= 2.4
 
 Package: apt-forktracer
 Architecture: all
-Depends: python-apt, ${python:Depends}, ${misc:Depends}
+Depends: python-apt (>= 0.7.93), ${python:Depends}, ${misc:Depends}
 XB-Python-Version: ${python:Versions}
 Description: a utility for tracking non-official package versions
  apt-forktracer tries to alleviate the problem that APT stops tracking official
diff --git a/lib/apt_forktracer/apt_pkg_adapter.py b/lib/apt_forktracer/apt_pkg_adapter.py
index 3827d3d..f1aa4d7 100755
--- a/lib/apt_forktracer/apt_pkg_adapter.py
+++ b/lib/apt_forktracer/apt_pkg_adapter.py
@@ -35,24 +35,18 @@ class AptPkgAdapter:
 	def __init__(self, apt_pkg):
 		"""apt_pkg is the imported libapt module to wrap."""
 		self.apt_pkg = apt_pkg
-		# python-apt << 0.6.22 does not have the CurState* attributes
-		if hasattr(apt_pkg, "CurStateInstalled"):
-			self.state_installed = apt_pkg.CurStateInstalled
-			self.state_half_installed = apt_pkg.CurStateHalfInstalled
-			self.state_half_configured = apt_pkg.CurStateHalfConfigured
-			self.state_unpacked = apt_pkg.CurStateUnPacked
-		else:
-			self.state_installed = 6
-			self.state_half_installed = 4
-			self.state_half_configured = 2
-			self.state_unpacked = 1
+
+		self.state_installed = apt_pkg.CURSTATE_INSTALLED
+		self.state_half_installed = apt_pkg.CURSTATE_HALF_INSTALLED
+		self.state_half_configured = apt_pkg.CURSTATE_HALF_CONFIGURED
+		self.state_unpacked = apt_pkg.CURSTATE_UNPACKED
 		self.apt_cache = None
 		self.inited = False
 
 	def init(self):
 		"""Initializes libapt. Must be called before any other method."""
-		self.apt_pkg.InitConfig()
-		self.apt_pkg.InitSystem()
+		self.apt_pkg.init_config()
+		self.apt_pkg.init_system()
 		self.inited = True
 
 	def _assert_initialized(self):
@@ -67,7 +61,7 @@ class AptPkgAdapter:
 		Throws an exception if called before init().
 		"""
 		self._assert_initialized()
-		self.apt_cache = self.apt_pkg.GetCache(progress)
+		self.apt_cache = self.apt_pkg.Cache(progress)
 		return cache_adapter_factory.create_cache_adapter(self.apt_cache, self, reporter)
 
 	def get_depcache_adapter(self, depcache_adapter_factory):
@@ -79,7 +73,7 @@ class AptPkgAdapter:
 		self._assert_initialized()
 		if not self.apt_cache:
 			raise Exception('you must call get_cache_adapter() earlier')
-		apt_depcache = self.apt_pkg.GetDepCache(self.apt_cache)
+		apt_depcache = self.apt_pkg.DepCache(self.apt_cache)
 		return depcache_adapter_factory.create_depcache_adapter(apt_depcache)
 
 	def version_compare(self, version_a, version_b):
@@ -92,7 +86,7 @@ class AptPkgAdapter:
 		self._assert_initialized()
 		if version_a == None or version_b == None:
 			raise ValueError('cannot compare a None version string')
-		return self.apt_pkg.VersionCompare(version_a, version_b)
+		return self.apt_pkg.version_compare(version_a, version_b)
 
 	def version_sort(self, versions):
 		"""Sorts the given versions list of VersionAdapters in situ and also
diff --git a/lib/apt_forktracer/cache_adapter.py b/lib/apt_forktracer/cache_adapter.py
index a379ffe..2720658 100755
--- a/lib/apt_forktracer/cache_adapter.py
+++ b/lib/apt_forktracer/cache_adapter.py
@@ -27,8 +27,8 @@ class _CacheAdapter:
 		self.reporter = reporter
 		self.states_we_check = [ apt_pkg_adapter.state_installed, apt_pkg_adapter.state_half_configured, apt_pkg_adapter.state_half_installed, apt_pkg_adapter.state_unpacked ]
 	def run(self, checker, policy, package_adapter_factory):
-		for package in self.apt_cache.Packages:
-			if package.CurrentState not in self.states_we_check:
+		for package in self.apt_cache.packages:
+			if package.current_state not in self.states_we_check:
 				continue
 			pa = package_adapter_factory.create_package_adapter(package)
 			status = checker.check(pa)
@@ -38,6 +38,6 @@ class _CacheAdapter:
 				self.reporter.report(status)
 
 	def __str__(self):
-		return '<CacheAdapter with %d package(s)>' % len(self.apt_cache.Packages)
+		return '<CacheAdapter with %d package(s)>' % len(self.apt_cache.packages)
 	__repr__ = __str__
 
diff --git a/lib/apt_forktracer/depcache_adapter.py b/lib/apt_forktracer/depcache_adapter.py
index 5851e2f..b6a21ef 100755
--- a/lib/apt_forktracer/depcache_adapter.py
+++ b/lib/apt_forktracer/depcache_adapter.py
@@ -31,7 +31,7 @@ class DepCacheAdapter:
 		"""Returns a VersionAdapter object representing the candidate version
 		of the given PackageAdapter object pkg. Returns None if there is no
 		candidate version."""
-		apt_version = self.apt_dep_cache.GetCandidateVer(pkg.apt_package)
+		apt_version = self.apt_dep_cache.get_candidate_ver(pkg.apt_package)
 		if not apt_version:
 			return None
 		else:
diff --git a/lib/apt_forktracer/package_adapter.py b/lib/apt_forktracer/package_adapter.py
index 97c272a..c294e6c 100755
--- a/lib/apt_forktracer/package_adapter.py
+++ b/lib/apt_forktracer/package_adapter.py
@@ -40,13 +40,13 @@ class PackageAdapter:
 	"""
 	def __init__(self, apt_package):
 		self.apt_package = apt_package
-		self.name = apt_package.Name
-		if apt_package.CurrentVer:
-			self.current_version = VersionAdapter(apt_package.CurrentVer)
+		self.name = apt_package.name
+		if apt_package.current_ver:
+			self.current_version = VersionAdapter(apt_package.current_ver)
 		else:
 			self.current_version = None
 		self.candidate_version = None
-		self.versions = [VersionAdapter(v) for v in apt_package.VersionList]
+		self.versions = [VersionAdapter(v) for v in apt_package.version_list]
 
 	def get_status(self, facter):
 		"""Creates a new Status object based on this one, given a Facter."""
diff --git a/lib/apt_forktracer/package_file_adapter.py b/lib/apt_forktracer/package_file_adapter.py
index 7fd2f03..f37df4b 100755
--- a/lib/apt_forktracer/package_file_adapter.py
+++ b/lib/apt_forktracer/package_file_adapter.py
@@ -21,14 +21,14 @@ class PackageFileAdapter:
 	TYPE_PACKAGE_FILE = 'Debian Package Index'
 	TYPE_DPKG_STATUS = 'Debian dpkg status file'
 	def __init__(self, apt_package_file):
-		self.name = apt_package_file.FileName
-		self.archive = apt_package_file.Archive
-		self.component = apt_package_file.Component
-		self.version = apt_package_file.Version
-		self.origin = apt_package_file.Origin
-		self.label = apt_package_file.Label
-		self.not_automatic = apt_package_file.NotAutomatic
-		self.index_type = apt_package_file.IndexType
+		self.name = apt_package_file.filename
+		self.archive = apt_package_file.archive
+		self.component = apt_package_file.component
+		self.version = apt_package_file.version
+		self.origin = apt_package_file.origin
+		self.label = apt_package_file.label
+		self.not_automatic = apt_package_file.not_automatic
+		self.index_type = apt_package_file.index_type
 
 	def is_official(self, facter):
 		"""Returns True if the package file's origin matches distributor's ID
diff --git a/lib/apt_forktracer/version_adapter.py b/lib/apt_forktracer/version_adapter.py
index aeecb50..d4b0c13 100755
--- a/lib/apt_forktracer/version_adapter.py
+++ b/lib/apt_forktracer/version_adapter.py
@@ -21,8 +21,8 @@ class VersionAdapter:
 	"""Mirror of the aptCache::Version libapt class. See AptPkgAdapter for an
 	explanation of why this is needed."""
 	def __init__(self, apt_version):
-		self.string = apt_version.VerStr
-		self.files = [PackageFileAdapter(pf[0]) for pf in apt_version.FileList]
+		self.string = apt_version.ver_str
+		self.files = [PackageFileAdapter(pf[0]) for pf in apt_version.file_list]
 
 	def is_officially_available(self, facter):
 		"""Returns True if any of the files considers itself official."""
-- 
1.7.0

Attachment: pgpDcwOyyYyQW.pgp
Description: PGP signature

Reply via email to