summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-04-15 23:55:17 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-04-15 23:55:17 +0000
commitadf769447b329a3afb49a4873da0ffd93b9d3a58 (patch)
treeec986c87fd832be1b6331cd16af2f2f9c65779f1 /src
parent93b0d1285dbc7552b4325731f6aa9a9538a7e360 (diff)
downloadbcfg2-adf769447b329a3afb49a4873da0ffd93b9d3a58.tar.gz
bcfg2-adf769447b329a3afb49a4873da0ffd93b9d3a58.tar.bz2
bcfg2-adf769447b329a3afb49a4873da0ffd93b9d3a58.zip
Remove last traces of popen2 from client code
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5167 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Client/Tools/__init__.py50
1 files changed, 12 insertions, 38 deletions
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:
'''