109 | | if options["groups"] : |
110 | | printersgroups = self.storage.getMatchingPrinters(options["groups"]) |
111 | | if not printersgroups : |
112 | | raise PyKotaToolError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) |
113 | | |
114 | | if options["charge"] : |
115 | | try : |
116 | | charges = [float(part) for part in options["charge"].split(',', 1)] |
117 | | except ValueError : |
118 | | raise PyKotaToolError, _("Invalid charge amount value %s") % options["charge"] |
| 107 | if options["add"] : |
| 108 | billingcodes = [] |
| 109 | for bname in names : |
| 110 | billingcode = self.storage.getBillingCode(bname) |
| 111 | if billingcode.Exists : |
| 112 | if options["skipexisting"] : |
| 113 | self.printInfo(_("Billing code [%s] already exists, skipping.") % billingcode.Name) |
| 114 | else : |
| 115 | self.printInfo(_("Billing code [%s] already exists, will be modified.") % billingcode.Name) |
| 116 | billingcodes.append(billingcode) |
| 117 | else : |
| 118 | billingcode = self.storage.addBillingCode(bname) |
| 119 | if not billingcode.Exists : |
| 120 | raise PyKotaToolError, _("Impossible to add billingcode %s") % bname |
| 121 | else : |
| 122 | billingcodes.append(billingcode) |
| 123 | else : |
| 124 | billingcodes = self.storage.getMatchingBillingCodes(",".join(names)) |
| 125 | if not billingcodes : |
| 126 | raise PyKotaToolError, _("There's no billingcode matching %s") % " ".join(names) |
| 127 | |
| 128 | for billingcode in billingcodes : |
| 129 | if options["delete"] : |
| 130 | billingcode.delete() |
| 131 | elif options["list"] : |
| 132 | print "%s [%s] %s %s %s %.2f %s" % \ |
| 133 | (billingcode.Name, billingcode.Description, \ |
| 134 | billingcode.PageCounter, \ |
| 135 | _("pages"), \ |
| 136 | _("and"), \ |
| 137 | billingcode.Balance, \ |
| 138 | _("credits")) |
120 | | if len(charges) > 2 : |
121 | | charges = charges[:2] |
122 | | if len(charges) != 2 : |
123 | | charges = [charges[0], None] |
124 | | (perpage, perjob) = charges |
125 | | |
126 | | if options["add"] : |
127 | | printers = [] |
128 | | for pname in names : |
129 | | printer = self.storage.getPrinter(pname) |
130 | | if printer.Exists : |
131 | | if options["skipexisting"] : |
132 | | self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) |
133 | | else : |
134 | | self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) |
135 | | printers.append(printer) |
136 | | else : |
137 | | if self.isValidName(pname) : |
138 | | printer = self.storage.addPrinter(pname) |
139 | | if not printer.Exists : |
140 | | raise PyKotaToolError, _("Impossible to add printer %s") % pname |
141 | | else : |
142 | | printers.append(printer) |
143 | | else : |
144 | | raise PyKotaToolError, _("Invalid printer name %s") % pname |
145 | | else : |
146 | | printers = self.storage.getMatchingPrinters(",".join(names)) |
147 | | if not printers : |
148 | | raise PyKotaToolError, _("There's no printer matching %s") % " ".join(names) |
149 | | |
150 | | for printer in printers : |
151 | | if options["delete"] : |
152 | | printer.delete() |
153 | | elif options["list"] : |
154 | | parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) |
155 | | if parents : |
156 | | parents = "%s %s" % (_("in"), parents) |
157 | | print "%s [%s] (%s + #*%s) %s" % \ |
158 | | (printer.Name, printer.Description, printer.PricePerJob, \ |
159 | | printer.PricePerPage, parents) |
160 | | else : |
161 | | if options["charge"] : |
162 | | printer.setPrices(perpage, perjob) |
| 140 | if options["reset"] : |
| 141 | billingcode.reset() |