summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Tools/__init__.py
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-05-27 15:32:41 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-05-27 15:32:41 +0000
commit9d4abc43fb2896d8ae1edf107e0b8c5fd5c4e038 (patch)
tree1114774168ad8df510de4f9c628c9a49ffb697fa /src/lib/Client/Tools/__init__.py
parentce2c306c68a01349a28d8a3356ceff3efc153e28 (diff)
downloadbcfg2-9d4abc43fb2896d8ae1edf107e0b8c5fd5c4e038.tar.gz
bcfg2-9d4abc43fb2896d8ae1edf107e0b8c5fd5c4e038.tar.bz2
bcfg2-9d4abc43fb2896d8ae1edf107e0b8c5fd5c4e038.zip
Revert "Remove last traces of popen2 from client code"
This reverts commit 5167. We are still supporting python2.3 on the client. This can be redone once we start supporting 2.4 or greater. Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5257 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/Tools/__init__.py')
-rw-r--r--src/lib/Client/Tools/__init__.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py
index f0ae01a0a..dd950a7ef 100644
--- a/src/lib/Client/Tools/__init__.py
+++ b/src/lib/Client/Tools/__init__.py
@@ -8,17 +8,30 @@ __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
-import stat
-import sys
-import time
-from subprocess import Popen, PIPE
-import Bcfg2.Client.XML
+import os, popen2, stat, sys, Bcfg2.Client.XML, time
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):
@@ -28,12 +41,25 @@ class executor:
'''Run a command in a pipe dealing with stdout buffer overloads'''
self.logger.debug('> %s' % command)
- 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())
+ 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)
class Tool:
'''