1 | import re
|
---|
2 |
|
---|
3 | from ....builtins import *
|
---|
4 |
|
---|
5 | from ...exceptions import *
|
---|
6 | from ...expressions import *
|
---|
7 | from ...streams import *
|
---|
8 |
|
---|
9 | re_cannot_connect_on_socket = re.compile('^cannot connect on socket.*$')
|
---|
10 |
|
---|
11 | ##
|
---|
12 | ## bpplclients has one record per-line
|
---|
13 | ##
|
---|
14 | def stream(stream, format='bpplclients -L'):
|
---|
15 |
|
---|
16 | if format in ['bpplclients -L']:
|
---|
17 | return NewLineStream(stream, header=0)
|
---|
18 | else:
|
---|
19 | raise ParseError, 'Unknown format %s' % (format)
|
---|
20 |
|
---|
21 |
|
---|
22 | ##
|
---|
23 | ## Parse a bpplclients record
|
---|
24 | ##
|
---|
25 | ## bpplclients -allunique -L
|
---|
26 | ##
|
---|
27 | def parse(record, format='bpplclients -L', version=None, tz=None):
|
---|
28 |
|
---|
29 | client = ExtendedDict()
|
---|
30 |
|
---|
31 | if format == 'bpplclients -L':
|
---|
32 |
|
---|
33 | if re_cannot_connect_on_socket.match(record):
|
---|
34 | return None
|
---|
35 |
|
---|
36 | regex = re.compile('^Client/HW/OS/Pri:\s+(\S+)\s+(\S+)\s+(\S+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\S+)$')
|
---|
37 |
|
---|
38 | try:
|
---|
39 |
|
---|
40 | match = regex.match(record)
|
---|
41 |
|
---|
42 | client['client'] = match.group(1)
|
---|
43 | client['name'] = match.group(1)
|
---|
44 | client['hw'] = match.group(2)
|
---|
45 | client['os'] = match.group(3)
|
---|
46 | client['pri'] = int(match.group(4))
|
---|
47 |
|
---|
48 | return client
|
---|
49 |
|
---|
50 | except Exception, e:
|
---|
51 |
|
---|
52 | raise ParseError, e
|
---|
53 |
|
---|
54 | else:
|
---|
55 |
|
---|
56 | raise ParseError, 'Unknown format %s' % (format)
|
---|