[976] | 1 | import re
|
---|
| 2 |
|
---|
| 3 | from ....builtins import *
|
---|
| 4 |
|
---|
| 5 | from ...exceptions import *
|
---|
| 6 | from ...expressions import *
|
---|
| 7 | from ...streams import *
|
---|
| 8 | from ...autotype import *
|
---|
| 9 |
|
---|
| 10 | re_error = re.compile('^AN[RS]\d+E .*$')
|
---|
| 11 | re_no_match_found = re.compile('^ANR2034E SELECT: No match found using this criteria.*$')
|
---|
| 12 | re_session_rejected = re.compile('^ANS1017E Session rejected: TCP/IP connection failure.*$')
|
---|
| 13 | re_unable_to_establish_session = re.compile('ANS8023E Unable to establish session with server.*$')
|
---|
| 14 |
|
---|
| 15 | ##
|
---|
| 16 | ## dsmadmc records
|
---|
| 17 | ##
|
---|
| 18 | def stream(stream, format='dsmadmc -dataonly=yes -displaymode=list'):
|
---|
| 19 |
|
---|
| 20 | if format in ['dsmadmc -dataonly=yes -displaymode=list']:
|
---|
| 21 | return BlankLineStream(stream, header=0)
|
---|
| 22 | else:
|
---|
| 23 | raise ParseError, 'Unknown format %s' % (format)
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | ##
|
---|
| 27 | ## Parse a dsmadmc record
|
---|
| 28 | ##
|
---|
| 29 | ## dsmadmc -dataonly=yes -displaymode=list
|
---|
| 30 | ##
|
---|
| 31 | def parse(record, format='dsmadmc -dataonly=yes -displaymode=list', version=None, tz=None):
|
---|
| 32 |
|
---|
| 33 | obj = ExtendedDict()
|
---|
| 34 | re_pair = re.compile('^\s*([^:]+):\s+(.*)$')
|
---|
| 35 |
|
---|
| 36 | if format == 'dsmadmc -dataonly=yes -displaymode=list':
|
---|
| 37 |
|
---|
| 38 | try:
|
---|
| 39 |
|
---|
| 40 | for line in record:
|
---|
| 41 |
|
---|
| 42 | if re_error.match(line):
|
---|
| 43 | return None
|
---|
| 44 |
|
---|
| 45 | #if re_no_match_found.match(line):
|
---|
| 46 | # return None
|
---|
| 47 |
|
---|
| 48 | #if re_session_rejected(line):
|
---|
| 49 | # return None
|
---|
| 50 |
|
---|
| 51 | #if re_unable_to_establish_session:
|
---|
| 52 | # return None
|
---|
| 53 |
|
---|
| 54 | match = re_pair.match(line)
|
---|
| 55 |
|
---|
| 56 | key = match.group(1)
|
---|
| 57 | value = match.group(2)
|
---|
| 58 | key = key.lower()
|
---|
| 59 | key = key.replace(' ', '_')
|
---|
| 60 | key = key.replace('/', '_')
|
---|
| 61 | key = key.replace('\\', '_')
|
---|
| 62 | key = key.replace('?', '')
|
---|
| 63 | key = key.replace('.', '')
|
---|
| 64 |
|
---|
| 65 | value = autotype(value, tz=tz)
|
---|
| 66 |
|
---|
| 67 | #if value == '':
|
---|
| 68 | # value = None
|
---|
| 69 |
|
---|
| 70 | obj[key] = value
|
---|
| 71 |
|
---|
| 72 | return obj
|
---|
| 73 |
|
---|
| 74 | except Exception, e:
|
---|
| 75 |
|
---|
| 76 | raise ParseError, e
|
---|
| 77 |
|
---|
| 78 | else:
|
---|
| 79 |
|
---|
| 80 | raise ParseError, 'Unknown format %s' % (format)
|
---|
| 81 |
|
---|
| 82 |
|
---|