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