Line | |
---|
1 | import re
|
---|
2 |
|
---|
3 | import time
|
---|
4 | import datetime
|
---|
5 | import pytz
|
---|
6 |
|
---|
7 | from ....builtins import *
|
---|
8 |
|
---|
9 | from ...exceptions import *
|
---|
10 | from ...expressions import *
|
---|
11 | from ...autotype import *
|
---|
12 | from ...streams import *
|
---|
13 |
|
---|
14 | ##
|
---|
15 | ## nbemmcmd feeds have records separated by blank lines
|
---|
16 | ##
|
---|
17 | def stream(stream, format='nbemmcmd -machinealias -getaliases'):
|
---|
18 |
|
---|
19 | if format in ['nbemmcmd -machinealias -getaliases']:
|
---|
20 | return BlankLineStream(stream, header=0)
|
---|
21 | else:
|
---|
22 | raise ParseError, 'Unknown format %s' % (format)
|
---|
23 |
|
---|
24 |
|
---|
25 | ##
|
---|
26 | ## Parse a nbemmcmd record
|
---|
27 | ##
|
---|
28 | ## nbemmcmd -L
|
---|
29 | ##
|
---|
30 | def parse(record, format='nbemmcmd -machinealias -getaliases', version=None, tz=None):
|
---|
31 |
|
---|
32 | if format == 'nbemmcmd -machinealias -getaliases':
|
---|
33 |
|
---|
34 | aliases = []
|
---|
35 |
|
---|
36 | try:
|
---|
37 |
|
---|
38 | #
|
---|
39 | # strip header
|
---|
40 | #
|
---|
41 | # NBEMMCMD, Version:6.5.4
|
---|
42 | #
|
---|
43 | record.pop(0)
|
---|
44 |
|
---|
45 | #
|
---|
46 | # get alias name
|
---|
47 | #
|
---|
48 | try:
|
---|
49 | alias = re.compile('^The following aliases were found for the alias: "(.+)"$').match(record.pop(0)).group(1)
|
---|
50 | except:
|
---|
51 | raise ParseError, 'No alias name found on line 2 of record!'
|
---|
52 |
|
---|
53 | for line in record:
|
---|
54 |
|
---|
55 | if line == 'Command completed successfully.':
|
---|
56 | continue
|
---|
57 |
|
---|
58 | aliases.append(line)
|
---|
59 |
|
---|
60 | return alias, aliases
|
---|
61 |
|
---|
62 | except Exception, e:
|
---|
63 |
|
---|
64 | for line in record:
|
---|
65 | print line
|
---|
66 |
|
---|
67 | raise ParseError, e
|
---|
68 |
|
---|
69 | else:
|
---|
70 |
|
---|
71 | raise ParseError, 'Unknown format %s' % (format)
|
---|
72 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.