Revision 80a8fa62 mininet/xterm.py

View differences:

mininet/xterm.py
1 1
#!/usr/bin/env python
2
"""XTerm creation and cleanup.
3 2

  
4
Utility functions to run an xterm (connected via screen(1)) on each host.
3
"""
4
XTerm creation and cleanup.
5
Utility functions to run an xterm ( connected via screen( 1 ) ) on each host.
5 6

  
6
Requires xterm(1) and GNU screen(1).
7
Requires xterm( 1 ) and GNU screen( 1 ).
7 8
"""
8 9

  
9 10
import re
10 11
from subprocess import Popen
11

  
12 12
from mininet.util import quietRun
13 13

  
14

  
15
def makeXterm(node, title):
16
    '''Run screen on a node, and hook up an xterm.
17

  
18
    @param node Node object
19
    @param title base title
20
    @return process created
21
    '''
14
def makeXterm( node, title ):
15
    """Run screen on a node, and hook up an xterm.
16
       node: Node object
17
       title: base title
18
       returns: process created"""
22 19
    title += ': ' + node.name
23 20
    if not node.inNamespace:
24 21
        title += ' (root)'
25
    cmd = ['xterm', '-title', title, '-e']
22
    cmd = [ 'xterm', '-title', title, '-e' ]
26 23
    if not node.execed:
27
        node.cmdPrint('screen -dmS ' + node.name)
28
        cmd += ['screen', '-D', '-RR', '-S', node.name]
24
        node.cmdPrint( 'screen -dmS ' + node.name )
25
        cmd += [ 'screen', '-D', '-RR', '-S', node.name ]
29 26
    else:
30
        cmd += ['sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log']
31
    return Popen(cmd)
32

  
27
        cmd += [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ]
28
    return Popen( cmd )
33 29

  
34 30
def cleanUpScreens():
35
    '''Remove moldy old screen sessions.'''
31
    "Remove moldy old screen sessions."
36 32
    r = r'(\d+.[hsc]\d+)'
37
    output = quietRun('screen -ls').split('\n')
33
    output = quietRun( 'screen -ls' ).split( '\n' )
38 34
    for line in output:
39
        m = re.search(r, line)
35
        m = re.search( r, line )
40 36
        if m:
41
            quietRun('screen -S ' + m.group(1) + ' -X kill')
42

  
43

  
44
def makeXterms(nodes, title):
45
    '''Create XTerms.
46

  
47
    @param nodes list of Node objects
48
    @param title base title for each
49
    @return list of created xterm processes
50
    '''
51
    return [makeXterm(node, title) for node in nodes]
37
            quietRun( 'screen -S ' + m.group( 1 ) + ' -X kill' )
38

  
39
def makeXterms( nodes, title ):
40
    """Create XTerms.
41
       nodes: list of Node objects
42
       title: base title for each
43
       returns: list of created xterm processes"""
44
    return [ makeXterm( node, title ) for node in nodes ]

Also available in: Unified diff