Changeset 2686
- Timestamp:
- 02/12/06 13:32:53 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r2658 r2686 392 392 (perpage, perjob) = charges 393 393 printer.setPrices(perpage, perjob) 394 printer.save() 394 395 395 396 if options["prototype"] : -
pykota/trunk/bin/pkprinters
r2674 r2686 170 170 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 171 171 172 if not options["list"] : 173 self.display("%s...\n" % _("Modification")) 174 175 if options["groups"] : 176 printersgroups = self.storage.getMatchingPrinters(options["groups"]) 177 if not printersgroups : 178 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 179 180 if options["charge"] : 181 try : 182 charges = [float(part) for part in options["charge"].split(',', 1)] 183 except ValueError : 184 raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 185 else : 186 if len(charges) > 2 : 187 charges = charges[:2] 188 if len(charges) != 2 : 189 charges = [charges[0], None] 190 (perpage, perjob) = charges 191 192 if options["maxjobsize"] : 193 try : 194 maxjobsize = int(options["maxjobsize"]) 195 if maxjobsize < 0 : 196 raise ValueError 197 except ValueError : 198 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] 199 else : 200 maxjobsize = None 201 202 nbtotal = len(printers) 203 for i in range(nbtotal) : 204 printer = printers[i] 205 if options["list"] : 172 if options["list"] : 173 for printer in printers : 206 174 parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) 207 175 if parents : … … 214 182 if parents : 215 183 print " %s" % parents 216 else : 184 else : 185 self.display("%s...\n" % _("Modification")) 186 187 if options["groups"] : 188 printersgroups = self.storage.getMatchingPrinters(options["groups"]) 189 if not printersgroups : 190 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 191 else : 192 printersgroups = [] 193 194 if options["charge"] : 195 try : 196 charges = [float(part) for part in options["charge"].split(',', 1)] 197 except ValueError : 198 raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 199 else : 200 if len(charges) > 2 : 201 charges = charges[:2] 202 if len(charges) != 2 : 203 charges = [charges[0], None] 204 (perpage, perjob) = charges 205 206 if options["maxjobsize"] : 207 try : 208 maxjobsize = int(options["maxjobsize"]) 209 if maxjobsize < 0 : 210 raise ValueError 211 except ValueError : 212 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] 213 else : 214 maxjobsize = None 215 216 if options["description"] : 217 description = options["description"].strip() 218 nopassthrough = options["nopassthrough"] 219 passthrough = options["passthrough"] 220 nbtotal = len(printers) 221 for i in range(nbtotal) : 222 printer = printers[i] 217 223 if options["charge"] : 218 224 printer.setPrices(perpage, perjob) 219 if options["description"] is not None :220 printer.setDescription( options["description"].strip())221 if options["nopassthrough"]and printer.PassThrough :222 self.storage.setPrinterPassThroughMode(printer, 0)223 if options["passthrough"]and not printer.PassThrough :224 self.storage.setPrinterPassThroughMode(printer, 1)225 if description is not None : # NB : "" is allowed ! 226 printer.setDescription(description) 227 if nopassthrough and printer.PassThrough : 228 printer.setPassThrough(False) 229 if passthrough and not printer.PassThrough : 230 printer.setPassThrough(True) 225 231 if (maxjobsize is not None) and (printer.MaxJobSize != maxjobsize) : 226 self.storage.setPrinterMaxJobSize(printer,maxjobsize)227 if options["groups"] :228 229 230 231 232 232 printer.setMaxJobSize(maxjobsize) 233 printer.save() 234 for pgroup in printersgroups : 235 if options["remove"] : 236 pgroup.delPrinterFromGroup(printer) 237 else : 238 pgroup.addPrinterToGroup(printer) 233 239 percent = 100.0 * float(i) / float(nbtotal) 234 240 self.display("\r%.02f%%" % percent) -
pykota/trunk/NEWS
r2677 r2686 24 24 - 1.24alpha11 : 25 25 26 - Huge speed improvements when modifying billing codes. 26 - Huge speed improvements when modifying billing codes and 27 printers. 27 28 28 29 - Both pkbcodes and pkprinters now display the percent done -
pykota/trunk/pykota/storage.py
r2676 r2686 164 164 raise AttributeError, name 165 165 166 def save(self) : 167 """Saves the billing code to disk in a single operation.""" 168 if self.isDirty : 169 self.parent.savePrinter(self) 170 self.isDirty = False 171 166 172 def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 167 173 """Adds a job to the printer's history.""" … … 190 196 else : 191 197 self.PricePerJob = float(priceperjob) 192 self. parent.writePrinterPrices(self)198 self.isDirty = True 193 199 194 200 def setDescription(self, description=None) : … … 198 204 else : 199 205 self.Description = str(description) 200 self.parent.writePrinterDescription(self) 206 self.isDirty = True 207 208 def setPassThrough(self, passthrough) : 209 """Sets the printer's passthrough mode.""" 210 self.PassThrough = passthrough 211 self.isDirty = True 212 213 def setMaxJobSize(self, maxjobsize) : 214 """Sets the printer's maximal job size.""" 215 self.MaxJobSize = maxjobsize 216 self.isDirty = True 201 217 202 218 def delete(self) : … … 218 234 if v.Printer.Name == self.Name : 219 235 self.parent.flushEntry("GROUPPQUOTAS", "%s@%s" % (v.Group.Name, v.Printer.Name)) 220 self.Exists = 0 236 self.isDirty = False 237 self.Exists = False 221 238 222 239 class StorageUserPQuota(StorageObject) : … … 453 470 self.parent.deleteBillingCode(self) 454 471 self.parent.flushEntry("BILLINGCODES", self.BillingCode) 472 self.isDirty = False 455 473 self.Exists = False 456 self.isDirty = False457 474 458 475 def reset(self, balance=0.0, pagecounter=0) : 459 476 """Resets the pagecounter and balance for this billing code.""" 460 if self.Balance != balance : 461 self.Balance = balance 462 self.isDirty = True 463 if self.PageCounter != pagecounter : 464 self.PageCounter = pagecounter 465 self.isDirty = True 477 self.Balance = balance 478 self.PageCounter = pagecounter 479 self.isDirty = True 466 480 467 481 def setDescription(self, description=None) : -
pykota/trunk/pykota/storages/ldapstorage.py
r2680 r2686 1017 1017 return self.getGroupPQuota(group, printer) 1018 1018 1019 def writePrinterPrices(self, printer) :1020 """ Write the printer's prices back into the storage."""1019 def savePrinter(self, printer) : 1020 """Saves the printer to the database in a single operation.""" 1021 1021 fields = { 1022 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 1023 "pykotaMaxJobSize" : (printer.MaxJobSize and str(printer.MaxJobSize)) or "0", 1024 "description" : self.userCharsetToDatabase(printer.Description or ""), 1022 1025 "pykotaPricePerPage" : str(printer.PricePerPage), 1023 1026 "pykotaPricePerJob" : str(printer.PricePerJob), 1024 }1025 self.doModify(printer.ident, fields)1026 1027 def writePrinterDescription(self, printer) :1028 """Write the printer's description back into the storage."""1029 fields = {1030 "description" : self.userCharsetToDatabase(printer.Description or ""),1031 }1032 if fields["description"] :1033 self.doModify(printer.ident, fields)1034 1035 def setPrinterMaxJobSize(self, printer, maxjobsize) :1036 """Write the printer's maxjobsize attribute."""1037 fields = {1038 "pykotaMaxJobSize" : (maxjobsize and str(maxjobsize)) or "0",1039 }1040 self.doModify(printer.ident, fields)1041 1042 def setPrinterPassThroughMode(self, printer, passthrough) :1043 """Write the printer's passthrough attribute."""1044 fields = {1045 "pykotaPassThrough" : (passthrough and "t") or "f",1046 1027 } 1047 1028 self.doModify(printer.ident, fields) -
pykota/trunk/pykota/storages/sql.py
r2678 r2686 547 547 return self.getGroupPQuota(group, printer) 548 548 549 def writePrinterPrices(self, printer) : 550 """Write the printer's prices back into the storage.""" 551 self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident))) 552 553 def writePrinterDescription(self, printer) : 554 """Write the printer's description back into the storage.""" 555 description = self.userCharsetToDatabase(printer.Description) 556 self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 557 558 def setPrinterMaxJobSize(self, printer, maxjobsize) : 559 """Write the printer's maxjobsize attribute.""" 560 self.doModify("UPDATE printers SET maxjobsize=%s WHERE id=%s" % (self.doQuote(maxjobsize), self.doQuote(printer.ident))) 561 562 def setPrinterPassThroughMode(self, printer, passthrough) : 563 """Write the printer's passthrough attribute.""" 564 self.doModify("UPDATE printers SET passthrough=%s WHERE id=%s" % (self.doQuote((passthrough and "t") or "f"), self.doQuote(printer.ident))) 549 def savePrinter(self, printer) : 550 """Saves the printer to the database in a single operation.""" 551 self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 552 % (self.doQuote((printer.PassThrough and "t") or "f"), \ 553 self.doQuote(printer.MaxJobSize), \ 554 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 555 self.doQuote(printer.PricePerPage), \ 556 self.doQuote(printer.PricePerJob), \ 557 self.doQuote(printer.ident))) 565 558 566 559 def writeUserOverCharge(self, user, factor) :