source: people/peter.buschman/backup_monitoring/parsing/parsers/bpretlevel/_bpretlevel.py@ 976

Last change on this file since 976 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 1.1 KB
Line 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8
9##
10## bpretlevel has one record per-line
11##
12def 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##
25def 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.