root / pykota / trunk / pykota / config.py @ 2066

Revision 2066, 27.9 kB (checked in by jalet, 19 years ago)

Fixed the maxdenybanners directive.
Introduced the denyduplicates directive.
Fixed some database related glitches.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[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$
[2066]24# Revision 1.61  2005/02/16 00:29:33  jalet
25# Fixed the maxdenybanners directive.
26# Introduced the denyduplicates directive.
27# Fixed some database related glitches.
28#
[2062]29# Revision 1.60  2005/02/14 23:39:50  jalet
30# Introduces the new 'trustjobsize' directive to workaround some printers
31# generating unstable internal page counter values when queried through SNMP.
32#
[2054]33# Revision 1.59  2005/02/13 22:02:29  jalet
34# Big database structure changes. Upgrade script is now included as well as
35# the new LDAP schema.
36# Introduction of the -o | --overcharge command line option to edpykota.
37# The output of repykota is more complete, but doesn't fit in 80 columns anymore.
38# Introduction of the new 'maxdenybanners' directive.
39#
[1968]40# Revision 1.58  2004/12/02 22:01:58  jalet
41# TLS is now supported with the LDAP backend
42#
[1956]43# Revision 1.57  2004/11/22 21:53:38  jalet
44# Added the reject_unknown directive to pykota.conf to reject user/group
45# creation if user or group is unknown to the system
46#
[1916]47# Revision 1.56  2004/11/15 15:23:07  jalet
48# Strips spaces just in case
49#
[1914]50# Revision 1.55  2004/11/15 15:14:06  jalet
51# Preliminary integration of Matt's patch for banners.
52#
[1875]53# Revision 1.54  2004/10/25 14:12:25  jalet
54# For URGENT legal reasons (Italy), a new "privacy" directive was added to pykota.conf
55# to hide print jobs' title, filename, and options.
56#
[1785]57# Revision 1.53  2004/10/06 10:05:47  jalet
58# Minor changes to allow any PyKota administrator to launch enhanced versions
59# of the commands, and not only the root user.
60#
[1757]61# Revision 1.52  2004/09/29 20:20:52  jalet
62# Added the winbind_separator directive to pykota.conf to allow the admin to
63# strip out the Samba/Winbind domain name when users print.
64#
[1687]65# Revision 1.51  2004/08/31 23:29:53  jalet
66# Introduction of the new 'onaccountererror' configuration directive.
67# Small fix for software accounter's return code which can't be None anymore.
68# Make software and hardware accounting code look similar : will be factorized
69# later.
70#
[1646]71# Revision 1.50  2004/07/27 07:07:27  jalet
72# Typo : treshold ==> threshold
73#
[1518]74# Revision 1.49  2004/06/03 21:53:24  jalet
75# crashrecipient directive
76#
[1495]77# Revision 1.48  2004/05/24 22:45:49  jalet
78# New 'enforcement' directive added
79# Polling loop improvements
80#
[1483]81# Revision 1.47  2004/05/18 14:49:20  jalet
82# Big code changes to completely remove the need for "requester" directives,
83# jsut use "hardware(... your previous requester directive's content ...)"
84#
[1475]85# Revision 1.46  2004/05/13 13:59:28  jalet
86# Code simplifications
87#
[1371]88# Revision 1.45  2004/03/01 10:22:30  jalet
89# Can now extract per printer pre and post hooks from the configuration file
90#
[1356]91# Revision 1.44  2004/02/20 14:42:21  jalet
92# Experimental ldapcache directive added
93#
[1353]94# Revision 1.43  2004/02/19 14:20:21  jalet
95# maildomain pykota.conf directive added.
96# Small improvements on mail headers quality.
97#
[1257]98# Revision 1.42  2004/01/08 14:10:32  jalet
99# Copyright year changed.
100#
[1227]101# Revision 1.41  2003/11/29 20:06:20  jalet
102# Added 'utolower' configuration option to convert all usernames to
103# lowercase when printing. All database accesses are still and will
104# remain case sensitive though.
105#
[1192]106# Revision 1.40  2003/11/18 23:43:12  jalet
107# Mailto can be any external command now, as usual.
108#
[1152]109# Revision 1.39  2003/10/08 21:41:38  jalet
110# External policies for printers works !
111# We can now auto-add users on first print, and do other useful things if needed.
112#
[1148]113# Revision 1.38  2003/10/07 22:06:05  jalet
114# Preliminary code to disable job history
115#
[1144]116# Revision 1.37  2003/10/07 09:07:28  jalet
117# Character encoding added to please latest version of Python
118#
[1130]119# Revision 1.36  2003/10/02 20:23:18  jalet
120# Storage caching mechanism added.
121#
[1111]122# Revision 1.35  2003/07/29 09:54:03  jalet
123# Added configurable LDAP mail attribute support
124#
[1105]125# Revision 1.34  2003/07/28 09:11:12  jalet
126# PyKota now tries to add its attributes intelligently in existing LDAP
127# directories.
128#
[1087]129# Revision 1.33  2003/07/16 21:53:07  jalet
130# Really big modifications wrt new configuration file's location and content.
131#
[1077]132# Revision 1.32  2003/07/08 19:43:51  jalet
133# Configurable warning messages.
134# Poor man's treshold value added.
135#
[1068]136# Revision 1.31  2003/07/07 11:49:24  jalet
137# Lots of small fixes with the help of PyChecker
138#
[1041]139# Revision 1.30  2003/06/25 14:10:01  jalet
140# Hey, it may work (edpykota --reset excepted) !
141#
[1029]142# Revision 1.29  2003/06/14 22:44:21  jalet
143# More work on LDAP storage backend.
144#
[1021]145# Revision 1.28  2003/06/10 16:37:54  jalet
146# Deletion of the second user which is not needed anymore.
147# Added a debug configuration field in /etc/pykota.conf
148# All queries can now be sent to the logger in debug mode, this will
149# greatly help improve performance when time for this will come.
150#
[1000]151# Revision 1.27  2003/05/27 23:00:21  jalet
152# Big rewrite of external accounting methods.
153# Should work well now.
154#
[980]155# Revision 1.26  2003/04/30 19:53:58  jalet
156# 1.05
157#
[976]158# Revision 1.25  2003/04/30 13:36:40  jalet
159# Stupid accounting method was added.
160#
[973]161# Revision 1.24  2003/04/29 18:37:54  jalet
162# Pluggable accounting methods (actually doesn't support external scripts)
163#
[956]164# Revision 1.23  2003/04/24 11:53:48  jalet
165# Default policy for unknown users/groups is to DENY printing instead
166# of the previous default to ALLOW printing. This is to solve an accuracy
167# problem. If you set the policy to ALLOW, jobs printed by in nexistant user
168# (from PyKota's POV) will be charged to the next user who prints on the
169# same printer.
170#
[952]171# Revision 1.22  2003/04/23 22:13:57  jalet
172# Preliminary support for LPRng added BUT STILL UNTESTED.
173#
[873]174# Revision 1.21  2003/03/29 13:45:27  jalet
175# GPL paragraphs were incorrectly (from memory) copied into the sources.
176# Two README files were added.
177# Upgrade script for PostgreSQL pre 1.01 schema was added.
178#
[872]179# Revision 1.20  2003/03/29 13:08:28  jalet
180# Configuration is now expected to be found in /etc/pykota.conf instead of
181# in /etc/cups/pykota.conf
182# Installation script can move old config files to the new location if needed.
183# Better error handling if configuration file is absent.
184#
[854]185# Revision 1.19  2003/03/16 09:56:52  jalet
186# Mailto option now accepts some additional values which all mean that
187# nobody will receive any email message.
188# Mailto option now works. Version 1.01 is now officially out.
189#
[853]190# Revision 1.18  2003/03/16 08:00:50  jalet
191# Default hard coded options are now used if they are not set in the
192# configuration file.
193#
[852]194# Revision 1.17  2003/03/15 23:01:28  jalet
195# New mailto option in configuration file added.
196# No time to test this tonight (although it should work).
197#
[804]198# Revision 1.16  2003/02/17 23:01:56  jalet
199# Typos
200#
[802]201# Revision 1.15  2003/02/17 22:55:01  jalet
202# More options can now be set per printer or globally :
203#
[804]204#       admin
205#       adminmail
206#       gracedelay
207#       requester
[802]208#
209# the printer option has priority when both are defined.
210#
[800]211# Revision 1.14  2003/02/17 22:05:50  jalet
212# Storage backend now supports admin and user passwords (untested)
213#
[789]214# Revision 1.13  2003/02/10 11:47:39  jalet
215# Moved some code down into the requesters
216#
[786]217# Revision 1.12  2003/02/10 10:36:33  jalet
218# Small problem wrt external requester
219#
[785]220# Revision 1.11  2003/02/10 08:50:45  jalet
221# External requester seems to be finally ok now
222#
[783]223# Revision 1.10  2003/02/10 08:19:57  jalet
224# tell ConfigParser to return raw data, this allows our own strings
225# interpolations in the requester
226#
[781]227# Revision 1.9  2003/02/10 00:44:38  jalet
228# Typos
229#
[780]230# Revision 1.8  2003/02/10 00:42:17  jalet
231# External requester should be ok (untested)
232# New syntax for configuration file wrt requesters
233#
[773]234# Revision 1.7  2003/02/09 13:05:43  jalet
235# Internationalization continues...
236#
[747]237# Revision 1.6  2003/02/07 22:00:09  jalet
238# Bad cut&paste
239#
[731]240# Revision 1.5  2003/02/06 23:58:05  jalet
241# repykota should be ok
242#
[713]243# Revision 1.4  2003/02/06 09:19:02  jalet
244# More robust behavior (hopefully) when the user or printer is not managed
245# correctly by the Quota System : e.g. cupsFilter added in ppd file, but
246# printer and/or user not 'yet?' in storage.
247#
[708]248# Revision 1.3  2003/02/05 23:26:22  jalet
249# Incorrect handling of grace delay
250#
[707]251# Revision 1.2  2003/02/05 23:09:20  jalet
252# Name conflict
253#
[695]254# Revision 1.1  2003/02/05 21:28:17  jalet
255# Initial import into CVS
256#
257#
258#
259
260import os
261import ConfigParser
262
263class PyKotaConfigError(Exception):
264    """An exception for PyKota config related stuff."""
265    def __init__(self, message = ""):
266        self.message = message
267        Exception.__init__(self, message)
268    def __repr__(self):
269        return self.message
270    __str__ = __repr__
271   
272class PyKotaConfig :
273    """A class to deal with PyKota's configuration."""
274    def __init__(self, directory) :
275        """Reads and checks the configuration file."""
[1785]276        self.isAdmin = 0
277        self.directory = directory
[695]278        self.filename = os.path.join(directory, "pykota.conf")
[872]279        if not os.path.isfile(self.filename) :
280            raise PyKotaConfigError, _("Configuration file %s not found.") % self.filename
[695]281        self.config = ConfigParser.ConfigParser()
282        self.config.read([self.filename])
[1227]283           
284    def isTrue(self, option) :       
285        """Returns 1 if option is set to true, else 0."""
286        if (option is not None) and (option.upper().strip() in ['Y', 'YES', '1', 'ON', 'T', 'TRUE']) :
287            return 1
288        else :   
289            return 0
[695]290                       
291    def getPrinterNames(self) :   
292        """Returns the list of configured printers, i.e. all sections names minus 'global'."""
293        return [pname for pname in self.config.sections() if pname != "global"]
294       
[802]295    def getGlobalOption(self, option, ignore=0) :   
296        """Returns an option from the global section, or raises a PyKotaConfigError if ignore is not set, else returns None."""
297        try :
298            return self.config.get("global", option, raw=1)
299        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :   
300            if ignore :
301                return
302            else :
303                raise PyKotaConfigError, _("Option %s not found in section global of %s") % (option, self.filename)
304               
[1192]305    def getPrinterOption(self, printername, option) :   
[802]306        """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError."""
307        globaloption = self.getGlobalOption(option, ignore=1)
308        try :
[1192]309            return self.config.get(printername, option, raw=1)
[802]310        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :   
311            if globaloption is not None :
312                return globaloption
313            else :
[1192]314                raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printername, self.filename)
[802]315       
[695]316    def getStorageBackend(self) :   
[800]317        """Returns the storage backend information as a Python mapping."""       
318        backendinfo = {}
[695]319        for option in [ "storagebackend", "storageserver", \
[1087]320                        "storagename", "storageuser", \
[695]321                      ] :
[804]322            backendinfo[option] = self.getGlobalOption(option)
[1087]323        backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=1)  # password is optional
324        backendinfo["storageadmin"] = None
325        backendinfo["storageadminpw"] = None
326        adminconf = ConfigParser.ConfigParser()
[1785]327        filename = os.path.join(self.directory, "pykotadmin.conf")
328        adminconf.read([filename])
[1087]329        if adminconf.sections() : # were we able to read the file ?
330            try :
331                backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1)
332            except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :   
[1785]333                raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", filename)
334            else :   
335                self.isAdmin = 1 # We are a PyKota administrator
[1087]336            try :
337                backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1)
338            except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :   
339                pass # Password is optional
[800]340        return backendinfo
[695]341       
[1029]342    def getLDAPInfo(self) :   
343        """Returns some hints for the LDAP backend."""       
344        ldapinfo = {}
345        for option in [ "userbase", "userrdn", \
[1041]346                        "balancebase", "balancerdn", \
[1029]347                        "groupbase", "grouprdn", "groupmembers", \
348                        "printerbase", "printerrdn", \
349                        "userquotabase", "groupquotabase", \
350                        "jobbase", "lastjobbase", \
[1105]351                        "newuser", "newgroup", \
[1111]352                        "usermail", \
[1029]353                      ] :
[1105]354            ldapinfo[option] = self.getGlobalOption(option).strip()
355        for field in ["newuser", "newgroup"] :
356            if ldapinfo[field].lower().startswith('attach(') :
357                ldapinfo[field] = ldapinfo[field][7:-1]
[1968]358               
359        # should we use TLS, by default (if unset) value is NO       
360        ldapinfo["ldaptls"] = self.isTrue(self.getGlobalOption("ldaptls", ignore=1))
361        ldapinfo["cacert"] = self.getGlobalOption("cacert", ignore=1)
362        if ldapinfo["cacert"] :
363            ldapinfo["cacert"] = ldapinfo["cacert"].strip()
364        if ldapinfo["ldaptls"] :   
365            if not os.access(ldapinfo["cacert"] or "", os.R_OK) :
366                raise PyKotaConfigError, _("Option ldaptls is set, but certificate %s is not readable.") % str(ldapinfo["cacert"])
[1029]367        return ldapinfo
368       
[695]369    def getLoggingBackend(self) :   
370        """Returns the logging backend information."""
[802]371        validloggers = [ "stderr", "system" ] 
[853]372        try :
373            logger = self.getGlobalOption("logger").lower()
374        except PyKotaConfigError :   
375            logger = "system"
[802]376        if logger not in validloggers :             
377            raise PyKotaConfigError, _("Option logger only supports values in %s") % str(validloggers)
378        return logger   
[695]379       
[1192]380    def getAccounterBackend(self, printername) :   
[973]381        """Returns the accounter backend to use for a given printer.
382       
[1475]383           if it is not set, it defaults to 'hardware' which means ask printer
[973]384           for its internal lifetime page counter.
385        """   
[1475]386        validaccounters = [ "hardware", "software" ]     
[1371]387        fullaccounter = self.getPrinterOption(printername, "accounter").strip()
[1483]388        flower = fullaccounter.lower()
389        if flower.startswith("software") or flower.startswith("hardware") :   
[980]390            try :
391                (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)]
392            except ValueError :   
[1483]393                raise PyKotaConfigError, _("Invalid accounter %s for printer %s") % (fullaccounter, printername)
[980]394            if args.endswith(')') :
395                args = args[:-1]
396            if not args :
[1483]397                raise PyKotaConfigError, _("Invalid accounter %s for printer %s") % (fullaccounter, printername)
[1000]398            return (accounter.lower(), args)   
[1483]399        else :
[1192]400            raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printername, str(validaccounters))
[973]401       
[1371]402    def getPreHook(self, printername) :   
403        """Returns the prehook command line to launch, or None if unset."""
404        try :
405            return self.getPrinterOption(printername, "prehook").strip()
406        except PyKotaConfigError :   
407            return      # No command to launch in the pre-hook
408           
409    def getPostHook(self, printername) :   
410        """Returns the posthook command line to launch, or None if unset."""
411        try :
412            return self.getPrinterOption(printername, "posthook").strip()
413        except PyKotaConfigError :   
414            return      # No command to launch in the post-hook
415           
[1495]416    def getPrinterEnforcement(self, printername) :   
417        """Returns if quota enforcement should be strict or laxist for the current printer."""
418        validenforcements = [ "STRICT", "LAXIST" ]     
419        try :
420            enforcement = self.getPrinterOption(printername, "enforcement")
421        except PyKotaConfigError :   
422            return "LAXIST"
423        else :   
424            enforcement = enforcement.upper()
425            if enforcement not in validenforcements :
426                raise PyKotaConfigError, _("Option enforcement in section %s only supports values in %s") % (printername, str(validenforcements))
427            return enforcement   
428           
[1687]429    def getPrinterOnAccounterError(self, printername) :   
430        """Returns what must be done whenever the accounter fails."""
431        validactions = [ "CONTINUE", "STOP" ]     
432        try :
433            action = self.getPrinterOption(printername, "onaccountererror")
434        except PyKotaConfigError :   
435            return "STOP"
436        else :   
437            action = action.upper()
438            if action not in validactions :
439                raise PyKotaConfigError, _("Option onaccountererror in section %s only supports values in %s") % (printername, str(validactions))
440            return action 
441           
[1192]442    def getPrinterPolicy(self, printername) :   
[695]443        """Returns the default policy for the current printer."""
[1152]444        validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ]     
[853]445        try :
[1192]446            fullpolicy = self.getPrinterOption(printername, "policy")
[853]447        except PyKotaConfigError :   
[1152]448            return ("DENY", None)
449        else :   
450            try :
451                policy = [x.strip() for x in fullpolicy.split('(', 1)]
452            except ValueError :   
[1192]453                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername)
[1152]454            if len(policy) == 1 :   
455                policy.append("")
456            (policy, args) = policy   
457            if args.endswith(')') :
458                args = args[:-1]
459            policy = policy.upper()   
460            if (policy == "EXTERNAL") and not args :
[1192]461                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername)
[1152]462            if policy not in validpolicies :
[1192]463                raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printername, str(validpolicies))
[1152]464            return (policy, args)
[695]465       
[1518]466    def getCrashRecipient(self) :   
467        """Returns the email address of the software crash messages recipient."""
468        try :
469            return self.getGlobalOption("crashrecipient")
470        except :   
471            return
472           
[695]473    def getSMTPServer(self) :   
474        """Returns the SMTP server to use to send messages to users."""
[853]475        try :
476            return self.getGlobalOption("smtpserver")
477        except PyKotaConfigError :   
478            return "localhost"
[695]479       
[1353]480    def getMailDomain(self) :   
481        """Returns the mail domain to use to send messages to users."""
482        try :
483            return self.getGlobalOption("maildomain")
484        except PyKotaConfigError :   
485            return 
486       
[1192]487    def getAdminMail(self, printername) :   
[695]488        """Returns the Email address of the Print Quota Administrator."""
[853]489        try :
[1192]490            return self.getPrinterOption(printername, "adminmail")
[853]491        except PyKotaConfigError :   
492            return "root@localhost"
[695]493       
[1192]494    def getAdmin(self, printername) :   
[695]495        """Returns the full name of the Print Quota Administrator."""
[853]496        try :
[1192]497            return self.getPrinterOption(printername, "admin")
[853]498        except PyKotaConfigError :   
499            return "root"
[708]500       
[1192]501    def getMailTo(self, printername) :   
[852]502        """Returns the recipient of email messages."""
[1192]503        validmailtos = [ "EXTERNAL", "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ]
[853]504        try :
[1192]505            fullmailto = self.getPrinterOption(printername, "mailto")
[853]506        except PyKotaConfigError :   
[1192]507            return ("BOTH", None)
508        else :   
509            try :
510                mailto = [x.strip() for x in fullmailto.split('(', 1)]
511            except ValueError :   
512                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername)
513            if len(mailto) == 1 :   
514                mailto.append("")
515            (mailto, args) = mailto   
516            if args.endswith(')') :
517                args = args[:-1]
518            mailto = mailto.upper()   
519            if (mailto == "EXTERNAL") and not args :
520                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername)
521            if mailto not in validmailtos :
522                raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printername, str(validmailtos))
523            return (mailto, args)
[852]524       
[2054]525    def getMaxDenyBanners(self, printername) :   
526        """Returns the maximum number of deny banners to be printed for a particular user on a particular printer."""
527        try :
528            maxdb = self.getPrinterOption(printername, "maxdenybanners")
529        except PyKotaConfigError :   
530            return 0 # default value is to forbid printing a deny banner.
531        try :
532            value = int(maxdb.strip())
533            if value < 0 :
534                raise ValueError
535        except (TypeError, ValueError) :   
536            raise PyKotaConfigError, _("Invalid maximal deny banners counter %s") % maxdb
537        else :   
538            return value
539           
[1192]540    def getGraceDelay(self, printername) :   
[708]541        """Returns the grace delay in days."""
[731]542        try :
[1192]543            gd = self.getPrinterOption(printername, "gracedelay")
[853]544        except PyKotaConfigError :   
[1914]545            gd = 7      # default value of 7 days
[853]546        try :
[731]547            return int(gd)
[1077]548        except (TypeError, ValueError) :   
[773]549            raise PyKotaConfigError, _("Invalid grace delay %s") % gd
[1021]550           
[1077]551    def getPoorMan(self) :   
[1646]552        """Returns the poor man's threshold."""
[1077]553        try :
554            pm = self.getGlobalOption("poorman")
555        except PyKotaConfigError :   
[1914]556            pm = 1.0    # default value of 1 unit
[1077]557        try :
558            return float(pm)
559        except (TypeError, ValueError) :   
[1646]560            raise PyKotaConfigError, _("Invalid poor man's threshold %s") % pm
[1077]561           
562    def getPoorWarn(self) :   
563        """Returns the poor man's warning message."""
564        try :
565            return self.getGlobalOption("poorwarn")
566        except PyKotaConfigError :   
567            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.")
568           
[1192]569    def getHardWarn(self, printername) :   
[1077]570        """Returns the hard limit error message."""
571        try :
[1192]572            return self.getPrinterOption(printername, "hardwarn")
[1077]573        except PyKotaConfigError :   
[1192]574            return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername
[1077]575           
[1192]576    def getSoftWarn(self, printername) :   
[1077]577        """Returns the soft limit error message."""
578        try :
[1192]579            return self.getPrinterOption(printername, "softwarn")
[1077]580        except PyKotaConfigError :   
[1192]581            return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername
[1077]582           
[1875]583    def getPrivacy(self) :       
584        """Returns 1 if privacy is activated, else 0."""
585        return self.isTrue(self.getGlobalOption("privacy", ignore=1))
586       
[1021]587    def getDebug(self) :         
588        """Returns 1 if debugging is activated, else 0."""
[1227]589        return self.isTrue(self.getGlobalOption("debug", ignore=1))
[1130]590           
591    def getCaching(self) :         
592        """Returns 1 if database caching is enabled, else 0."""
[1227]593        return self.isTrue(self.getGlobalOption("storagecaching", ignore=1))
[1148]594           
[1356]595    def getLDAPCache(self) :         
596        """Returns 1 if low-level LDAP caching is enabled, else 0."""
597        return self.isTrue(self.getGlobalOption("ldapcache", ignore=1))
598           
[1148]599    def getDisableHistory(self) :         
600        """Returns 1 if we want to disable history, else 0."""
[1227]601        return self.isTrue(self.getGlobalOption("disablehistory", ignore=1))
602           
603    def getUserNameToLower(self) :         
604        """Returns 1 if we want to convert usernames to lowercase when printing, else 0."""
605        return self.isTrue(self.getGlobalOption("utolower", ignore=1))
[1757]606       
[1956]607    def getRejectUnknown(self) :         
608        """Returns 1 if we want to reject the creation of unknown users or groups, else 0."""
609        return self.isTrue(self.getGlobalOption("reject_unknown", ignore=1))
610       
[2066]611    def getDenyDuplicates(self, printername) :         
612        """Returns 1 if we want to deny duplicate jobs, else 0."""
613        try : 
614            return self.isTrue(self.getPrinterOption(printername, "denyduplicates"))
615        except PyKotaConfigError :   
616            return 0
617       
[1757]618    def getWinbindSeparator(self) :         
619        """Returns the winbind separator's value if it is set, else None."""
620        return self.getGlobalOption("winbind_separator", ignore=1)
[1914]621
622    def getAccountBanner(self, printername) :
623        """Returns which banner(s) to account for: NONE, BOTH, STARTING, ENDING."""
624        validvalues = [ "NONE", "BOTH", "STARTING", "ENDING" ]     
625        try :
626            value = self.getPrinterOption(printername, "accountbanner")
627        except PyKotaConfigError :   
628            return "BOTH"       # Default value of BOTH
629        else :   
[1916]630            value = value.strip().upper()
[1914]631            if value not in validvalues :
[1916]632                raise PyKotaConfigError, _("Option accountbanner in section %s only supports values in %s") % (printername, str(validvalues))
[1914]633            return value 
634
635    def getStartingBanner(self, printername) :
636        """Returns the startingbanner value if set, else None."""
637        try :
[1916]638            return self.getPrinterOption(printername, "startingbanner").strip()
[1914]639        except PyKotaConfigError :
640            return None
641
642    def getEndingBanner(self, printername) :
643        """Returns the endingbanner value if set, else None."""
644        try :
[1916]645            return self.getPrinterOption(printername, "endingbanner").strip()
[1914]646        except PyKotaConfigError :
647            return None
[2062]648           
649    def getTrustJobSize(self, printername) :
650        """Returns the normalized value of the trustjobsize's directive."""
651        try :
652            value = self.getPrinterOption(printername, "trustjobsize").strip().upper()
653        except PyKotaConfigError :
654            return (None, "YES")
655        else :   
656            if value == "YES" :
657                return (None, "YES")
658            try :   
659                (limit, replacement) = [p.strip() for p in value.split(">")[1].split(":")]
660                limit = int(limit)
661                try :
662                    replacement = int(replacement) 
663                except ValueError :   
664                    if replacement != "PRECOMPUTED" :
665                        raise
666                if limit < 0 :
667                    raise ValueError
668                if (replacement != "PRECOMPUTED") and (replacement < 0) :
669                    raise ValueError
670            except (IndexError, ValueError, TypeError) :
671                raise PyKotaConfigError, _("Option trustjobsize for printer %s is incorrect") % printername
672            return (limit, replacement)   
Note: See TracBrowser for help on using the browser.