| 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 | ## df has one record per-line | 
|---|
| 11 | ## | 
|---|
| 12 | def stream(stream, format='df -k'): | 
|---|
| 13 |  | 
|---|
| 14 | if format in ['df -k']: | 
|---|
| 15 | return NewLineStream(stream, header=1) | 
|---|
| 16 | else: | 
|---|
| 17 | raise ParseError, 'Unknown format %s' % (format) | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | ## | 
|---|
| 21 | ## Parse a df record | 
|---|
| 22 | ## | 
|---|
| 23 | ##     df -k | 
|---|
| 24 | ## | 
|---|
| 25 | def parse(record, format='df -k', version=None, tz=None): | 
|---|
| 26 |  | 
|---|
| 27 | fs = ExtendedDict() | 
|---|
| 28 |  | 
|---|
| 29 | if format == 'df -k': | 
|---|
| 30 |  | 
|---|
| 31 | regex = re.compile('^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(\S+).*$') | 
|---|
| 32 |  | 
|---|
| 33 | try: | 
|---|
| 34 |  | 
|---|
| 35 | match = regex.match(record) | 
|---|
| 36 |  | 
|---|
| 37 | fs['device']        = match.group(1) | 
|---|
| 38 | fs['kbytes']        = long(match.group(2)) | 
|---|
| 39 | fs['used']          = long(match.group(3)) | 
|---|
| 40 | fs['avail']         = long(match.group(4)) | 
|---|
| 41 | fs['pct_full']      = int(match.group(5)) | 
|---|
| 42 | fs['mountpoint']    = match.group(6) | 
|---|
| 43 |  | 
|---|
| 44 | return fs | 
|---|
| 45 |  | 
|---|
| 46 | except Exception, e: | 
|---|
| 47 |  | 
|---|
| 48 | raise ParseError, e | 
|---|
| 49 |  | 
|---|
| 50 | else: | 
|---|
| 51 |  | 
|---|
| 52 | raise ParseError, 'Unknown format %s' % (format) | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.