diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2011-04-04 12:01:34 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2011-04-04 12:01:34 +0200 |
| commit | 3a4a11628a6f80c2caed9488219f19d52f923917 (patch) | |
| tree | 476e54d05220a6fe65594970b475507e90ebde40 | |
| parent | 50ad561deddca0b239f67ce25fd9800e8bbe94a9 (diff) | |
| parent | 80e04f26777a5c7bd32b40a48f46f8d9f1c8aeb1 (diff) | |
| download | python-apt-3a4a11628a6f80c2caed9488219f19d52f923917.tar.gz | |
merged from debian-sid
| -rw-r--r-- | apt/cache.py | 27 | ||||
| -rw-r--r-- | apt/package.py | 42 | ||||
| -rw-r--r-- | debian/changelog | 20 | ||||
| -rw-r--r-- | debian/control | 2 | ||||
| -rw-r--r-- | debian/python3-apt.install | 2 | ||||
| -rwxr-xr-x | debian/rules | 9 | ||||
| -rw-r--r-- | doc/source/library/apt_pkg.rst | 21 | ||||
| -rw-r--r-- | python/cache.cc | 31 | ||||
| -rw-r--r-- | tests/test_apt_cache.py | 4 | ||||
| -rw-r--r-- | tests/test_debfile.py | 3 |
10 files changed, 135 insertions, 26 deletions
diff --git a/apt/cache.py b/apt/cache.py index 4b917236..bfa41edc 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -65,6 +65,7 @@ class Cache(object): self._callbacks = {} self._weakref = weakref.WeakValueDictionary() self._set = set() + self._fullnameset = set() self._sorted_set = None if memonly: # force apt to build its caches in memory @@ -129,9 +130,13 @@ class Cache(object): self._list = apt_pkg.SourceList() self._list.read_main_list() self._set.clear() + self._fullnameset.clear() self._sorted_set = None self._weakref.clear() + self._have_multi_arch = bool(apt_pkg.config.value_list("APT::" + + "Architectures")) + progress.op = _("Building data structures") i = last = 0 size = len(self._cache.packages) @@ -141,7 +146,9 @@ class Cache(object): last = i # drop stuff with no versions (cruft) if pkg.has_versions: - self._set.add(pkg.name) + self._set.add(pkg.get_fullname(pretty=True)) + if self._have_multi_arch: + self._fullnameset.add(pkg.get_fullname(pretty=False)) i += 1 @@ -153,7 +160,7 @@ class Cache(object): try: return self._weakref[key] except KeyError: - if key in self._set: + if key in self._set or key in self._fullnameset: key = str(key) pkg = self._weakref[key] = Package(self, self._cache[key]) return pkg @@ -174,10 +181,10 @@ class Cache(object): raise StopIteration def has_key(self, key): - return (key in self._set) + return (key in self._set or key in self._fullnameset) def __contains__(self, key): - return (key in self._set) + return (key in self._set or key in self._fullnameset) def __len__(self): return len(self._set) @@ -191,10 +198,11 @@ class Cache(object): marked_keep = self._depcache.marked_keep for pkg in self._cache.packages: if not marked_keep(pkg): + name = pkg.get_fullname(pretty=True) try: - changes.append(self._weakref[pkg.name]) + changes.append(self._weakref[name]) except KeyError: - package = self._weakref[pkg.name] = Package(self, pkg) + package = self._weakref[name] = Package(self, pkg) changes.append(package) return changes @@ -233,7 +241,7 @@ class Cache(object): for pkg in self._cache.packages: cand = get_candidate_ver(pkg) if cand and not cand.downloadable and pkg.inst_state in states: - reqreinst.add(pkg.name) + reqreinst.add(pkg.get_fullname(pretty=True)) return reqreinst def _run_fetcher(self, fetcher): @@ -318,10 +326,11 @@ class Cache(object): for provides, providesver, version in vp.provides_list: pkg = version.parent_pkg if not candidate_only or (version == get_candidate_ver(pkg)): + name = pkg.get_fullname(pretty=True) try: - providers.add(self._weakref[pkg.name]) + providers.add(self._weakref[name]) except KeyError: - package = self._weakref[pkg.name] = Package(self, pkg) + package = self._weakref[name] = Package(self, pkg) providers.add(package) return list(providers) diff --git a/apt/package.py b/apt/package.py index f16ac2a4..d7d5d167 100644 --- a/apt/package.py +++ b/apt/package.py @@ -374,9 +374,9 @@ class Version(object): def source_name(self): """Return the name of the source package.""" try: - return self._records.source_pkg or self.package.name + return self._records.source_pkg or self.package.shortname except IndexError: - return self.package.name + return self.package.shortname @property def source_version(self): @@ -549,7 +549,7 @@ class Version(object): dsc = None record = self._records - source_name = record.source_pkg or self.package.name + source_name = record.source_pkg or self.package.shortname source_version = record.source_ver or self._cand.ver_str source_lookup = src.lookup(source_name) @@ -674,7 +674,8 @@ class Package(object): self._changelog = "" # Cached changelog def __repr__(self): - return '<Package: name:%r id:%r>' % (self._pkg.name, self._pkg.id) + return '<Package: name:%r architecture=%r id:%r>' % (self._pkg.name, + self._pkg.architecture, self._pkg.id) def candidate(self): """Return the candidate version of the package. @@ -706,7 +707,30 @@ class Package(object): @property def name(self): - """Return the name of the package.""" + """Return the name of the package, possibly including architecture. + + If the package is not part of the system's preferred architecture, + return the same as :attr:`fullname`, otherwise return the same + as :attr:`shortname` + + .. versionchanged:: 0.7.100.3 + As part of multi-arch, this field now may include architecture + information. + """ + return self._pkg.get_fullname(True) + + @property + def fullname(self): + """Return the name of the package, including architecture. + + .. versionadded:: 0.7.100.3""" + return self._pkg.get_fullname(False) + + @property + def shortname(self): + """Return the name of the package, without architecture. + + .. versionadded:: 0.7.100.3""" return self._pkg.name @property @@ -757,13 +781,15 @@ class Package(object): """ return getattr(self.installed, 'dependencies', []) - @DeprecatedProperty def architecture(self): """Return the Architecture of the package. - .. deprecated:: 0.7.9 + .. versionchanged:: 0.7.100.3 + This is now the package's architecture in the multi-arch sense, + previously it was the architecture of the candidate version + and deprecated. """ - return getattr(self.candidate, "architecture", None) + return self._pkg.architecture @DeprecatedProperty def candidateDownloadable(self): #pylint: disable-msg=C0103 diff --git a/debian/changelog b/debian/changelog index 0aed50d9..b6c1945f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,7 +12,25 @@ python-apt (0.7.100.3) UNRELEASED; urgency=low - add test for xz compression * update priority of python3-apt to match the archive - -- Michael Vogt <mvo@debian.org> Mon, 21 Mar 2011 15:46:50 +0100 + [ Julian Andres Klode ] + * python/cache.cc: + - Add Package.get_fullname() and Package.architecture + * apt/cache.py, apt/package.py: + - Add architecture property to apt.Package (LP: #703472) + - Change apt.Package.name to use get_fullname(pretty=True) (LP: #740072) + * tests/test_debfile.py: + - Disable multi-arch for the test, it fails when run via test_all.py + - Fix mixed tab/spaces indentation in xz test + * tests/test_apt_cache.py: + - Package records 'Package' field now corresponds to shortname + + [ Scott Kitterman ] + * Override override_dh_auto_install to install python3 extensions in the + correct locations (Closes: #619528) + - Drop .so files from python3-apt.install + * Removed ${python:Breaks} - No longer used in dh_python2 + + -- Julian Andres Klode <jak@debian.org> Mon, 04 Apr 2011 09:48:10 +0200 python-apt (0.7.100.2) unstable; urgency=low diff --git a/debian/control b/debian/control index c434e35b..9985a685 100644 --- a/debian/control +++ b/debian/control @@ -23,7 +23,7 @@ Package: python-apt Architecture: any Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, python-apt-common Recommends: lsb-release, iso-codes, python2.6 -Breaks: debdelta (<< 0.28~), packagekit-backend-apt (<= 0.4.8-0ubuntu4), ${python:Breaks} +Breaks: debdelta (<< 0.28~), packagekit-backend-apt (<= 0.4.8-0ubuntu4) Provides: ${python:Provides} Suggests: python-apt-dbg, python-gtk2, python-vte, python-apt-doc XB-Python-Version: ${python:Versions} diff --git a/debian/python3-apt.install b/debian/python3-apt.install index 352d102b..6335f751 100644 --- a/debian/python3-apt.install +++ b/debian/python3-apt.install @@ -1,4 +1,2 @@ -usr/lib/python3*/*/apt_pkg*.so -usr/lib/python3*/*/apt_inst*.so usr/lib/python3*/*/*/ usr/lib/python3*/*/*.egg-info diff --git a/debian/rules b/debian/rules index a38b4605..d020e901 100755 --- a/debian/rules +++ b/debian/rules @@ -11,6 +11,15 @@ export SHELL = env PATH=$(PATH) sh override_dh_auto_build: dh_auto_build +override_dh_auto_install: + for i in $(shell py3versions -r); do \ + $$i ./setup.py install --install-layout=deb --root $(CURDIR)/debian/python3-apt; \ + done + for i in $(shell py3versions -r); do \ + $$i-dbg ./setup.py install --install-layout=deb --root $(CURDIR)/debian/python3-apt-dbg; \ + done + dh_auto_install + override_dh_installdocs: set -e; if [ -z $(filter -a,$(DH_INTERNAL_OPTIONS)) ]; then \ python setup.py build_sphinx; \ diff --git a/doc/source/library/apt_pkg.rst b/doc/source/library/apt_pkg.rst index 81358bac..426cb97e 100644 --- a/doc/source/library/apt_pkg.rst +++ b/doc/source/library/apt_pkg.rst @@ -437,18 +437,35 @@ Resolving Dependencies with :class:`ProblemResolver` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. class:: Package - Represent a package. A package is uniquely identified by its name - and each package can have zero or more versions which can be + Represent a package. A package is uniquely identified by its name and + architecture and each package can have zero or more versions which can be accessed via the :attr:`version_list` property. Packages can be installed and removed by a :class:`DepCache` object. Attributes: + .. attribute: architecture + + The architecture of the package. This is relevant on multi-arch + systems only. Please note that if a package is Architecture: all, + this value is not "all", but the architecture of the package file + it comes from. + + .. versionadded:: 0.7.100.3 + .. attribute:: current_ver The version currently installed as a :class:`Version` object, or None if the package is not installed. + .. method:: get_fullname([pretty: bool = False]) -> str + + Get the full name of the package, including the architecture. If + *pretty* is ``True``, the architecture is omitted for native packages, + that is, an amd64 "apt" package on an amd64 system would give "apt". + + .. versionadded:: 0.7.100.3 + .. attribute:: has_provides A boolean value determining whether the list available via the diff --git a/python/cache.cc b/python/cache.cc index cd51fcc3..190d4f27 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -509,6 +509,7 @@ PyTypeObject PyPackageList_Type = } MkGet(PackageGetName,PyString_FromString(Pkg.Name())) +MkGet(PackageGetArch,PyString_FromString(Pkg.Arch())) MkGet(PackageGetSection,Safe_FromString(Pkg.Section())) MkGet(PackageGetRevDependsList,CppPyObject_NEW<RDepListStruct>(Owner, &PyDependencyList_Type, Pkg.RevDependsList())) @@ -524,6 +525,25 @@ MkGet(PackageGetImportant,PyBool_FromLong((Pkg->Flags & pkgCache::Flag::Importan #undef MkGet #undef Owner +static const char PackageGetFullName_doc[] = + "get_fullname([pretty: bool = False]) -> str\n\n" + "Get the full name of the package, including the architecture. If\n" + "'pretty' is True, the architecture is omitted for native packages,\n" + "that is, and amd64 apt package on an amd64 system would give 'apt'."; +static PyObject *PackageGetFullName(PyObject *Self,PyObject *Args,PyObject *kwds) +{ + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(Self); + char pretty = 0; + char *kwlist[] = {"pretty", 0}; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "|b", kwlist, + &pretty) == 0) + return 0; + + + return CppPyString(Pkg.FullName(pretty)); +} + static PyObject *PackageGetVersionList(PyObject *Self,void*) { pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(Self); @@ -565,9 +585,18 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) Pkg.CurrentVer()); } + +static PyMethodDef PackageMethods[] = +{ + {"get_fullname",(PyCFunction)PackageGetFullName,METH_VARARGS|METH_KEYWORDS, + PackageGetFullName_doc}, + {} +}; + static PyGetSetDef PackageGetSet[] = { {"name",PackageGetName,0, "The name of the package."}, + {"architecture",PackageGetArch,0, "The architecture of the package."}, {"section",PackageGetSection,0, "The section of the package."}, {"rev_depends_list",PackageGetRevDependsList,0, @@ -656,7 +685,7 @@ PyTypeObject PyPackage_Type = 0, // tp_weaklistoffset 0, // tp_iter 0, // tp_iternext - 0, // tp_methods + PackageMethods, // tp_methods 0, // tp_members PackageGetSet, // tp_getset }; diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index cfb3ab99..cccfc9c8 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -47,10 +47,10 @@ class TestAptCache(unittest.TestCase): # particular, when using compressed indexes, it should not use # tons of seek operations r = pkg.candidate.record - self.assertEqual(r['Package'], pkg.name) + self.assertEqual(r['Package'], pkg.shortname) self.assert_('Version' in r) self.assert_(len(r['Description']) > 0) - self.assert_(str(r).startswith('Package: %s\n' % pkg.name)) + self.assert_(str(r).startswith('Package: %s\n' % pkg.shortname)) def test_get_provided_packages(self): cache = apt.Cache() diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 426bccde..5f6d1aa2 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -47,6 +47,9 @@ class TestDebfilee(unittest.TestCase): def setUp(self): apt_pkg.init_config() apt_pkg.config.set("APT::Architecture","i386") + # FIXME: When run via test_all.py, the tests fail without this if it + # is set in the system. + apt_pkg.config.clear("APT::Architectures") apt_pkg.config.set("Dir::State::status", "./data/test_debs/var/lib/dpkg/status") apt_pkg.config.set("Dir::State::lists", |
