Rev | Line | |
---|
[976] | 1 | import re
|
---|
| 2 |
|
---|
| 3 | from ....builtins import *
|
---|
| 4 |
|
---|
| 5 | from ...exceptions import *
|
---|
| 6 | from ...expressions import *
|
---|
| 7 | from ...streams import *
|
---|
| 8 |
|
---|
| 9 | ##
|
---|
| 10 | ## bpretlevel has one record per-line
|
---|
| 11 | ##
|
---|
| 12 | def stream(stream, format='bpretlevel -L'):
|
---|
| 13 |
|
---|
| 14 | if format in ['bpretlevel -L']:
|
---|
| 15 | return NewLineStream(stream, header=4)
|
---|
| 16 | else:
|
---|
| 17 | raise ParseError, 'Unknown format %s' % (format)
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | ##
|
---|
| 21 | ## Parse a bpretlevel record
|
---|
| 22 | ##
|
---|
| 23 | ## bpretlevel -L
|
---|
| 24 | ##
|
---|
| 25 | def parse(record, format='bpretlevel -L', version=None, tz=None):
|
---|
| 26 |
|
---|
| 27 | retlevel = ExtendedDict()
|
---|
| 28 |
|
---|
| 29 | if format == 'bpretlevel -L':
|
---|
| 30 |
|
---|
| 31 | regex = re.compile('^\s+(\d+)\s+(\d+)\s+\(\s*(\d+)\)\s+(.*)$')
|
---|
| 32 |
|
---|
| 33 | try:
|
---|
| 34 |
|
---|
| 35 | match = regex.match(record)
|
---|
| 36 |
|
---|
| 37 | retlevel['retention_level'] = int(match.group(1))
|
---|
| 38 | retlevel['equivalent_days'] = int(match.group(2))
|
---|
| 39 | retlevel['retention_seconds'] = int(match.group(3))
|
---|
| 40 | retlevel['retention_period'] = match.group(4).rstrip()
|
---|
| 41 |
|
---|
| 42 | return retlevel
|
---|
| 43 |
|
---|
| 44 | except Exception, e:
|
---|
| 45 |
|
---|
| 46 | raise ParseError, e
|
---|
| 47 |
|
---|
| 48 | else:
|
---|
| 49 |
|
---|
| 50 | raise ParseError, 'Unknown format %s' % (format)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.