summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Gentoo.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Client/Gentoo.py')
-rw-r--r--src/lib/Client/Gentoo.py57
1 files changed, 23 insertions, 34 deletions
diff --git a/src/lib/Client/Gentoo.py b/src/lib/Client/Gentoo.py
index a42d4b1b6..99390f19e 100644
--- a/src/lib/Client/Gentoo.py
+++ b/src/lib/Client/Gentoo.py
@@ -1,11 +1,7 @@
'''This provides bcfg2 support for Gentoo'''
__revision__ = '$Revision$'
-from os import popen, system, stat
-from popen2 import Popen4
-from glob import glob
-from re import match, compile as regcompile
-
+import glob, os, re
from Bcfg2.Client.Toolset import Toolset
class Gentoo(Toolset):
@@ -19,35 +15,33 @@ class Gentoo(Toolset):
self.installed = {}
self.extra_services = []
self.Refresh()
- system("emerge sync")
+ self.saferun("emerge sync")
def Refresh(self):
'''Refresh memory hashes of packages'''
self.installed = {}
- splitter = regcompile('([\w\-\+]+)-([\d].*)')
+ splitter = re.compile('([\w\-\+]+)-([\d].*)')
# Build list of packages
instp = [splitter.match(fname.split('/')[-1].replace('.ebuild','')).groups()
- for fname in glob('/var/db/pkg/*/*/*.ebuild')]
+ for fname in glob.glob('/var/db/pkg/*/*/*.ebuild')]
for info in instp:
self.installed["%s-%s" % info] = info[1]
def VerifyService(self, entry):
'''Verify Service status for entry'''
- runlevels = popen("/bin/rc-status --list").readlines()
+ runlevels = self.saferun("/bin/rc-status --list")[1]
try:
- crunlevels = popen("/sbin/rc-update show | grep %s" % entry.attrib['name']).readlines()[0].split()[2:]
+ crl = self.saferun("/sbin/rc-update show | grep %s" % entry.attrib['name'])[1][0].split()[2:]
except IndexError:
# Ocurrs when no lines are returned (service not installed)
return False
if entry.get('status') == 'off':
- if len(crunlevels) == 0:
- return True
+ return len(crl) == 0
elif entry.get('status') == 'on':
- if len(crunlevels) > 0:
- return True
+ return len(crl) > 0
return False
def InstallService(self, entry):
@@ -55,21 +49,21 @@ class Gentoo(Toolset):
self.logger.info("Installing Service %s" % (entry.get('name')))
try:
- stat('/etc/init.d/%s' % entry.get('name'))
+ os.stat('/etc/init.d/%s' % entry.get('name'))
except OSError:
self.logger.debug("Init script for service %s does not exist" % entry.get('name'))
return False
if entry.attrib['status'] == 'off':
if self.setup['dryrun']:
- print "Disabling Service %s" % (entry.get('name'))
+ self.logger.info("Disabling Service %s" % (entry.get('name')))
else:
- cmdrc = system("/sbin/rc-update del %s %s" % (entry.attrib['name'], entry.attrib['runlevels']))
+ cmdrc = self.saferun("/sbin/rc-update del %s %s" % (entry.attrib['name'], entry.attrib['runlevels']))[0]
else:
if self.setup['dryrun']:
- print "Enabling Service %s" % (entry.attrib['name'])
+ self.logger.info("Enabling Service %s" % (entry.attrib['name']))
else:
- cmdrc = system("/sbin/rc-update add %s %s" % (entry.attrib['name'], entry.attrib['runlevels']))
+ cmdrc = self.saferun("/sbin/rc-update add %s %s" % (entry.attrib['name'], entry.attrib['runlevels']))[0]
if cmdrc:
return False
return True
@@ -77,11 +71,11 @@ class Gentoo(Toolset):
def VerifyPackage(self, entry, modlist):
'''Verify Package status for entry'''
if not (entry.get('name') and entry.get('version')):
- print "Can't verify package, not enough data."
+ self.logger.error("Can't verify package, not enough data.")
return False
- installed_package = popen("/usr/bin/qpkg --no-color --installed --verbose %s-%s" %
- (entry.get('name'), entry.get('version'))).readlines()
+ installed_package = self.saferun("/usr/bin/qpkg --no-color --installed --verbose %s-%s" %
+ (entry.get('name'), entry.get('version')))[1]
if installed_package:
installed_package = installed_package[0].strip("\n").split('/')[-1]
if installed_package != "%s-%s" % (entry.get('name'), entry.get('version')):
@@ -89,17 +83,11 @@ class Gentoo(Toolset):
if entry.attrib.get('verify', 'true') == 'true':
if self.setup['quick']:
return True
- verp = Popen4("/usr/bin/qpkg --no-color --check %s-%s" %
- (entry.get('name'), entry.get('version')), bufsize=16384)
- odata = verp.fromchild.read()
- vstat = verp.poll()
- while vstat == -1:
- odata += verp.fromchild.read()
- vstat = verp.poll()
- output = [line for line in odata.split("\n") if line]
+ output = self.saferun("/usr/bin/qpkg --no-color --check %s-%s" %
+ (entry.get('name'), entry.get('version')))[1]
differences = output[-1]
- if match("^0/", differences):
+ if re.match("^0/", differences):
return True
else:
for line in output[1:-1]:
@@ -112,7 +100,7 @@ class Gentoo(Toolset):
def Inventory(self):
'''Do standard inventory plus debian extra service check'''
Toolset.Inventory(self)
- allsrv = [ srv.split('/')[-1] for srv in glob('/etc/init.d/*')]
+ allsrv = [ srv.split('/')[-1] for srv in glob.glob('/etc/init.d/*')]
csrv = self.cfg.findall(".//Service")
[allsrv.remove(svc.get('name')) for svc in csrv if svc.get('status') == 'on' and svc.get('name') in allsrv]
self.extra_services = allsrv
@@ -122,13 +110,14 @@ class Gentoo(Toolset):
if len(self.pkgwork) > 0:
if self.setup['remove'] in ['all', 'packages']:
self.logger.info("Removing packages: %s" % (self.pkgwork['remove']))
- system("/usr/bin/emerge --quiet --nospinner unmerge %s" % " ".join(self.pkgwork['remove']))
+ cmd = "/usr/bin/emerge --quiet --nospinner unmerge %s" % " ".join(self.pkgwork['remove'])
+ self.saferun(cmd)
else:
self.logger.info("Need to remove packages: %s" % (self.pkgwork['remove']))
if len(self.extra_services) > 0:
if self.setup['remove'] in ['all', 'services']:
self.logger.info("Removing services: %s" % (self.extra_services))
for service in self.extra_services:
- system("/sbin/rc-update del %s" % service)
+ self.saferun("/sbin/rc-update del %s" % service)
else:
self.logger.info("Need to remove services: %s" % (self.extra_services))