diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-06-01 17:08:24 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-06-01 17:08:24 +0200 |
| commit | e74ead9f918b38bfe8ae5cfe941df4057dcc509e (patch) | |
| tree | 9f678aa2510cb1df272cd5beca5cf551794e6307 /apt | |
| parent | 5a062bb328348cd3a2ac693b579d35d0ce8e11f0 (diff) | |
| parent | 50f9df7e415deb9bb6156ef8f596b6d4d49b23a4 (diff) | |
| download | python-apt-e74ead9f918b38bfe8ae5cfe941df4057dcc509e.tar.gz | |
* merge from debian bzr, remaining changes:
- different mirror list
* data/templates/gNewSense.info.in,
data/templates/gNewSense.mirrors:
- add gNewSense template and mirrors, thanks to Karl Goetz
* apt/cache.py:
- Make Cache.get_changes() much (~35x) faster (Closes: #578074).
- Make Cache.req_reinstall_pkgs much faster as well.
- Make Cache.get_providing_packages() about 1000 times faster.
- Use has_versions and has_provides from apt_pkg.Package where possible.
* apt/package.py:
- Decode using utf-8 in installed_files (LP: #407953).
- Fix fetch_source() to work when source name = binary name (LP: #552400).
- Merge a patch from Sebastian Heinlein to make get_changelog() only
check sources where source version >= binary version (Closes: #581831).
- Add Version.source_version and enhance Sebastian's patch to make use
of it, in order to find the best changelog for the package.
* python:
- Return bool instead of int to Python where possible, looks better.
- Document every class, function, property.
* python/cache.cc:
- Check that 2nd argument to Cache.update() really is a SourceList object.
- Fix PackageFile.not_automatic to use NotAutomatic instead of NotSource.
- Add Package.has_versions to see which packages have at least one version,
and Package.has_provides for provides.
- Add rich compare methods to the Version object.
* python/generic.cc:
- Fix a memory leak when using old attribute names.
- Map ArchiveURI property to archive_uri
* python/progress.cc:
- Do not pass arguments to InstallProgress.wait_child().
* doc:
- Update the long documentation.
* debian/control:
- Change priority to standard, keep -doc and -dev on optional.
* utils/migrate-0.8.py:
- Open files in universal newline support and pass filename to ast.parse.
- Add has_key to the list of deprecated functions.
- Don't abort if parsing failed.
- do not require files to end in .py if they are passed on the command
line or if they contain python somewhere in the shebang line.
* apt/cache.py:
- make cache open silent by default (use apt.progress.base.OpProgress)
* tests/data/aptsources_ports/sources.list:
- fix ports test-data
* tests/test_apt_cache.py:
- add simple test for basic cache/dependency iteration
Diffstat (limited to 'apt')
| -rw-r--r-- | apt/cache.py | 65 | ||||
| -rw-r--r-- | apt/package.py | 49 |
2 files changed, 66 insertions, 48 deletions
diff --git a/apt/cache.py b/apt/cache.py index cfe6bedc..8e07e4d0 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -136,7 +136,7 @@ class Cache(object): progress.update(i/float(size)*100) last = i # drop stuff with no versions (cruft) - if len(pkg.version_list) > 0: + if pkg.has_versions: self._set.add(pkg.name) i += 1 @@ -176,10 +176,14 @@ class Cache(object): def get_changes(self): """ Get the marked changes """ changes = [] - for pkg in self: - if (pkg.marked_upgrade or pkg.marked_install or pkg.marked_delete - or pkg.marked_downgrade or pkg.marked_reinstall): - changes.append(pkg) + marked_keep = self._depcache.marked_keep + for pkg in self._cache.packages: + if not marked_keep(pkg): + try: + changes.append(self._weakref[pkg.name]) + except KeyError: + package = self._weakref[pkg.name] = Package(self, pkg) + changes.append(package) return changes @deprecated_args @@ -211,10 +215,12 @@ class Cache(object): def req_reinstall_pkgs(self): """Return the packages not downloadable packages in reqreinst state.""" reqreinst = set() - for pkg in self: - if (not pkg.candidate.downloadable and - (pkg._pkg.inst_state == apt_pkg.INSTSTATE_REINSTREQ or - pkg._pkg.inst_state == apt_pkg.INSTSTATE_HOLD_REINSTREQ)): + get_candidate_ver = self._depcache.get_candidate_ver + states = frozenset((apt_pkg.INSTSTATE_REINSTREQ, + apt_pkg.INSTSTATE_HOLD_REINSTREQ)) + 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) return reqreinst @@ -269,29 +275,36 @@ class Cache(object): except KeyError: return False else: - return bool(pkg.provides_list and not pkg.version_list) + return bool(pkg.has_provides and not pkg.has_versions) - def get_providing_packages(self, virtual): - """ + def get_providing_packages(self, virtual, candidate_only=True): + """Return a list of all packages providing a virtual package. + Return a list of packages which provide the virtual package of the - specified name + specified name. If 'candidate_only' is False, return all packages + with at least one version providing the virtual package. Otherwise, + return only those packages where the candidate version provides + the virtual package. """ - providers = [] + + providers = set() + get_candidate_ver = self._depcache.get_candidate_ver try: vp = self._cache[virtual] - if len(vp.version_list) != 0: - return providers + if vp.has_versions: + return list(providers) except KeyError: - return providers - for pkg in self: - v = self._depcache.get_candidate_ver(pkg._pkg) - if v is None: - continue - for p in v.provides_list: - if virtual == p[0]: - # we found a pkg that provides this virtual pkg - providers.append(pkg) - return providers + return list(providers) + + for provides, providesver, version in vp.provides_list: + pkg = version.parent_pkg + if not candidate_only or (version == get_candidate_ver(pkg)): + try: + providers.add(self._weakref[pkg.name]) + except KeyError: + package = self._weakref[pkg.name] = Package(self, pkg) + providers.add(package) + return list(providers) @deprecated_args def update(self, fetch_progress=None, pulse_interval=0, diff --git a/apt/package.py b/apt/package.py index 342fb5cf..7dcead02 100644 --- a/apt/package.py +++ b/apt/package.py @@ -379,6 +379,14 @@ class Version(object): return self.package.name @property + def source_version(self): + """Return the version of the source package.""" + try: + return self._records.source_ver or self._cand.ver_str + except IndexError: + return self._cand.ver_str + + @property def priority(self): """Return the priority of the package, as string.""" return self._cand.priority_str @@ -1006,34 +1014,31 @@ class Package(object): src_section = "main" # use the section of the candidate as a starting point section = self.candidate.section - - # get the source version, start with the binaries version - bin_ver = self.candidate.version - src_ver = self.candidate.version - #print "bin: %s" % binver + + # get the source version + src_ver = self.candidate.source_version + try: - # FIXME: This try-statement is too long ... # try to get the source version of the pkg, this differs # for some (e.g. libnspr4 on ubuntu) # this feature only works if the correct deb-src are in the - # sources.list - # otherwise we fall back to the binary version number + # sources.list otherwise we fall back to the binary version number src_records = apt_pkg.SourceRecords() - src_rec = src_records.lookup(src_pkg) - if src_rec: - src_ver = src_records.version - #if apt_pkg.VersionCompare(binver, srcver) > 0: - # srcver = binver - if not src_ver: - src_ver = bin_ver - #print "srcver: %s" % src_ver - section = src_records.section - #print "srcsect: %s" % section - else: - # fail into the error handler - raise SystemError except SystemError: - src_ver = bin_ver + pass + else: + while src_records.lookup(src_pkg): + if not src_records.version: + continue + if self.candidate.source_version == src_records.version: + # Direct match, use it and do not do more lookups. + src_ver = src_records.version + section = src_records.section + break + if apt_pkg.version_compare(src_records.version, src_ver) > 0: + # The version is higher, it seems to match. + src_ver = src_records.version + section = src_records.section section_split = section.split("/", 1) if len(section_split) > 1: |
