| 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 | |
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") |
| 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"] |
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) |
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 |
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")) |
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) |