109 | | try : |
110 | | jobsize = (self.counterafter - self.counterbefore) |
111 | | if jobsize < 0 : |
112 | | # Try to take care of HP printers |
113 | | # Their internal page counter is saved to NVRAM |
114 | | # only every 10 pages. If the printer was switched |
115 | | # off then back on during the job, and that the |
116 | | # counters difference is negative, we know |
117 | | # the formula (we can't know if more than eleven |
118 | | # pages were printed though) : |
119 | | if jobsize > -10 : |
120 | | jobsize += 10 |
121 | | else : |
122 | | # here we may have got a printer being replaced |
123 | | # DURING the job. This is HIGHLY improbable ! |
124 | | jobsize = 0 |
125 | | except : |
126 | | # takes care of the case where one counter (or both) was never set. |
127 | | jobsize = 0 |
| 112 | if (not self.counterbefore) or (not self.counterafter) : |
| 113 | # there was a problem retrieving page counter |
| 114 | self.filter.printInfo(_("A problem occured while reading printer %s's internal page counter.") % printer.Name, "warn") |
| 115 | if printer.LastJob.Exists : |
| 116 | # if there's a previous job, use the last value from database |
| 117 | self.filter.printInfo(_("Retrieving printer %s's page counter from database instead.") % printer.Name, "warn") |
| 118 | if not self.counterbefore : |
| 119 | self.counterbefore = printer.LastJob.PrinterPageCounter or 0 |
| 120 | if not self.counterafter : |
| 121 | self.counterafter = printer.LastJob.PrinterPageCounter or 0 |
| 122 | before = min(self.counterbefore, self.counterafter) |
| 123 | after = max(self.counterbefore, self.counterafter) |
| 124 | self.counterbefore = before |
| 125 | self.counterafter = after |
| 126 | if self.counterbefore == self.counterafter : |
| 127 | self.filter.printInfo(_("Couldn't retrieve printer %s's internal page counter either before or after printing.") % printer.Name, "warn") |
| 128 | self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") |
| 129 | self.counterafter = self.counterbefore + 1 |
| 130 | else : |
| 131 | self.filter.printInfo(_("No previous job in database for printer %s.") % printer.Name, "warn") |
| 132 | self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") |
| 133 | self.counterbefore = 0 |
| 134 | self.counterafter = 1 |
| 135 | |
| 136 | jobsize = (self.counterafter - self.counterbefore) |
| 137 | if jobsize < 0 : |
| 138 | # Try to take care of HP printers |
| 139 | # Their internal page counter is saved to NVRAM |
| 140 | # only every 10 pages. If the printer was switched |
| 141 | # off then back on during the job, and that the |
| 142 | # counters difference is negative, we know |
| 143 | # the formula (we can't know if more than eleven |
| 144 | # pages were printed though) : |
| 145 | if jobsize > -10 : |
| 146 | jobsize += 10 |
| 147 | else : |
| 148 | # here we may have got a printer being replaced |
| 149 | # DURING the job. This is HIGHLY improbable ! |
| 150 | self.filter.printInfo(_("Inconsistent values for printer %s's internal page counter.") % printer.Name, "warn") |
| 151 | self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") |
| 152 | jobsize = 1 |