4150e591de
The charm.py file had got too big and complex for efficient maintenance. This refactor tries to break down the charm.py file into logical parts (core, classes, defaults, utils) and also provide tests for those parts. Change-Id: Ifd171b5a47b814cee6c7e53d9a6bae52833caed2
24 lines
670 B
Python
24 lines
670 B
Python
import charmhelpers.fetch as fetch
|
|
|
|
|
|
# TODO: drop once charmhelpers releases a new version
|
|
# with this function in the fetch helper (> 0.9.1)
|
|
def get_upstream_version(package):
|
|
"""Determine upstream version based on installed package
|
|
|
|
@returns None (if not installed) or the upstream version
|
|
"""
|
|
import apt_pkg
|
|
cache = fetch.apt_cache()
|
|
try:
|
|
pkg = cache[package]
|
|
except:
|
|
# the package is unknown to the current apt cache.
|
|
return None
|
|
|
|
if not pkg.current_ver:
|
|
# package is known, but no version is currently installed.
|
|
return None
|
|
|
|
return apt_pkg.upstream_version(pkg.current_ver.ver_str)
|