source: people/peter.buschman/backup_monitoring/parsing/parsers/du/_du.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: 893 bytes
Line 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8
9##
10## du has one record per-line
11##
12def stream(stream, format='du -k'):
13
14 if format in ['du -k']:
15 return NewLineStream(stream, header=0)
16 else:
17 raise ParseError, 'Unknown format %s' % (format)
18
19
20##
21## Parse a du record
22##
23## du -k
24##
25def parse(record, format='du -k', version=None, tz=None):
26
27 fs = ExtendedDict()
28
29 if format == 'du -k':
30
31 regex = re.compile('^(\d+)\s+(.*)$')
32
33 try:
34
35 match = regex.match(record)
36
37 fs['kbytes'] = long(match.group(1))
38 fs['path'] = match.group(2)
39
40 return fs
41
42 except Exception, e:
43
44 raise ParseError, e
45
46 else:
47
48 raise ParseError, 'Unknown format %s' % (format)
Note: See TracBrowser for help on using the repository browser.