4
def service_available(service_name):
5
"""Determine whether a system service is available"""
7
subprocess.check_output(
8
['service', service_name, 'status'],
9
stderr=subprocess.STDOUT).decode('UTF-8')
10
except subprocess.CalledProcessError as e:
11
return b'unrecognized service' not in e.output
16
def add_new_group(group_name, system_group=False, gid=None):
19
cmd.extend(['--gid', str(gid)])
21
cmd.append('--system')
26
cmd.append(group_name)
27
subprocess.check_call(cmd)
31
"""Return /etc/lsb-release in a dict"""
33
with open('/etc/lsb-release', 'r') as lsb:
36
d[k.strip()] = v.strip()
40
def cmp_pkgrevno(package, revno, pkgcache=None):
41
"""Compare supplied revno with the revno of the installed package.
43
* 1 => Installed revno is greater than supplied arg
44
* 0 => Installed revno is the same as supplied arg
45
* -1 => Installed revno is less than supplied arg
47
This function imports apt_cache function from charmhelpers.fetch if
48
the pkgcache argument is None. Be sure to add charmhelpers.fetch if
49
you call this function, or pass an apt_pkg.Cache() instance.
53
from charmhelpers.fetch import apt_cache
54
pkgcache = apt_cache()
55
pkg = pkgcache[package]
56
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)