First crack at restoring mininet python style, assisted by handy

'unpep8' script, which does most of the work.

- topo.py is still in pep8
- not all examples work, but this is due to other issues
This commit is contained in:
Bob Lantz
2010-02-05 02:33:34 -08:00
parent bebe9dbed2
commit 80a8fa62d5
9 changed files with 849 additions and 999 deletions
Executable → Regular
+24 -31
View File
@@ -1,51 +1,44 @@
#!/usr/bin/env python
"""XTerm creation and cleanup.
Utility functions to run an xterm (connected via screen(1)) on each host.
"""
XTerm creation and cleanup.
Utility functions to run an xterm ( connected via screen( 1 ) ) on each host.
Requires xterm(1) and GNU screen(1).
Requires xterm( 1 ) and GNU screen( 1 ).
"""
import re
from subprocess import Popen
from mininet.util import quietRun
def makeXterm(node, title):
'''Run screen on a node, and hook up an xterm.
@param node Node object
@param title base title
@return process created
'''
def makeXterm( node, title ):
"""Run screen on a node, and hook up an xterm.
node: Node object
title: base title
returns: process created"""
title += ': ' + node.name
if not node.inNamespace:
title += ' (root)'
cmd = ['xterm', '-title', title, '-e']
cmd = [ 'xterm', '-title', title, '-e' ]
if not node.execed:
node.cmdPrint('screen -dmS ' + node.name)
cmd += ['screen', '-D', '-RR', '-S', node.name]
node.cmdPrint( 'screen -dmS ' + node.name )
cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
else:
cmd += ['sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log']
return Popen(cmd)
cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
return Popen( cmd )
def cleanUpScreens():
'''Remove moldy old screen sessions.'''
"Remove moldy old screen sessions."
r = r'(\d+.[hsc]\d+)'
output = quietRun('screen -ls').split('\n')
output = quietRun( 'screen -ls' ).split( '\n' )
for line in output:
m = re.search(r, line)
m = re.search( r, line )
if m:
quietRun('screen -S ' + m.group(1) + ' -X kill')
quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
def makeXterms(nodes, title):
'''Create XTerms.
@param nodes list of Node objects
@param title base title for each
@return list of created xterm processes
'''
return [makeXterm(node, title) for node in nodes]
def makeXterms( nodes, title ):
"""Create XTerms.
nodes: list of Node objects
title: base title for each
returns: list of created xterm processes"""
return [ makeXterm( node, title ) for node in nodes ]