131 | | if options["list"] and not names : |
132 | | names = ["*"] |
133 | | |
134 | | if options["groups"] : |
135 | | printersgroups = self.storage.getMatchingPrinters(options["groups"]) |
136 | | if not printersgroups : |
137 | | raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(options["groups"].split(',')) |
138 | | |
139 | | if options["charge"] : |
140 | | try : |
141 | | charges = [float(part) for part in options["charge"].split(',', 1)] |
142 | | except ValueError : |
143 | | raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] |
144 | | else : |
145 | | if len(charges) > 2 : |
146 | | charges = charges[:2] |
147 | | if len(charges) != 2 : |
148 | | charges = [charges[0], None] |
149 | | (perpage, perjob) = charges |
| 131 | if options["delete"] : |
| 132 | self.display("Processing...\n") |
| 133 | todelete = self.storage.getMatchingPrinters(",".join(names)) |
| 134 | nbtotal = len(todelete) |
| 135 | for i in range(nbtotal) : |
| 136 | todelete[i].delete() |
| 137 | percent = 100.0 * float(i) / float(nbtotal) |
| 138 | self.display("\r%.02f%%" % percent) |
| 139 | self.display("\r100.00%%\r ") |
| 140 | self.display("\r%s\n" % _("Done.")) |
| 141 | else : |
| 142 | if options["list"] and not names : |
| 143 | names = ["*"] |
161 | | |
162 | | if options["add"] : |
163 | | printers = [] |
164 | | for pname in names : |
165 | | printer = self.storage.getPrinter(pname) |
166 | | if printer.Exists : |
167 | | if options["skipexisting"] : |
168 | | self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) |
169 | | else : |
170 | | self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) |
171 | | printers.append(printer) |
172 | | else : |
173 | | if self.isValidName(pname) : |
174 | | printer = self.storage.addPrinter(pname) |
175 | | if not printer.Exists : |
176 | | raise PyKotaToolError, _("Impossible to add printer %s") % pname |
| 150 | if options["charge"] : |
| 151 | try : |
| 152 | charges = [float(part) for part in options["charge"].split(',', 1)] |
| 153 | except ValueError : |
| 154 | raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] |
| 155 | else : |
| 156 | if len(charges) > 2 : |
| 157 | charges = charges[:2] |
| 158 | if len(charges) != 2 : |
| 159 | charges = [charges[0], None] |
| 160 | (perpage, perjob) = charges |
| 161 | |
| 162 | if options["maxjobsize"] : |
| 163 | try : |
| 164 | maxjobsize = int(options["maxjobsize"]) |
| 165 | if maxjobsize < 0 : |
| 166 | raise ValueError |
| 167 | except ValueError : |
| 168 | raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options["maxjobsize"] |
| 169 | else : |
| 170 | maxjobsize = None |
| 171 | |
| 172 | |
| 173 | if options["add"] : |
| 174 | printers = [] |
| 175 | for pname in names : |
| 176 | printer = self.storage.getPrinter(pname) |
| 177 | if printer.Exists : |
| 178 | if options["skipexisting"] : |
| 179 | self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) |
179 | | else : |
180 | | raise PyKotaCommandLineError, _("Invalid printer name %s") % pname |
181 | | else : |
182 | | printers = self.storage.getMatchingPrinters(",".join(names)) |
183 | | if not printers : |
184 | | raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) |
185 | | |
186 | | for printer in printers : |
187 | | if options["delete"] : |
188 | | printer.delete() |
189 | | elif options["list"] : |
190 | | parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) |
191 | | if parents : |
192 | | parents = "%s %s" % (_("in"), parents) |
193 | | print "%s [%s] (%s + #*%s)" % \ |
194 | | (printer.Name, printer.Description, printer.PricePerJob, \ |
195 | | printer.PricePerPage) |
196 | | print " %s" % (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF"))) |
197 | | print " %s" % (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))) |
198 | | if parents : |
199 | | print " %s" % parents |
200 | | else : |
201 | | if options["charge"] : |
202 | | printer.setPrices(perpage, perjob) |
203 | | if options["description"] is not None : |
204 | | printer.setDescription(options["description"].strip()) |
205 | | if options["nopassthrough"] and printer.PassThrough : |
206 | | self.storage.setPrinterPassThroughMode(printer, 0) |
207 | | if options["passthrough"] and not printer.PassThrough : |
208 | | self.storage.setPrinterPassThroughMode(printer, 1) |
209 | | if (maxjobsize is not None) and (printer.MaxJobSize != maxjobsize) : |
210 | | self.storage.setPrinterMaxJobSize(printer, maxjobsize) |
211 | | if options["groups"] : |
212 | | for pgroup in printersgroups : |
213 | | if options["remove"] : |
214 | | pgroup.delPrinterFromGroup(printer) |
215 | | else : |
216 | | pgroup.addPrinterToGroup(printer) |
| 183 | else : |
| 184 | if self.isValidName(pname) : |
| 185 | printer = self.storage.addPrinter(pname) |
| 186 | if not printer.Exists : |
| 187 | raise PyKotaToolError, _("Impossible to add printer %s") % pname |
| 188 | else : |
| 189 | printers.append(printer) |
| 190 | else : |
| 191 | raise PyKotaCommandLineError, _("Invalid printer name %s") % pname |
| 192 | else : |
| 193 | printers = self.storage.getMatchingPrinters(",".join(names)) |
| 194 | if not printers : |
| 195 | raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) |
| 196 | |
| 197 | for printer in printers : |
| 198 | if options["list"] : |
| 199 | parents = ", ".join([p.Name for p in self.storage.getParentPrinters(printer)]) |
| 200 | if parents : |
| 201 | parents = "%s %s" % (_("in"), parents) |
| 202 | print "%s [%s] (%s + #*%s)" % \ |
| 203 | (printer.Name, printer.Description, printer.PricePerJob, \ |
| 204 | printer.PricePerPage) |
| 205 | print " %s" % (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF"))) |
| 206 | print " %s" % (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))) |
| 207 | if parents : |
| 208 | print " %s" % parents |
| 209 | else : |
| 210 | if options["charge"] : |
| 211 | printer.setPrices(perpage, perjob) |
| 212 | if options["description"] is not None : |
| 213 | printer.setDescription(options["description"].strip()) |
| 214 | if options["nopassthrough"] and printer.PassThrough : |
| 215 | self.storage.setPrinterPassThroughMode(printer, 0) |
| 216 | if options["passthrough"] and not printer.PassThrough : |
| 217 | self.storage.setPrinterPassThroughMode(printer, 1) |
| 218 | if (maxjobsize is not None) and (printer.MaxJobSize != maxjobsize) : |
| 219 | self.storage.setPrinterMaxJobSize(printer, maxjobsize) |
| 220 | if options["groups"] : |
| 221 | for pgroup in printersgroups : |
| 222 | if options["remove"] : |
| 223 | pgroup.delPrinterFromGroup(printer) |
| 224 | else : |
| 225 | pgroup.addPrinterToGroup(printer) |