[695] | 1 | # PyKota |
---|
[1144] | 2 | # -*- coding: ISO-8859-15 -*- |
---|
[695] | 3 | # |
---|
[952] | 4 | # PyKota : Print Quotas for CUPS and LPRng |
---|
[695] | 5 | # |
---|
[1257] | 6 | # (c) 2003-2004 Jerome Alet <alet@librelogiciel.com> |
---|
[873] | 7 | # This program is free software; you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
[695] | 11 | # |
---|
[873] | 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
[695] | 20 | # |
---|
| 21 | # $Id$ |
---|
| 22 | # |
---|
| 23 | # $Log$ |
---|
[1495] | 24 | # Revision 1.48 2004/05/24 22:45:49 jalet |
---|
| 25 | # New 'enforcement' directive added |
---|
| 26 | # Polling loop improvements |
---|
| 27 | # |
---|
[1483] | 28 | # Revision 1.47 2004/05/18 14:49:20 jalet |
---|
| 29 | # Big code changes to completely remove the need for "requester" directives, |
---|
| 30 | # jsut use "hardware(... your previous requester directive's content ...)" |
---|
| 31 | # |
---|
[1475] | 32 | # Revision 1.46 2004/05/13 13:59:28 jalet |
---|
| 33 | # Code simplifications |
---|
| 34 | # |
---|
[1371] | 35 | # Revision 1.45 2004/03/01 10:22:30 jalet |
---|
| 36 | # Can now extract per printer pre and post hooks from the configuration file |
---|
| 37 | # |
---|
[1356] | 38 | # Revision 1.44 2004/02/20 14:42:21 jalet |
---|
| 39 | # Experimental ldapcache directive added |
---|
| 40 | # |
---|
[1353] | 41 | # Revision 1.43 2004/02/19 14:20:21 jalet |
---|
| 42 | # maildomain pykota.conf directive added. |
---|
| 43 | # Small improvements on mail headers quality. |
---|
| 44 | # |
---|
[1257] | 45 | # Revision 1.42 2004/01/08 14:10:32 jalet |
---|
| 46 | # Copyright year changed. |
---|
| 47 | # |
---|
[1227] | 48 | # Revision 1.41 2003/11/29 20:06:20 jalet |
---|
| 49 | # Added 'utolower' configuration option to convert all usernames to |
---|
| 50 | # lowercase when printing. All database accesses are still and will |
---|
| 51 | # remain case sensitive though. |
---|
| 52 | # |
---|
[1192] | 53 | # Revision 1.40 2003/11/18 23:43:12 jalet |
---|
| 54 | # Mailto can be any external command now, as usual. |
---|
| 55 | # |
---|
[1152] | 56 | # Revision 1.39 2003/10/08 21:41:38 jalet |
---|
| 57 | # External policies for printers works ! |
---|
| 58 | # We can now auto-add users on first print, and do other useful things if needed. |
---|
| 59 | # |
---|
[1148] | 60 | # Revision 1.38 2003/10/07 22:06:05 jalet |
---|
| 61 | # Preliminary code to disable job history |
---|
| 62 | # |
---|
[1144] | 63 | # Revision 1.37 2003/10/07 09:07:28 jalet |
---|
| 64 | # Character encoding added to please latest version of Python |
---|
| 65 | # |
---|
[1130] | 66 | # Revision 1.36 2003/10/02 20:23:18 jalet |
---|
| 67 | # Storage caching mechanism added. |
---|
| 68 | # |
---|
[1111] | 69 | # Revision 1.35 2003/07/29 09:54:03 jalet |
---|
| 70 | # Added configurable LDAP mail attribute support |
---|
| 71 | # |
---|
[1105] | 72 | # Revision 1.34 2003/07/28 09:11:12 jalet |
---|
| 73 | # PyKota now tries to add its attributes intelligently in existing LDAP |
---|
| 74 | # directories. |
---|
| 75 | # |
---|
[1087] | 76 | # Revision 1.33 2003/07/16 21:53:07 jalet |
---|
| 77 | # Really big modifications wrt new configuration file's location and content. |
---|
| 78 | # |
---|
[1077] | 79 | # Revision 1.32 2003/07/08 19:43:51 jalet |
---|
| 80 | # Configurable warning messages. |
---|
| 81 | # Poor man's treshold value added. |
---|
| 82 | # |
---|
[1068] | 83 | # Revision 1.31 2003/07/07 11:49:24 jalet |
---|
| 84 | # Lots of small fixes with the help of PyChecker |
---|
| 85 | # |
---|
[1041] | 86 | # Revision 1.30 2003/06/25 14:10:01 jalet |
---|
| 87 | # Hey, it may work (edpykota --reset excepted) ! |
---|
| 88 | # |
---|
[1029] | 89 | # Revision 1.29 2003/06/14 22:44:21 jalet |
---|
| 90 | # More work on LDAP storage backend. |
---|
| 91 | # |
---|
[1021] | 92 | # Revision 1.28 2003/06/10 16:37:54 jalet |
---|
| 93 | # Deletion of the second user which is not needed anymore. |
---|
| 94 | # Added a debug configuration field in /etc/pykota.conf |
---|
| 95 | # All queries can now be sent to the logger in debug mode, this will |
---|
| 96 | # greatly help improve performance when time for this will come. |
---|
| 97 | # |
---|
[1000] | 98 | # Revision 1.27 2003/05/27 23:00:21 jalet |
---|
| 99 | # Big rewrite of external accounting methods. |
---|
| 100 | # Should work well now. |
---|
| 101 | # |
---|
[980] | 102 | # Revision 1.26 2003/04/30 19:53:58 jalet |
---|
| 103 | # 1.05 |
---|
| 104 | # |
---|
[976] | 105 | # Revision 1.25 2003/04/30 13:36:40 jalet |
---|
| 106 | # Stupid accounting method was added. |
---|
| 107 | # |
---|
[973] | 108 | # Revision 1.24 2003/04/29 18:37:54 jalet |
---|
| 109 | # Pluggable accounting methods (actually doesn't support external scripts) |
---|
| 110 | # |
---|
[956] | 111 | # Revision 1.23 2003/04/24 11:53:48 jalet |
---|
| 112 | # Default policy for unknown users/groups is to DENY printing instead |
---|
| 113 | # of the previous default to ALLOW printing. This is to solve an accuracy |
---|
| 114 | # problem. If you set the policy to ALLOW, jobs printed by in nexistant user |
---|
| 115 | # (from PyKota's POV) will be charged to the next user who prints on the |
---|
| 116 | # same printer. |
---|
| 117 | # |
---|
[952] | 118 | # Revision 1.22 2003/04/23 22:13:57 jalet |
---|
| 119 | # Preliminary support for LPRng added BUT STILL UNTESTED. |
---|
| 120 | # |
---|
[873] | 121 | # Revision 1.21 2003/03/29 13:45:27 jalet |
---|
| 122 | # GPL paragraphs were incorrectly (from memory) copied into the sources. |
---|
| 123 | # Two README files were added. |
---|
| 124 | # Upgrade script for PostgreSQL pre 1.01 schema was added. |
---|
| 125 | # |
---|
[872] | 126 | # Revision 1.20 2003/03/29 13:08:28 jalet |
---|
| 127 | # Configuration is now expected to be found in /etc/pykota.conf instead of |
---|
| 128 | # in /etc/cups/pykota.conf |
---|
| 129 | # Installation script can move old config files to the new location if needed. |
---|
| 130 | # Better error handling if configuration file is absent. |
---|
| 131 | # |
---|
[854] | 132 | # Revision 1.19 2003/03/16 09:56:52 jalet |
---|
| 133 | # Mailto option now accepts some additional values which all mean that |
---|
| 134 | # nobody will receive any email message. |
---|
| 135 | # Mailto option now works. Version 1.01 is now officially out. |
---|
| 136 | # |
---|
[853] | 137 | # Revision 1.18 2003/03/16 08:00:50 jalet |
---|
| 138 | # Default hard coded options are now used if they are not set in the |
---|
| 139 | # configuration file. |
---|
| 140 | # |
---|
[852] | 141 | # Revision 1.17 2003/03/15 23:01:28 jalet |
---|
| 142 | # New mailto option in configuration file added. |
---|
| 143 | # No time to test this tonight (although it should work). |
---|
| 144 | # |
---|
[804] | 145 | # Revision 1.16 2003/02/17 23:01:56 jalet |
---|
| 146 | # Typos |
---|
| 147 | # |
---|
[802] | 148 | # Revision 1.15 2003/02/17 22:55:01 jalet |
---|
| 149 | # More options can now be set per printer or globally : |
---|
| 150 | # |
---|
[804] | 151 | # admin |
---|
| 152 | # adminmail |
---|
| 153 | # gracedelay |
---|
| 154 | # requester |
---|
[802] | 155 | # |
---|
| 156 | # the printer option has priority when both are defined. |
---|
| 157 | # |
---|
[800] | 158 | # Revision 1.14 2003/02/17 22:05:50 jalet |
---|
| 159 | # Storage backend now supports admin and user passwords (untested) |
---|
| 160 | # |
---|
[789] | 161 | # Revision 1.13 2003/02/10 11:47:39 jalet |
---|
| 162 | # Moved some code down into the requesters |
---|
| 163 | # |
---|
[786] | 164 | # Revision 1.12 2003/02/10 10:36:33 jalet |
---|
| 165 | # Small problem wrt external requester |
---|
| 166 | # |
---|
[785] | 167 | # Revision 1.11 2003/02/10 08:50:45 jalet |
---|
| 168 | # External requester seems to be finally ok now |
---|
| 169 | # |
---|
[783] | 170 | # Revision 1.10 2003/02/10 08:19:57 jalet |
---|
| 171 | # tell ConfigParser to return raw data, this allows our own strings |
---|
| 172 | # interpolations in the requester |
---|
| 173 | # |
---|
[781] | 174 | # Revision 1.9 2003/02/10 00:44:38 jalet |
---|
| 175 | # Typos |
---|
| 176 | # |
---|
[780] | 177 | # Revision 1.8 2003/02/10 00:42:17 jalet |
---|
| 178 | # External requester should be ok (untested) |
---|
| 179 | # New syntax for configuration file wrt requesters |
---|
| 180 | # |
---|
[773] | 181 | # Revision 1.7 2003/02/09 13:05:43 jalet |
---|
| 182 | # Internationalization continues... |
---|
| 183 | # |
---|
[747] | 184 | # Revision 1.6 2003/02/07 22:00:09 jalet |
---|
| 185 | # Bad cut&paste |
---|
| 186 | # |
---|
[731] | 187 | # Revision 1.5 2003/02/06 23:58:05 jalet |
---|
| 188 | # repykota should be ok |
---|
| 189 | # |
---|
[713] | 190 | # Revision 1.4 2003/02/06 09:19:02 jalet |
---|
| 191 | # More robust behavior (hopefully) when the user or printer is not managed |
---|
| 192 | # correctly by the Quota System : e.g. cupsFilter added in ppd file, but |
---|
| 193 | # printer and/or user not 'yet?' in storage. |
---|
| 194 | # |
---|
[708] | 195 | # Revision 1.3 2003/02/05 23:26:22 jalet |
---|
| 196 | # Incorrect handling of grace delay |
---|
| 197 | # |
---|
[707] | 198 | # Revision 1.2 2003/02/05 23:09:20 jalet |
---|
| 199 | # Name conflict |
---|
| 200 | # |
---|
[695] | 201 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 202 | # Initial import into CVS |
---|
| 203 | # |
---|
| 204 | # |
---|
| 205 | # |
---|
| 206 | |
---|
| 207 | import os |
---|
| 208 | import ConfigParser |
---|
| 209 | |
---|
| 210 | class PyKotaConfigError(Exception): |
---|
| 211 | """An exception for PyKota config related stuff.""" |
---|
| 212 | def __init__(self, message = ""): |
---|
| 213 | self.message = message |
---|
| 214 | Exception.__init__(self, message) |
---|
| 215 | def __repr__(self): |
---|
| 216 | return self.message |
---|
| 217 | __str__ = __repr__ |
---|
| 218 | |
---|
| 219 | class PyKotaConfig : |
---|
| 220 | """A class to deal with PyKota's configuration.""" |
---|
| 221 | def __init__(self, directory) : |
---|
| 222 | """Reads and checks the configuration file.""" |
---|
| 223 | self.filename = os.path.join(directory, "pykota.conf") |
---|
[872] | 224 | if not os.path.isfile(self.filename) : |
---|
| 225 | raise PyKotaConfigError, _("Configuration file %s not found.") % self.filename |
---|
[695] | 226 | self.config = ConfigParser.ConfigParser() |
---|
| 227 | self.config.read([self.filename]) |
---|
[1227] | 228 | |
---|
| 229 | def isTrue(self, option) : |
---|
| 230 | """Returns 1 if option is set to true, else 0.""" |
---|
| 231 | if (option is not None) and (option.upper().strip() in ['Y', 'YES', '1', 'ON', 'T', 'TRUE']) : |
---|
| 232 | return 1 |
---|
| 233 | else : |
---|
| 234 | return 0 |
---|
[695] | 235 | |
---|
| 236 | def getPrinterNames(self) : |
---|
| 237 | """Returns the list of configured printers, i.e. all sections names minus 'global'.""" |
---|
| 238 | return [pname for pname in self.config.sections() if pname != "global"] |
---|
| 239 | |
---|
[802] | 240 | def getGlobalOption(self, option, ignore=0) : |
---|
| 241 | """Returns an option from the global section, or raises a PyKotaConfigError if ignore is not set, else returns None.""" |
---|
| 242 | try : |
---|
| 243 | return self.config.get("global", option, raw=1) |
---|
| 244 | except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : |
---|
| 245 | if ignore : |
---|
| 246 | return |
---|
| 247 | else : |
---|
| 248 | raise PyKotaConfigError, _("Option %s not found in section global of %s") % (option, self.filename) |
---|
| 249 | |
---|
[1192] | 250 | def getPrinterOption(self, printername, option) : |
---|
[802] | 251 | """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError.""" |
---|
| 252 | globaloption = self.getGlobalOption(option, ignore=1) |
---|
| 253 | try : |
---|
[1192] | 254 | return self.config.get(printername, option, raw=1) |
---|
[802] | 255 | except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : |
---|
| 256 | if globaloption is not None : |
---|
| 257 | return globaloption |
---|
| 258 | else : |
---|
[1192] | 259 | raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printername, self.filename) |
---|
[802] | 260 | |
---|
[695] | 261 | def getStorageBackend(self) : |
---|
[800] | 262 | """Returns the storage backend information as a Python mapping.""" |
---|
| 263 | backendinfo = {} |
---|
[695] | 264 | for option in [ "storagebackend", "storageserver", \ |
---|
[1087] | 265 | "storagename", "storageuser", \ |
---|
[695] | 266 | ] : |
---|
[804] | 267 | backendinfo[option] = self.getGlobalOption(option) |
---|
[1087] | 268 | backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=1) # password is optional |
---|
| 269 | backendinfo["storageadmin"] = None |
---|
| 270 | backendinfo["storageadminpw"] = None |
---|
| 271 | adminconf = ConfigParser.ConfigParser() |
---|
| 272 | adminconf.read(["/etc/pykota/pykotadmin.conf"]) |
---|
| 273 | if adminconf.sections() : # were we able to read the file ? |
---|
| 274 | try : |
---|
| 275 | backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) |
---|
| 276 | except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : |
---|
| 277 | raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", "/etc/pykota/pykotadmin.conf") |
---|
| 278 | try : |
---|
| 279 | backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) |
---|
| 280 | except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : |
---|
| 281 | pass # Password is optional |
---|
[800] | 282 | return backendinfo |
---|
[695] | 283 | |
---|
[1029] | 284 | def getLDAPInfo(self) : |
---|
| 285 | """Returns some hints for the LDAP backend.""" |
---|
| 286 | ldapinfo = {} |
---|
| 287 | for option in [ "userbase", "userrdn", \ |
---|
[1041] | 288 | "balancebase", "balancerdn", \ |
---|
[1029] | 289 | "groupbase", "grouprdn", "groupmembers", \ |
---|
| 290 | "printerbase", "printerrdn", \ |
---|
| 291 | "userquotabase", "groupquotabase", \ |
---|
| 292 | "jobbase", "lastjobbase", \ |
---|
[1105] | 293 | "newuser", "newgroup", \ |
---|
[1111] | 294 | "usermail", \ |
---|
[1029] | 295 | ] : |
---|
[1105] | 296 | ldapinfo[option] = self.getGlobalOption(option).strip() |
---|
| 297 | for field in ["newuser", "newgroup"] : |
---|
| 298 | if ldapinfo[field].lower().startswith('attach(') : |
---|
| 299 | ldapinfo[field] = ldapinfo[field][7:-1] |
---|
[1029] | 300 | return ldapinfo |
---|
| 301 | |
---|
[695] | 302 | def getLoggingBackend(self) : |
---|
| 303 | """Returns the logging backend information.""" |
---|
[802] | 304 | validloggers = [ "stderr", "system" ] |
---|
[853] | 305 | try : |
---|
| 306 | logger = self.getGlobalOption("logger").lower() |
---|
| 307 | except PyKotaConfigError : |
---|
| 308 | logger = "system" |
---|
[802] | 309 | if logger not in validloggers : |
---|
| 310 | raise PyKotaConfigError, _("Option logger only supports values in %s") % str(validloggers) |
---|
| 311 | return logger |
---|
[695] | 312 | |
---|
[1192] | 313 | def getAccounterBackend(self, printername) : |
---|
[973] | 314 | """Returns the accounter backend to use for a given printer. |
---|
| 315 | |
---|
[1475] | 316 | if it is not set, it defaults to 'hardware' which means ask printer |
---|
[973] | 317 | for its internal lifetime page counter. |
---|
| 318 | """ |
---|
[1475] | 319 | validaccounters = [ "hardware", "software" ] |
---|
[1371] | 320 | fullaccounter = self.getPrinterOption(printername, "accounter").strip() |
---|
[1483] | 321 | flower = fullaccounter.lower() |
---|
| 322 | if flower.startswith("software") or flower.startswith("hardware") : |
---|
[980] | 323 | try : |
---|
| 324 | (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] |
---|
| 325 | except ValueError : |
---|
[1483] | 326 | raise PyKotaConfigError, _("Invalid accounter %s for printer %s") % (fullaccounter, printername) |
---|
[980] | 327 | if args.endswith(')') : |
---|
| 328 | args = args[:-1] |
---|
| 329 | if not args : |
---|
[1483] | 330 | raise PyKotaConfigError, _("Invalid accounter %s for printer %s") % (fullaccounter, printername) |
---|
[1000] | 331 | return (accounter.lower(), args) |
---|
[1483] | 332 | else : |
---|
[1192] | 333 | raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printername, str(validaccounters)) |
---|
[973] | 334 | |
---|
[1371] | 335 | def getPreHook(self, printername) : |
---|
| 336 | """Returns the prehook command line to launch, or None if unset.""" |
---|
| 337 | try : |
---|
| 338 | return self.getPrinterOption(printername, "prehook").strip() |
---|
| 339 | except PyKotaConfigError : |
---|
| 340 | return # No command to launch in the pre-hook |
---|
| 341 | |
---|
| 342 | def getPostHook(self, printername) : |
---|
| 343 | """Returns the posthook command line to launch, or None if unset.""" |
---|
| 344 | try : |
---|
| 345 | return self.getPrinterOption(printername, "posthook").strip() |
---|
| 346 | except PyKotaConfigError : |
---|
| 347 | return # No command to launch in the post-hook |
---|
| 348 | |
---|
[1495] | 349 | def getPrinterEnforcement(self, printername) : |
---|
| 350 | """Returns if quota enforcement should be strict or laxist for the current printer.""" |
---|
| 351 | validenforcements = [ "STRICT", "LAXIST" ] |
---|
| 352 | try : |
---|
| 353 | enforcement = self.getPrinterOption(printername, "enforcement") |
---|
| 354 | except PyKotaConfigError : |
---|
| 355 | return "LAXIST" |
---|
| 356 | else : |
---|
| 357 | enforcement = enforcement.upper() |
---|
| 358 | if enforcement not in validenforcements : |
---|
| 359 | raise PyKotaConfigError, _("Option enforcement in section %s only supports values in %s") % (printername, str(validenforcements)) |
---|
| 360 | return enforcement |
---|
| 361 | |
---|
[1192] | 362 | def getPrinterPolicy(self, printername) : |
---|
[695] | 363 | """Returns the default policy for the current printer.""" |
---|
[1152] | 364 | validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ] |
---|
[853] | 365 | try : |
---|
[1192] | 366 | fullpolicy = self.getPrinterOption(printername, "policy") |
---|
[853] | 367 | except PyKotaConfigError : |
---|
[1152] | 368 | return ("DENY", None) |
---|
| 369 | else : |
---|
| 370 | try : |
---|
| 371 | policy = [x.strip() for x in fullpolicy.split('(', 1)] |
---|
| 372 | except ValueError : |
---|
[1192] | 373 | raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) |
---|
[1152] | 374 | if len(policy) == 1 : |
---|
| 375 | policy.append("") |
---|
| 376 | (policy, args) = policy |
---|
| 377 | if args.endswith(')') : |
---|
| 378 | args = args[:-1] |
---|
| 379 | policy = policy.upper() |
---|
| 380 | if (policy == "EXTERNAL") and not args : |
---|
[1192] | 381 | raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) |
---|
[1152] | 382 | if policy not in validpolicies : |
---|
[1192] | 383 | raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printername, str(validpolicies)) |
---|
[1152] | 384 | return (policy, args) |
---|
[695] | 385 | |
---|
| 386 | def getSMTPServer(self) : |
---|
| 387 | """Returns the SMTP server to use to send messages to users.""" |
---|
[853] | 388 | try : |
---|
| 389 | return self.getGlobalOption("smtpserver") |
---|
| 390 | except PyKotaConfigError : |
---|
| 391 | return "localhost" |
---|
[695] | 392 | |
---|
[1353] | 393 | def getMailDomain(self) : |
---|
| 394 | """Returns the mail domain to use to send messages to users.""" |
---|
| 395 | try : |
---|
| 396 | return self.getGlobalOption("maildomain") |
---|
| 397 | except PyKotaConfigError : |
---|
| 398 | return |
---|
| 399 | |
---|
[1192] | 400 | def getAdminMail(self, printername) : |
---|
[695] | 401 | """Returns the Email address of the Print Quota Administrator.""" |
---|
[853] | 402 | try : |
---|
[1192] | 403 | return self.getPrinterOption(printername, "adminmail") |
---|
[853] | 404 | except PyKotaConfigError : |
---|
| 405 | return "root@localhost" |
---|
[695] | 406 | |
---|
[1192] | 407 | def getAdmin(self, printername) : |
---|
[695] | 408 | """Returns the full name of the Print Quota Administrator.""" |
---|
[853] | 409 | try : |
---|
[1192] | 410 | return self.getPrinterOption(printername, "admin") |
---|
[853] | 411 | except PyKotaConfigError : |
---|
| 412 | return "root" |
---|
[708] | 413 | |
---|
[1192] | 414 | def getMailTo(self, printername) : |
---|
[852] | 415 | """Returns the recipient of email messages.""" |
---|
[1192] | 416 | validmailtos = [ "EXTERNAL", "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] |
---|
[853] | 417 | try : |
---|
[1192] | 418 | fullmailto = self.getPrinterOption(printername, "mailto") |
---|
[853] | 419 | except PyKotaConfigError : |
---|
[1192] | 420 | return ("BOTH", None) |
---|
| 421 | else : |
---|
| 422 | try : |
---|
| 423 | mailto = [x.strip() for x in fullmailto.split('(', 1)] |
---|
| 424 | except ValueError : |
---|
| 425 | raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) |
---|
| 426 | if len(mailto) == 1 : |
---|
| 427 | mailto.append("") |
---|
| 428 | (mailto, args) = mailto |
---|
| 429 | if args.endswith(')') : |
---|
| 430 | args = args[:-1] |
---|
| 431 | mailto = mailto.upper() |
---|
| 432 | if (mailto == "EXTERNAL") and not args : |
---|
| 433 | raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) |
---|
| 434 | if mailto not in validmailtos : |
---|
| 435 | raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printername, str(validmailtos)) |
---|
| 436 | return (mailto, args) |
---|
[852] | 437 | |
---|
[1192] | 438 | def getGraceDelay(self, printername) : |
---|
[708] | 439 | """Returns the grace delay in days.""" |
---|
[731] | 440 | try : |
---|
[1192] | 441 | gd = self.getPrinterOption(printername, "gracedelay") |
---|
[853] | 442 | except PyKotaConfigError : |
---|
| 443 | gd = 7 |
---|
| 444 | try : |
---|
[731] | 445 | return int(gd) |
---|
[1077] | 446 | except (TypeError, ValueError) : |
---|
[773] | 447 | raise PyKotaConfigError, _("Invalid grace delay %s") % gd |
---|
[1021] | 448 | |
---|
[1077] | 449 | def getPoorMan(self) : |
---|
| 450 | """Returns the poor man's treshold.""" |
---|
| 451 | try : |
---|
| 452 | pm = self.getGlobalOption("poorman") |
---|
| 453 | except PyKotaConfigError : |
---|
| 454 | pm = 1.0 |
---|
| 455 | try : |
---|
| 456 | return float(pm) |
---|
| 457 | except (TypeError, ValueError) : |
---|
| 458 | raise PyKotaConfigError, _("Invalid poor man's treshold %s") % pm |
---|
| 459 | |
---|
| 460 | def getPoorWarn(self) : |
---|
| 461 | """Returns the poor man's warning message.""" |
---|
| 462 | try : |
---|
| 463 | return self.getGlobalOption("poorwarn") |
---|
| 464 | except PyKotaConfigError : |
---|
| 465 | return _("Your Print Quota account balance is Low.\nSoon you'll not be allowed to print anymore.\nPlease contact the Print Quota Administrator to solve the problem.") |
---|
| 466 | |
---|
[1192] | 467 | def getHardWarn(self, printername) : |
---|
[1077] | 468 | """Returns the hard limit error message.""" |
---|
| 469 | try : |
---|
[1192] | 470 | return self.getPrinterOption(printername, "hardwarn") |
---|
[1077] | 471 | except PyKotaConfigError : |
---|
[1192] | 472 | return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername |
---|
[1077] | 473 | |
---|
[1192] | 474 | def getSoftWarn(self, printername) : |
---|
[1077] | 475 | """Returns the soft limit error message.""" |
---|
| 476 | try : |
---|
[1192] | 477 | return self.getPrinterOption(printername, "softwarn") |
---|
[1077] | 478 | except PyKotaConfigError : |
---|
[1192] | 479 | return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername |
---|
[1077] | 480 | |
---|
[1021] | 481 | def getDebug(self) : |
---|
| 482 | """Returns 1 if debugging is activated, else 0.""" |
---|
[1227] | 483 | return self.isTrue(self.getGlobalOption("debug", ignore=1)) |
---|
[1130] | 484 | |
---|
| 485 | def getCaching(self) : |
---|
| 486 | """Returns 1 if database caching is enabled, else 0.""" |
---|
[1227] | 487 | return self.isTrue(self.getGlobalOption("storagecaching", ignore=1)) |
---|
[1148] | 488 | |
---|
[1356] | 489 | def getLDAPCache(self) : |
---|
| 490 | """Returns 1 if low-level LDAP caching is enabled, else 0.""" |
---|
| 491 | return self.isTrue(self.getGlobalOption("ldapcache", ignore=1)) |
---|
| 492 | |
---|
[1148] | 493 | def getDisableHistory(self) : |
---|
| 494 | """Returns 1 if we want to disable history, else 0.""" |
---|
[1227] | 495 | return self.isTrue(self.getGlobalOption("disablehistory", ignore=1)) |
---|
| 496 | |
---|
| 497 | def getUserNameToLower(self) : |
---|
| 498 | """Returns 1 if we want to convert usernames to lowercase when printing, else 0.""" |
---|
| 499 | return self.isTrue(self.getGlobalOption("utolower", ignore=1)) |
---|