Changeset 2768 for pykota/trunk/bin
- Timestamp:
- 03/01/06 10:47:49 (18 years ago)
- Location:
- pykota/trunk/bin
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkbcodes
r2765 r2768 106 106 raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) 107 107 108 reset = options["reset"] 109 description = options["description"] 110 if description : 111 description = options["description"].strip() 112 113 if options["delete"] : 108 if options["list"] : 109 for billingcode in billingcodes : 110 print "%s [%s] %s %s %s %.2f %s" % \ 111 (billingcode.BillingCode, billingcode.Description, \ 112 billingcode.PageCounter, \ 113 _("pages"), \ 114 _("and"), \ 115 billingcode.Balance, \ 116 _("credits")) 117 elif options["delete"] : 114 118 self.display("\n%s..." % _("Deletion")) 115 119 self.storage.deleteManyBillingCodes(billingcodes) 116 120 self.display("\n") 117 elif options["add"] : 118 self.display("%s...\n" % _("Creation")) 119 nbtotal = len(names) 120 for i in range(nbtotal) : 121 bname = names[i] 122 billingcode = StorageBillingCode(self.storage, bname) 123 self.modifyBillingCode(billingcode, reset, description) 124 oldbillingcode = self.storage.addBillingCode(billingcode) 125 if oldbillingcode is not None : 126 if options["skipexisting"] : 127 self.printInfo(_("Billing code [%s] already exists, skipping.") % bname) 128 else : 129 self.printInfo(_("Billing code [%s] already exists, will be modified.") % bname) 130 self.modifyBillingCode(oldbillingcode, reset, description) 131 oldbillingcode.save() 132 percent = 100.0 * float(i) / float(nbtotal) 133 self.display("\r%.02f%%" % percent) 134 else : 135 if options["list"] : 136 for billingcode in billingcodes : 137 if billingcode.Exists : 138 print "%s [%s] %s %s %s %.2f %s" % \ 139 (billingcode.BillingCode, billingcode.Description, \ 140 billingcode.PageCounter, \ 141 _("pages"), \ 142 _("and"), \ 143 billingcode.Balance, \ 144 _("credits")) 145 else : 121 else : 122 reset = options["reset"] 123 description = options["description"] 124 if description : 125 description = options["description"].strip() 126 skipexisting = options["skipexisting"] 127 if options["add"] : 128 self.display("%s...\n" % _("Creation")) 129 nbtotal = len(names) 130 for i in range(nbtotal) : 131 bname = names[i] 132 billingcode = StorageBillingCode(self.storage, bname) 133 self.modifyBillingCode(billingcode, reset, description) 134 oldbillingcode = self.storage.addBillingCode(billingcode) 135 if oldbillingcode is not None : 136 if skipexisting : 137 self.printInfo(_("Billing code [%s] already exists, skipping.") % bname) 138 else : 139 self.printInfo(_("Billing code [%s] already exists, will be modified.") % bname) 140 self.modifyBillingCode(oldbillingcode, reset, description) 141 oldbillingcode.save() 142 percent = 100.0 * float(i) / float(nbtotal) 143 self.display("\r%.02f%%" % percent) 144 else : 146 145 self.display("\n%s...\n" % _("Modification")) 147 146 nbtotal = len(billingcodes) … … 152 151 percent = 100.0 * float(i) / float(nbtotal) 153 152 self.display("\r%.02f%%" % percent) 154 153 155 154 if not options["list"] : 156 155 self.done() -
pykota/trunk/bin/pkprinters
r2725 r2768 30 30 31 31 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 32 from pykota.storage import StoragePrinter 32 33 33 34 __doc__ = N_("""pkprinters v%(__version__)s (c) %(__years__)s %(__author__)s … … 124 125 class PKPrinters(PyKotaTool) : 125 126 """A class for a printers manager.""" 127 def modifyPrinter(self, printer, charges, perpage, perjob, description, passthrough, nopassthrough, maxjobsize) : 128 if charges : 129 printer.setPrices(perpage, perjob) 130 if description is not None : # NB : "" is allowed ! 131 printer.setDescription(description) 132 if nopassthrough : 133 printer.setPassThrough(False) 134 if passthrough : 135 printer.setPassThrough(True) 136 if maxjobsize is not None : 137 printer.setMaxJobSize(maxjobsize) 138 139 def managePrintersGroups(self, pgroups, printer, remove) : 140 """Manage printer group membership.""" 141 for pgroup in pgroups : 142 if remove : 143 pgroup.delPrinterFromGroup(printer) 144 else : 145 pgroup.addPrinterToGroup(printer) 146 126 147 def main(self, names, options) : 127 148 """Manage printers.""" … … 129 150 raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 130 151 131 if options["delete"] : 132 self.display("%s...\n" % _("Deletion")) 133 todelete = self.storage.getMatchingPrinters(",".join(names)) 134 nbtotal = len(todelete) 135 for i in range(nbtotal) : 136 entry = todelete[i] 137 if entry.Exists : 138 entry.delete() 139 percent = 100.0 * float(i) / float(nbtotal) 140 self.display("\r%.02f%%" % percent) 152 if not options["add"] : 153 if not options["list"] : 154 self.display(_("Extracting datas...")) 155 if not names : # NB : can't happen for --delete because it's catched earlier 156 names = ["*"] 157 printers = self.storage.getMatchingPrinters(",".join(names)) 158 if not printers : 159 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 160 161 if options["list"] : 162 for printer in printers : 163 parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) 164 print "%s [%s] (%s + #*%s)" % \ 165 (printer.Name, printer.Description, printer.PricePerJob, \ 166 printer.PricePerPage) 167 print " %s" % (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF"))) 168 print " %s" % (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))) 169 if parents : 170 print " %s %s" % (_("in"), parents) 171 print 172 elif options["delete"] : 173 self.display("\n%s..." % _("Deletion")) 174 self.storage.deleteManyPrinters(printers) 175 self.display("\n") 141 176 else : 177 if options["groups"] : 178 printersgroups = self.storage.getMatchingPrinters(options["groups"]) 179 if not printersgroups : 180 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 181 else : 182 printersgroups = [] 183 184 if options["charge"] : 185 try : 186 charges = [float(part) for part in options["charge"].split(',', 1)] 187 except ValueError : 188 raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 189 else : 190 if len(charges) > 2 : 191 charges = charges[:2] 192 if len(charges) != 2 : 193 charges = [charges[0], None] 194 (perpage, perjob) = charges 195 else : 196 charges = perpage = perjob = None 197 198 if options["maxjobsize"] : 199 try : 200 maxjobsize = int(options["maxjobsize"]) 201 if maxjobsize < 0 : 202 raise ValueError 203 except ValueError : 204 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] 205 else : 206 maxjobsize = None 207 208 description = options["description"] 209 if description : 210 description = description.strip() 211 212 nopassthrough = options["nopassthrough"] 213 passthrough = options["passthrough"] 214 remove = options["remove"] 215 skipexisting = options["skipexisting"] 142 216 if options["add"] : 143 217 self.display("%s...\n" % _("Creation")) 144 printers = []145 218 nbtotal = len(names) 146 219 for i in range(nbtotal) : 147 220 pname = names[i] 148 printer = self.storage.getPrinter(pname) 149 if printer.Exists : 150 if options["skipexisting"] : 151 self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) 152 else : 153 self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) 154 printers.append(printer) 155 else : 156 if self.isValidName(pname) : 157 printer = self.storage.addPrinter(pname) 158 if not printer.Exists : 159 raise PyKotaToolError, _("Impossible to add printer %s") % pname 221 if self.isValidName(pname) : 222 printer = StoragePrinter(self.storage, pname) 223 self.modifyPrinter(printer, charges, perpage, perjob,\ 224 description, passthrough, \ 225 nopassthrough, maxjobsize) 226 oldprinter = self.storage.addPrinter(printer) 227 if oldprinter is not None : 228 if skipexisting : 229 self.printInfo(_("Printer %s already exists, skipping.") % pname) 160 230 else : 161 printers.append(printer) 162 else : 163 raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 231 self.printInfo(_("Printer %s already exists, will be modified.") % pname) 232 self.modifyPrinter(oldprinter, charges, \ 233 perpage, perjob, description, \ 234 passthrough, nopassthrough, \ 235 maxjobsize) 236 oldprinter.save() 237 self.managePrintersGroups(printersgroups, oldprinter, remove) 238 elif printersgroups : 239 self.managePrintersGroups(printersgroups, \ 240 self.storage.getPrinter(pname), \ 241 remove) 242 else : 243 raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 164 244 percent = 100.0 * float(i) / float(nbtotal) 165 245 self.display("\r%.02f%%" % percent) 166 self.display("\r100.00%%\r \r%s\n" % _("Done."))167 246 else : 168 if not names : 169 names = ["*"] 170 printers = self.storage.getMatchingPrinters(",".join(names)) 171 if not printers : 172 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 173 174 if options["list"] : 175 for printer in printers : 176 if printer.Exists : 177 parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) 178 print "%s [%s] (%s + #*%s)" % \ 179 (printer.Name, printer.Description, printer.PricePerJob, \ 180 printer.PricePerPage) 181 print " %s" % (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF"))) 182 print " %s" % (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))) 183 if parents : 184 print " %s %s" % (_("in"), parents) 185 print 186 else : 187 self.display("%s...\n" % _("Modification")) 188 189 if options["groups"] : 190 printersgroups = self.storage.getMatchingPrinters(options["groups"]) 191 if not printersgroups : 192 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) 193 else : 194 printersgroups = [] 195 196 if options["charge"] : 197 try : 198 charges = [float(part) for part in options["charge"].split(',', 1)] 199 except ValueError : 200 raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] 201 else : 202 if len(charges) > 2 : 203 charges = charges[:2] 204 if len(charges) != 2 : 205 charges = [charges[0], None] 206 (perpage, perjob) = charges 207 208 if options["maxjobsize"] : 209 try : 210 maxjobsize = int(options["maxjobsize"]) 211 if maxjobsize < 0 : 212 raise ValueError 213 except ValueError : 214 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] 215 else : 216 maxjobsize = None 217 218 description = options["description"] 219 if description : 220 description = description.strip() 221 222 nopassthrough = options["nopassthrough"] 223 passthrough = options["passthrough"] 247 self.display("\n%s...\n" % _("Modification")) 224 248 nbtotal = len(printers) 225 249 for i in range(nbtotal) : 226 250 printer = printers[i] 227 if options["charge"] : 228 printer.setPrices(perpage, perjob) 229 if description is not None : # NB : "" is allowed ! 230 printer.setDescription(description) 231 if nopassthrough and printer.PassThrough : 232 printer.setPassThrough(False) 233 if passthrough and not printer.PassThrough : 234 printer.setPassThrough(True) 235 if (maxjobsize is not None) and (printer.MaxJobSize != maxjobsize) : 236 printer.setMaxJobSize(maxjobsize) 251 self.modifyPrinter(printer, charges, perpage, perjob, \ 252 description, passthrough, \ 253 nopassthrough, maxjobsize) 237 254 printer.save() 238 for pgroup in printersgroups : 239 if options["remove"] : 240 pgroup.delPrinterFromGroup(printer) 241 else : 242 pgroup.addPrinterToGroup(printer) 255 self.managePrintersGroups(printersgroups, printer, remove) 243 256 percent = 100.0 * float(i) / float(nbtotal) 244 257 self.display("\r%.02f%%" % percent) 245 258 246 259 if not options["list"] : 247 self.d isplay("\r100.00%%\r \r%s\n" % _("Done."))260 self.done() 248 261 249 262 if __name__ == "__main__" : … … 285 298 or (options["skipexisting"] and not options["add"]) \ 286 299 or (options["list"] and (options["add"] or options["delete"] or options["groups"] or options["charge"] or options["remove"] or options["description"])) \ 287 or (options["passthrough"] and options["nopassthrough"]) : 300 or (options["passthrough"] and options["nopassthrough"]) \ 301 or (options["remove"] and options["add"]) : 288 302 raise PyKotaCommandLineError, _("incompatible options, see help.") 289 elif options["remove"] and not options["groups"] : 303 elif options["remove"] and not options["groups"] : 290 304 raise PyKotaCommandLineError, _("You have to pass printer groups names on the command line") 291 elif (not args) and ( not options["list"]) :305 elif (not args) and (options["add"] or options["delete"]) : 292 306 raise PyKotaCommandLineError, _("You have to pass printer names on the command line") 293 307 else :