Package CedarBackup2 :: Package extend :: Module capacity
[hide private]
[frames] | no frames]

Source Code for Module CedarBackup2.extend.capacity

  1  # -*- coding: iso-8859-1 -*- 
  2  # vim: set ft=python ts=3 sw=3 expandtab: 
  3  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
  4  # 
  5  #              C E D A R 
  6  #          S O L U T I O N S       "Software done right." 
  7  #           S O F T W A R E 
  8  # 
  9  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 10  # 
 11  # Copyright (c) 2008 Kenneth J. Pronovici. 
 12  # All rights reserved. 
 13  # 
 14  # This program is free software; you can redistribute it and/or 
 15  # modify it under the terms of the GNU General Public License, 
 16  # Version 2, as published by the Free Software Foundation. 
 17  # 
 18  # This program is distributed in the hope that it will be useful, 
 19  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 21  # 
 22  # Copies of the GNU General Public License are available from 
 23  # the Free Software Foundation website, http://www.gnu.org/. 
 24  # 
 25  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 26  # 
 27  # Author   : Kenneth J. Pronovici <pronovic@ieee.org> 
 28  # Language : Python (>= 2.3) 
 29  # Project  : Cedar Backup, release 2 
 30  # Revision : $Id: capacity.py 871 2008-03-19 01:27:24Z pronovic $ 
 31  # Purpose  : Provides an extension to check remaining media capacity. 
 32  # 
 33  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 34   
 35  ######################################################################## 
 36  # Module documentation 
 37  ######################################################################## 
 38   
 39  """ 
 40  Provides an extension to check remaining media capacity. 
 41   
 42  Some users have asked for advance warning that their media is beginning to fill 
 43  up.  This is an extension that checks the current capacity of the media in the 
 44  writer, and prints a warning if the media is more than X% full, or has fewer 
 45  than X bytes of capacity remaining. 
 46   
 47  @author: Kenneth J. Pronovici <pronovic@ieee.org> 
 48  """ 
 49   
 50  ######################################################################## 
 51  # Imported modules 
 52  ######################################################################## 
 53   
 54  # System modules 
 55  import logging 
 56   
 57  # Cedar Backup modules 
 58  from CedarBackup2.util import displayBytes 
 59  from CedarBackup2.config import ByteQuantity, readByteQuantity, addByteQuantityNode 
 60  from CedarBackup2.xmlutil import createInputDom, addContainerNode, addStringNode 
 61  from CedarBackup2.xmlutil import readFirstChild, readString 
 62  from CedarBackup2.actions.util import createWriter, checkMediaState 
 63   
 64   
 65  ######################################################################## 
 66  # Module-wide constants and variables 
 67  ######################################################################## 
 68   
 69  logger = logging.getLogger("CedarBackup2.log.extend.capacity") 
 70   
 71   
 72  ######################################################################## 
 73  # Percentage class definition 
 74  ######################################################################## 
 75   
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.__repr__()
116
117 - def __cmp__(self, other):
118 """ 119 Definition of equals operator for this class. 120 Lists within this class are "unordered" for equality comparisons. 121 @param other: Other object to compare to. 122 @return: -1/0/1 depending on whether self is C{<}, C{=} or C{&gle CedarBackup2.config.ExtensionsConfig.actions=CedarBackup2.config.ExtensionsConfig-class.html#actions">actions.util import createWriter, checkMediaState 63 64 65 ######################################################################## 66 # Module-wide constants and variables 67 ######################################################################## 68 69 logger = logging.getLogger("CedarBackup2.log.extend.capacity") 70 71 72 ######################################################################## 73 # Percentage class definition 74 ######################################################################## 75
76 -class PercentageQuantity(object):
77 78 """ 79 Class representing a percentage quantity. 80 81 The percentage is maintained internally as a string so that issues of 82 precision can be avoided. It really isn't possible to store a floating 83 point number here while being able to losslessly translate back and forth 84 between XML and object representations. (Perhaps the Python 2.4 Decimal 85 class would have been an option, but I want to stay compatible with Python 86 2.3.) 87 88 Even though the quantity is maintained as a string, the string must be in a 89 valid floating point positive number. Technically, any floating point 90 string format supported by Python is allowble. However, it does not make 91 sense to have a negative percentage in this context. 92 93 @sort: __init__, __repr__, __str__, __cmp__, quantity 94 """ 95
96 - def __init__(self, quantity=None):
97 """ 98 Constructor for the C{PercentageQuantity} class. 99 @param quantity: Percentage quantity, as a string (i.e. "99.9" or "12") 100 @raise ValueError: If the quantity value is invaid. 101 """ 102 self._quantity = None 103 self.quantity = quantity
104
105 - def __repr__(self):
106 """ 107 Official string representation for class instance. 108 """ 109 return "PercentageQuantity(%s)" % (self.quantity)
110
111 - def __str__(self):
112 """ 113 Informal string representation for class instance. 114 """ 115 return self.