141 | | self.checkConfiguration() |
142 | | |
143 | | def checkConfiguration(self) : |
144 | | """Checks if configuration is correct. |
145 | | |
146 | | raises PyKotaConfigError in case a problem is detected |
147 | | """ |
148 | | validmethods = [ "lazy" ] # TODO add more methods |
149 | | if self.config.get("global", "method", raw=1).lower() not in validmethods : |
150 | | raise PyKotaConfigError, _("Option method only supports values in %s") % str(validmethods) |
| 193 | def getAccounterBackend(self, printer) : |
| 194 | """Returns the accounter backend to use for a given printer. |
| 195 | |
| 196 | if it is not set, it defaults to 'querying' which means ask printer |
| 197 | for its internal lifetime page counter. |
| 198 | """ |
| 199 | validaccounters = [ "querying" ] |
| 200 | try : |
| 201 | accounter = self.getPrinterOption(printer, "accounter").lower() |
| 202 | except PyKotaConfigError : |
| 203 | accounter = "querying" |
| 204 | if accounter not in validaccounters : |
| 205 | raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printer, str(validaccounters)) |
| 206 | return accounter |
| 207 | |
202 | | fullrequester = self.getPrinterOption(printer, "requester") |
203 | | try : |
204 | | (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] |
205 | | except ValueError : |
206 | | raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) |
207 | | if args.endswith(')') : |
208 | | args = args[:-1] |
209 | | if not args : |
210 | | raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) |
211 | | validrequesters = [ "snmp", "external" ] # TODO : add more requesters |
212 | | if requester not in validrequesters : |
213 | | raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) |
214 | | return (requester, args) |
| 210 | try : |
| 211 | fullrequester = self.getPrinterOption(printer, "requester") |
| 212 | except PyKotaConfigError : |
| 213 | # No requester defined, maybe it is not needed if accounting method |
| 214 | # is not set to 'querying', but if we are called, then the accounting |
| 215 | # method really IS 'querying', and so there's a big problem. |
| 216 | raise PyKotaConfigError, _("Option requester for printer %s was not set") % printer |
| 217 | else : |
| 218 | try : |
| 219 | (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] |
| 220 | except ValueError : |
| 221 | raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) |
| 222 | if args.endswith(')') : |
| 223 | args = args[:-1] |
| 224 | if not args : |
| 225 | raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) |
| 226 | validrequesters = [ "snmp", "external" ] # TODO : add more requesters |
| 227 | if requester not in validrequesters : |
| 228 | raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) |
| 229 | return (requester, args) |