From adf769447b329a3afb49a4873da0ffd93b9d3a58 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 15 Apr 2009 23:55:17 +0000 Subject: Remove last traces of popen2 from client code Signed-off-by: Sol Jerome git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5167 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Tools/__init__.py | 50 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 38 deletions(-) (limited to 'src/lib/Client') diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py index a4e150b9b..e5dedf3aa 100644 --- a/src/lib/Client/Tools/__init__.py +++ b/src/lib/Client/Tools/__init__.py @@ -9,30 +9,17 @@ __all__ = ["Action", "APT", "Blast", "Chkconfig", "DebInit", "Encap", "IPS", drivers = [item for item in __all__ if item not in ['rpmtools']] default = [item for item in drivers if item not in ['RPM', 'Yum']] -import os, popen2, stat, sys, Bcfg2.Client.XML, time +import os +import stat +import sys +import time +from subprocess import Popen, PIPE +import Bcfg2.Client.XML class toolInstantiationError(Exception): '''This error is called if the toolset cannot be instantiated''' pass -class readonlypipe(popen2.Popen4): - '''This pipe sets up stdin --> /dev/null''' - def __init__(self, cmd, bufsize=-1): - popen2._cleanup() - c2pread, c2pwrite = os.pipe() - null = open('/dev/null', 'w+') - self.pid = os.fork() - if self.pid == 0: - # Child - os.dup2(null.fileno(), sys.__stdin__.fileno()) - #os.dup2(p2cread, 0) - os.dup2(c2pwrite, 1) - os.dup2(c2pwrite, 2) - self._run_child(cmd) - os.close(c2pwrite) - self.fromchild = os.fdopen(c2pread, 'r', bufsize) - popen2._active.append(self) - class executor: '''this class runs stuff for us''' def __init__(self, logger): @@ -42,25 +29,12 @@ class executor: '''Run a command in a pipe dealing with stdout buffer overloads''' self.logger.debug('> %s' % command) - runpipe = readonlypipe(command, bufsize=16384) - output = [] - try:#macosx doesn't like this - runpipe.fromchild.flush() - except IOError: - pass - line = runpipe.fromchild.readline() - cmdstat = -1 - while cmdstat == -1: - while line: - if len(line) > 0: - self.logger.debug('< %s' % line[:-1]) - output.append(line[:-1]) - line = runpipe.fromchild.readline() - time.sleep(0.1) - cmdstat = runpipe.poll() - output += [line[:-1] for line in runpipe.fromchild.readlines() \ - if line] - return (cmdstat, output) + p = Popen(command, shell=True, bufsize=16384, + stdin=PIPE, stdout=PIPE, close_fds=True) + output = p.communicate()[0] + for line in output.splitlines(): + self.logger.debug('< %s' % line) + return (p.returncode, output.splitlines()) class Tool: ''' -- cgit v1.2.3-1-g7c22