Switch to unified view

a/web/scweb.py b/web/scweb.py
1
import subprocess
1
import subprocess
2
import sys
2
import sys
3
import bottle
3
import bottle
4
import re
4
import re
5
import time
5
import time
6
7
SPLITRE = '''\|\|'''
8
9
def _listReceivers():
10
    devnull = open('/dev/null', 'w')
11
    try:
12
        data = subprocess.check_output(['scctl', '-lm'], stderr = devnull)
13
    except:
14
        data = "scctl error"
15
    o = []
16
    for line in data.splitlines():
17
        #print >> sys.stderr, line
18
        fields = re.split(SPLITRE, line);
19
        if len(fields) == 4:
20
            status, fname, uuid, uri = fields
21
        elif len(fields) == 3:
22
            status, fname, uuid = fields
23
            uri = ''
24
        else:
25
            status = None
26
        if status:
27
            status = status.strip()
28
        if status is not None:
29
            o.append((fname, status, uuid, uri))
30
    return o
6
31
7
@bottle.route('/static/:path#.+#')
32
@bottle.route('/static/:path#.+#')
8
def server_static(path):
33
def server_static(path):
9
    return bottle.static_file(path, root='./static')
34
    return bottle.static_file(path, root='./static')
10
35
...
...
18
    return dict(title='')
43
    return dict(title='')
19
44
20
@bottle.route('/list')
45
@bottle.route('/list')
21
@bottle.view('list')
46
@bottle.view('list')
22
def listReceivers():
47
def listReceivers():
23
    devnull = open('/dev/null', 'w')
24
    try:
25
        data = subprocess.check_output(['scctl', '-l'], stderr = devnull)
26
    except:
27
        data = "scctl error"
28
    o = []
29
    for line in data.splitlines():
30
        #print >> sys.stderr, line
31
        fields = re.split('''\s+''', line);
32
        if len(fields) == 4:
33
            status, fname, uuid, uri = fields
34
        elif len(fields) == 3:
35
            status, fname, uuid = fields
36
            uri = ''
37
        else:
38
            status = None
39
        if status is not None:
40
            o.append((fname, status, uuid, uri))
41
    return {'receivers' : o}
48
    return {'receivers' : _listReceivers()}
42
49
43
@bottle.route('/assoc')
50
@bottle.route('/assoc')
44
@bottle.post('/assoc')
51
@bottle.post('/assoc')
45
@bottle.view('assoc')
52
@bottle.view('assoc')
46
def assocReceivers():
53
def assocReceivers():
47
    devnull = open('/dev/null', 'w')
54
    devnull = open('/dev/null', 'w')
48
55
49
    assocs = bottle.request.forms.getall('Assoc')
56
    assocs = bottle.request.forms.getall('Assoc')
50
    master = bottle.request.forms.get('Master')
57
    sender = bottle.request.forms.get('Sender')
51
    if master != '' and len(assocs) != 0:
58
    if sender != '' and len(assocs) != 0:
52
        arglist = ['scctl', '-s', master]
59
        arglist = ['scctl', '-r', sender]
53
        for uuid in assocs:
60
        for uuid in assocs:
54
            arglist.append(uuid)
61
            arglist.append(uuid)
62
        print >> sys.stderr, arglist
63
55
            try:
64
        try:
56
                subprocess.check_call(arglist, stderr = devnull)
65
            subprocess.check_call(arglist, stderr = devnull)
57
            except:
66
        except:
58
                pass
67
            pass
59
68
60
    try:
69
    try:
61
        data = subprocess.check_output(['scctl', '-l'], stderr = devnull)
70
        data = subprocess.check_output(['scctl', '-Lm'], stderr = devnull)
62
    except:
71
    except:
63
        data = "scctl error"
72
        data = "scctl error"
64
73
65
    a = []
74
    s = []
66
    o = []
67
    for line in data.splitlines():
75
    for line in data.splitlines():
68
        fields = re.split('''\s+''', line);
76
        fields = re.split(SPLITRE, line);
69
        if len(fields) == 4:
70
            status, fname, uuid, uri = fields
77
        fname, uuid, reason, uri = fields
71
            if status != 'Off' and uri != '':
72
                a.append((fname, status, uuid, uri))
78
        s.append((fname, uuid, uri))
73
            else:
79
74
                o.append((fname, status, uuid, uri))
80
    return {'receivers' : _listReceivers(), 'senders' : s}
75
        elif len(fields) == 3:
76
            status, fname, uuid = fields
77
            o.append(fname, status, uuid, '')
78
    return {'active' : a, 'others' : o}
79
81
80
82
81
@bottle.route('/stop')
83
@bottle.route('/stop')
82
@bottle.post('/stop')
84
@bottle.post('/stop')
83
@bottle.view('stop')
85
@bottle.view('stop')
...
...
88
            subprocess.check_call(['scctl', '-x', uuid], stderr=devnull)
90
            subprocess.check_call(['scctl', '-x', uuid], stderr=devnull)
89
        except:
91
        except:
90
            pass
92
            pass
91
93
92
    try:
94
    try:
93
        data = subprocess.check_output(['scctl', '-l'], stderr = devnull)
95
        data = subprocess.check_output(['scctl', '-lm'], stderr = devnull)
94
    except:
96
    except:
95
        data = "scctl error"
97
        data = "scctl error"
96
98
97
    a = []
99
    a = []
98
    for line in data.splitlines():
100
    for line in data.splitlines():
99
        fields = re.split('''\s+''', line);
101
        fields = re.split(SPLITRE, line);
100
        if len(fields) == 4:
102
        if len(fields) == 4:
101
            status, fname, uuid, uri = fields
103
            status, fname, uuid, uri = fields
102
            if status != 'Off':
104
            if status != 'Off':
103
                a.append((fname, status, uuid, uri))
105
                a.append((fname, status, uuid, uri))
104
        elif len(fields) == 3:
106
        elif len(fields) == 3: