Skip to content

Commit

Permalink
New group_by_latest_versions() function
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 25, 2014
1 parent 2d04b1d commit 7f0b409
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions deb_pkg_tools/__init__.py
@@ -1,11 +1,11 @@
# Debian packaging tools.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 22, 2014
# Last Change: June 25, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

# Semi-standard module versioning.
__version__ = '1.22.6'
__version__ = '1.23'

debian_package_dependencies = (
'apt', # apt-get
Expand Down
17 changes: 16 additions & 1 deletion deb_pkg_tools/package.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Package manipulation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 15, 2014
# Last Change: June 25, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand Down Expand Up @@ -225,6 +225,21 @@ def find_latest_version(packages):
raise ValueError(msg % concatenate(sorted(names)))
return packages[-1]

def group_by_latest_versions(packages):
"""
Group package archives by name of package and find latest version of each.
:param packages: A list of filenames (strings) and/or
:py:class:`PackageFile` objects.
:returns: A dictionary with package names as keys and
:py:class:`PackageFile` objects as values.
"""
grouped_packages = collections.defaultdict(set)
for value in packages:
package = parse_filename(value)
grouped_packages[package.name].add(package)
return dict((n, find_latest_version(p)) for n, p in grouped_packages.items())

def inspect_package(archive, cache=None):
"""
Get the metadata and contents from a ``*.deb`` archive.
Expand Down

0 comments on commit 7f0b409

Please sign in to comment.