65 | | def beginJob(self, printer, user) : |
66 | | """Saves the computed job size.""" |
67 | | # computes job's size |
68 | | self.JobSize = self.computeJobSize() |
69 | | |
70 | | # get last job information for this printer |
71 | | if not printer.LastJob.Exists : |
72 | | # The printer hasn't been used yet, from PyKota's point of view |
73 | | self.LastPageCounter = 0 |
74 | | else : |
75 | | # get last job size and page counter from Quota Storage |
76 | | # Last lifetime page counter before actual job is |
77 | | # last page counter + last job size |
78 | | self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) |
79 | | |
80 | | def endJob(self, printer, user) : |
81 | | """Do nothing.""" |
82 | | pass |
83 | | |
84 | | def getJobSize(self) : |
85 | | """Returns the actual job size.""" |
86 | | try : |
87 | | return self.JobSize |
88 | | except AttributeError : |
89 | | return 0 |
90 | | |
91 | | def doAccounting(self, printer, user) : |
92 | | """Deletgates the computation of the job size to an external command. |
93 | | |
94 | | The command must print the job size on its standard output and exit successfully. |
95 | | """ |
96 | | self.beginJob(printer, user) |
97 | | |
98 | | # get the job size, which is real job size * number of copies. |
99 | | jobsize = self.getJobSize() * self.filter.copies |
100 | | |
101 | | # Is the current user allowed to print at all ? |
102 | | userpquota = self.filter.storage.getUserPQuota(user, printer) |
103 | | action = self.filter.warnUserPQuota(userpquota) |
104 | | |
105 | | # update the quota for the current user on this printer, if allowed to print |
106 | | if action == "DENY" : |
107 | | jobsize = 0 |
108 | | else : |
109 | | userpquota.increasePagesUsage(jobsize) |
110 | | |
111 | | # adds the current job to history |
112 | | jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) |
113 | | printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) |
114 | | |
115 | | self.endJob(printer, user) |
116 | | |
117 | | return action |
118 | | |