summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Toolset.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-02-28 16:43:12 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-02-28 16:43:12 +0000
commitffd1a5e3b20720f8a63cfa2f83f186e77a8e2f5e (patch)
tree7cffd0d0829b6a7846563fdaf871199f78805b00 /src/lib/Client/Toolset.py
parent0c4bb9314b84e6a798fe9c33767d5cf456462a47 (diff)
downloadbcfg2-ffd1a5e3b20720f8a63cfa2f83f186e77a8e2f5e.tar.gz
bcfg2-ffd1a5e3b20720f8a63cfa2f83f186e77a8e2f5e.tar.bz2
bcfg2-ffd1a5e3b20720f8a63cfa2f83f186e77a8e2f5e.zip
Switch more client toolsets over to the new logging infrastructure
Depricate os.system and os.popen in favor of Toolset.saferun git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1778 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/Toolset.py')
-rw-r--r--src/lib/Client/Toolset.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/Client/Toolset.py b/src/lib/Client/Toolset.py
index aedccce35..744074cd2 100644
--- a/src/lib/Client/Toolset.py
+++ b/src/lib/Client/Toolset.py
@@ -21,6 +21,24 @@ def calcPerms(initial, perms):
tempperms |= perm
return tempperms
+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 Toolset(object):
'''The toolset class contains underlying command support and all states'''
__important__ = []
@@ -49,12 +67,11 @@ class Toolset(object):
'''Run a command in a pipe dealing with stdout buffer overloads'''
self.logger.debug('> %s' % command)
- runpipe = popen2.Popen4(command, bufsize=16384)
- output = runpipe.fromchild.read()
- if len(output) > 0:
- self.logger.debug('< %s' % output)
- cmdstat = runpipe.poll()
+ runpipe = readonlypipe(command, bufsize=16384)
+ output = ''
+ cmdstat = -1
while cmdstat == -1:
+ runpipe.fromchild.flush()
moreOutput = runpipe.fromchild.read()
if len(moreOutput) > 0:
self.logger.debug('< %s' % moreOutput)