source: people/peter.buschman/backup_monitoring/math/_math.py@ 1029

Last change on this file since 1029 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.5 KB
Line 
1###
2### Math Functions
3###
4import math
5#import cmath
6#import Numeric
7
8##
9## Pad a value in microseconds so that it can be added as a string following the decimal
10## to an integer value to produce a float.
11##
12def micropad(microseconds):
13 digits = '%s' % (microseconds)
14 digit_count = len(digits)
15 if digit_count < 6:
16 for i in range(6 - digit_count):
17 digits = '%s%s' % (0, digits)
18 return digits
19
20##
21## pp_bytes(bytes) - Pretty print a number of bytes with conversion to higher units
22##
23def pp_bytes(bytes, format='%7.2f %s'):
24
25 if bytes < 1024:
26 suffix = ' B'
27 elif bytes >= 1024 and bytes < 1048576:
28 bytes = bytes / 1024.0
29 suffix = 'KB'
30 elif bytes >= 1048576 and bytes < 1073741824:
31 bytes = bytes / 1024.0 / 1024.0
32 suffix = 'MB'
33 elif bytes >= 1073741824 and bytes < 1099511627776:
34 bytes = bytes / 1024.0 / 1024.0 / 1024.0
35 suffix = 'GB'
36 elif bytes >= 1099511627776 and bytes < 1125899906842624:
37 bytes = bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0
38 suffix = 'TB'
39 elif bytes >= 1125899906842624 and bytes < 1152921504606846976:
40 bytes = bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
41 suffix = 'PB'
42
43 return format % (bytes, suffix)
44
45
46##
47## pp_kytes(kytes) - Pretty print a number of kytes with conversion to higher units
48##
49def pp_kbytes(kbytes, format='%7.2f %s'):
50
51 return pp_bytes(kbytes*1024.0, format=format)
Note: See TracBrowser for help on using the repository browser.