- Instead of searching for a particular package name, how about
searching for the package that owns the current file? That's more
likely to be correct *and* it reduces the coupling between upstream
and the package. For example:
import inspect
from os.path import realpath
import apt
def find_package_of(cache, filename):
# This is quicker than you might think.
for pkg in cache:
if pkg.is_installed:
if filename in pkg.installed_files: return pkg
cache = apt.Cache()
source = inspect.getsourcefile(find_package_of)
package = find_package_of(cache, realpath(source))
if package is None:
pass # Check for branch info.
else:
installed = package.installed
# Use the *source* package name and version.
desc = "%s %s" % (installed.source_name, installed.source_version)
- When reporting the branch version, also include the branch's location,
or its name. This is less important to the developer, but could be
very useful in screen-grabs, for example.
A few comments (not a review):
- Instead of searching for a particular package name, how about
searching for the package that owns the current file? That's more
likely to be correct *and* it reduces the coupling between upstream
and the package. For example:
import inspect
from os.path import realpath
import apt
def find_package_ of(cache, filename): files:
return pkg
# This is quicker than you might think.
for pkg in cache:
if pkg.is_installed:
if filename in pkg.installed_
cache = apt.Cache() getsourcefile( find_package_ of) of(cache, realpath(source)) source_ name, installed. source_ version)
source = inspect.
package = find_package_
if package is None:
pass # Check for branch info.
else:
installed = package.installed
# Use the *source* package name and version.
desc = "%s %s" % (installed.
- When reporting the branch version, also include the branch's location,
or its name. This is less important to the developer, but could be
very useful in screen-grabs, for example.