Changeset 3413 for pykota/trunk/pykota/accounter.py
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounter.py
r3411 r3413 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 29 29 from pykota.errors import PyKotaAccounterError 30 30 31 class AccounterBase : 31 class AccounterBase : 32 32 """A class to account print usage by querying printers.""" 33 33 def __init__(self, kotafilter, arguments, ispreaccounter=0, name="Unknown") : … … 38 38 self.onerror = self.filter.config.getPrinterOnAccounterError(self.filter.PrinterName) 39 39 self.isSoftware = 1 # by default software accounting 40 self.isPreAccounter = ispreaccounter 40 self.isPreAccounter = ispreaccounter 41 41 self.inkUsage = [] 42 43 def getLastPageCounter(self) : 42 43 def getLastPageCounter(self) : 44 44 """Returns last internal page counter value (possibly faked).""" 45 45 try : 46 46 return self.LastPageCounter or 0 47 except : 47 except : 48 48 return 0 49 50 def beginJob(self, printer) : 49 50 def beginJob(self, printer) : 51 51 """Saves the computed job size.""" 52 52 # computes job's size 53 53 self.JobSize = self.computeJobSize() 54 54 55 55 # get last job information for this printer 56 56 if not self.isPreAccounter : … … 59 59 # The printer hasn't been used yet, from PyKota's point of view 60 60 self.LastPageCounter = 0 61 else : 61 else : 62 62 # get last job size and page counter from Quota Storage 63 # Last lifetime page counter before actual job is 63 # Last lifetime page counter before actual job is 64 64 # last page counter + last job size 65 65 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 66 67 def fakeBeginJob(self) : 66 67 def fakeBeginJob(self) : 68 68 """Do nothing.""" 69 69 pass 70 71 def endJob(self, printer) : 70 71 def endJob(self, printer) : 72 72 """Do nothing.""" 73 73 pass 74 75 def getJobSize(self, printer) : 74 75 def getJobSize(self, printer) : 76 76 """Returns the actual job size.""" 77 77 try : 78 78 return self.JobSize 79 except AttributeError : 79 except AttributeError : 80 80 return 0 81 82 def computeJobSize(self) : 81 82 def computeJobSize(self) : 83 83 """Must be overriden in children classes.""" 84 84 raise RuntimeError, "AccounterBase.computeJobSize() must be overriden !" 85 85 86 86 def openAccounter(kotafilter, ispreaccounter=0) : 87 87 """Returns a connection handle to the appropriate accounter.""" … … 91 91 (backend, args) = kotafilter.config.getAccounterBackend(kotafilter.PrinterName) 92 92 try : 93 accounterbackend = imp.load_source("accounterbackend", 93 accounterbackend = imp.load_source("accounterbackend", 94 94 os.path.join(os.path.dirname(__file__), 95 95 "accounters", … … 97 97 except ImportError : 98 98 raise PyKotaAccounterError, _("Unsupported accounter backend %s") % backend 99 else : 99 else : 100 100 return accounterbackend.Accounter(kotafilter, args, ispreaccounter, backend.lower())