def cmp_pkgrevno(package, revno, pkgcache=None): '''Compare supplied revno with the revno of the installed package * 1 => Installed revno is greater than supplied arg * 0 => Installed revno is the same as supplied arg * -1 => Installed revno is less than supplied arg ''' from apt import apt_pkg if not pkgcache: from charmhelpers.fetch import apt_cache pkgcache = apt_cache() pkg = pkgcache[package] return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
def setup_ipv6(): ubuntu_rel = lsb_release()['DISTRIB_CODENAME'].lower() if CompareHostReleases(ubuntu_rel) < "trusty": raise Exception("IPv6 is not supported in the charms for Ubuntu " "versions less than Trusty 14.04") from apt import apt_pkg apt_pkg.init() # Need haproxy >= 1.5.3 for ipv6 so for Trusty if we are <= Kilo we need to # use trusty-backports otherwise we can use the UCA. vc = apt_pkg.version_compare(get_pkg_version('haproxy'), '1.5.3') if ubuntu_rel == 'trusty' and vc == -1: add_source('deb http://archive.ubuntu.com/ubuntu trusty-backports ' 'main') apt_update(fatal=True) apt_install('haproxy/trusty-backports', fatal=True)
def _compress(self, filename): """ Compress given file. :param str filename: The name of the file to compress. """ self.log.debug('Compressing %s ...', filename) sorter = subprocess.Popen( ('apt-sortpkgs', filename + '.tmp'), stdout=subprocess.PIPE, ) tee = subprocess.Popen( ('tee', filename), stdin=subprocess.PIPE, stdout=subprocess.PIPE, ) gzip = subprocess.Popen( ('gzip', ), stdin=tee.stdout, stdout=open(filename + '.gz', 'wb'), ) tee.stdout.close() prev = None for pkg in Packages.iter_paragraphs(sorter.stdout): if prev: if prev["Package"] != pkg["Package"]: tee.stdin.write("%s\n" % prev) elif prev["Filename"].startswith( '../') and not pkg["Filename"].startswith('../'): pass elif not prev["Filename"].startswith( '../') and pkg["Filename"].startswith('../'): continue elif apt_pkg.version_compare(prev["Version"], pkg["Version"]) >= 0: continue prev = pkg if prev: tee.stdin.write("%s\n" % prev) tee.stdin.close() rc_sorter, rc_tee, rc_gzip = sorter.wait(), tee.wait(), gzip.wait() self.log.debug('sorter=%d tee=%d gzip=%d', rc_sorter, rc_tee, rc_gzip) os.remove(filename + '.tmp')
def is_present_in(self, version): """Check if a security issue is present in a specific version of the package.""" return not self.fixed_version or apt_pkg.version_compare( version, self.fixed_version) < 0
from apt import apt_pkg a='1:1.4.0-1~12.04' b='1:1.3.1+2SNAPSHOT20150116220343~2c07fa~devissue6273dspacemets~12.04' vc=apt_pkg.version_compare(a,b) print ('a=',a) print ('b=',b) if vc > 0: print('version a > version b') elif vc == 0: print('version a == version b') elif vc < 0: print('version a < version b')