[695] | 1 | # PyKota |
---|
| 2 | # |
---|
| 3 | # PyKota : Print Quotas for CUPS |
---|
| 4 | # |
---|
| 5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 6 | # You're welcome to redistribute this software under the |
---|
| 7 | # terms of the GNU General Public Licence version 2.0 |
---|
| 8 | # or, at your option, any higher version. |
---|
| 9 | # |
---|
| 10 | # You can read the complete GNU GPL in the file COPYING |
---|
| 11 | # which should come along with this software, or visit |
---|
| 12 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
| 13 | # |
---|
| 14 | # $Id$ |
---|
| 15 | # |
---|
| 16 | # $Log$ |
---|
[802] | 17 | # Revision 1.9 2003/02/17 22:55:01 jalet |
---|
| 18 | # More options can now be set per printer or globally : |
---|
| 19 | # |
---|
| 20 | # admin |
---|
| 21 | # adminmail |
---|
| 22 | # gracedelay |
---|
| 23 | # requester |
---|
| 24 | # |
---|
| 25 | # the printer option has priority when both are defined. |
---|
| 26 | # |
---|
[800] | 27 | # Revision 1.8 2003/02/17 22:05:50 jalet |
---|
| 28 | # Storage backend now supports admin and user passwords (untested) |
---|
| 29 | # |
---|
[791] | 30 | # Revision 1.7 2003/02/10 12:07:31 jalet |
---|
| 31 | # Now repykota should output the recorded total page number for each printer too. |
---|
| 32 | # |
---|
[773] | 33 | # Revision 1.6 2003/02/09 13:05:43 jalet |
---|
| 34 | # Internationalization continues... |
---|
| 35 | # |
---|
[768] | 36 | # Revision 1.5 2003/02/08 22:39:46 jalet |
---|
| 37 | # --reset command line option added |
---|
| 38 | # |
---|
[759] | 39 | # Revision 1.4 2003/02/08 09:59:59 jalet |
---|
| 40 | # Added preliminary base class for all storages |
---|
| 41 | # |
---|
[698] | 42 | # Revision 1.3 2003/02/05 22:10:29 jalet |
---|
| 43 | # Typos |
---|
| 44 | # |
---|
[697] | 45 | # Revision 1.2 2003/02/05 22:02:22 jalet |
---|
| 46 | # __import__ statement didn't work as expected |
---|
| 47 | # |
---|
[695] | 48 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 49 | # Initial import into CVS |
---|
| 50 | # |
---|
| 51 | # |
---|
| 52 | # |
---|
| 53 | |
---|
| 54 | class PyKotaStorageError(Exception): |
---|
| 55 | """An exception for Quota Storage related stuff.""" |
---|
| 56 | def __init__(self, message = ""): |
---|
| 57 | self.message = message |
---|
| 58 | Exception.__init__(self, message) |
---|
| 59 | def __repr__(self): |
---|
| 60 | return self.message |
---|
| 61 | __str__ = __repr__ |
---|
| 62 | |
---|
[759] | 63 | class BaseStorage : |
---|
| 64 | """Base class for all storages.""" |
---|
| 65 | def getMatchingPrinters(self, printerpattern) : |
---|
[791] | 66 | """Returns the list of all printers tuples (name, pagecounter) which match a certain pattern for the printer name.""" |
---|
[759] | 67 | pass |
---|
| 68 | |
---|
| 69 | def addPrinter(self, printername) : |
---|
| 70 | """Adds a printer to the quota storage.""" |
---|
| 71 | pass |
---|
| 72 | |
---|
| 73 | def getPrinterUsers(self, printername) : |
---|
| 74 | """Returns the list of usernames which uses a given printer.""" |
---|
| 75 | pass |
---|
| 76 | |
---|
| 77 | def getPrinterGroups(self, printername) : |
---|
| 78 | """Returns the list of groups which uses a given printer.""" |
---|
| 79 | pass |
---|
| 80 | |
---|
| 81 | def getPrinterPageCounter(self, printername) : |
---|
| 82 | """Returns the last page counter value for a printer given its name.""" |
---|
| 83 | pass |
---|
| 84 | |
---|
| 85 | def updatePrinterPageCounter(self, printername, username, pagecount) : |
---|
| 86 | """Updates the last page counter information for a printer given its name, last username and pagecount.""" |
---|
| 87 | pass |
---|
| 88 | |
---|
| 89 | def addUserPQuota(self, username, printername) : |
---|
[768] | 90 | """Initializes a user print quota on a printer, adds the printer and the user to the quota storage if needed.""" |
---|
[759] | 91 | pass |
---|
| 92 | |
---|
| 93 | def getUPIds(self, username, printername) : |
---|
| 94 | """Returns a tuple (userid, printerid) given a username and a printername.""" |
---|
| 95 | pass |
---|
| 96 | |
---|
| 97 | def getUserPQuota(self, username, printername) : |
---|
| 98 | """Returns the Print Quota information for a given (username, printername).""" |
---|
| 99 | pass |
---|
| 100 | |
---|
| 101 | def setUserPQuota(self, username, printername, softlimit, hardlimit) : |
---|
| 102 | """Sets soft and hard limits for a user quota on a specific printer given (username, printername).""" |
---|
| 103 | pass |
---|
| 104 | |
---|
[768] | 105 | def resetUserPQuota(self, username, printername) : |
---|
| 106 | """Resets the page counter to zero. Life time page counter is kept unchanged.""" |
---|
| 107 | pass |
---|
| 108 | |
---|
[759] | 109 | def setDateLimit(self, username, printername, datelimit) : |
---|
| 110 | """Sets the limit date for a soft limit to become an hard one given (username, printername).""" |
---|
| 111 | pass |
---|
| 112 | |
---|
| 113 | def updateUserPQuota(self, username, printername, pagecount) : |
---|
| 114 | """Updates the used user Quota information given (username, printername) and a job size in pages.""" |
---|
| 115 | pass |
---|
| 116 | |
---|
| 117 | def buyUserPQuota(self, username, printername, pagebought) : |
---|
| 118 | """Buys pages for a given (username, printername).""" |
---|
| 119 | pass |
---|
| 120 | |
---|
[695] | 121 | def openConnection(config, asadmin=0) : |
---|
| 122 | """Returns a connection handle to the appropriate Quota Storage Database.""" |
---|
[800] | 123 | backendinfo = config.getStorageBackend() |
---|
| 124 | backend = backendinfo["storagebackend"] |
---|
[695] | 125 | try : |
---|
[698] | 126 | if not backend.isalpha() : |
---|
[697] | 127 | # don't trust user input |
---|
| 128 | raise ImportError |
---|
| 129 | exec "from pykota.storages import %s as storagebackend" % backend.lower() |
---|
[695] | 130 | except ImportError : |
---|
[773] | 131 | raise PyKotaStorageError, _("Unsupported quota storage backend %s") % backend |
---|
[695] | 132 | else : |
---|
[800] | 133 | host = backendinfo["storageserver"] |
---|
| 134 | database = backendinfo["storagename"] |
---|
| 135 | admin = backendinfo["storageadmin"] |
---|
| 136 | user = backendinfo["storageuser"] |
---|
| 137 | adminpw = backendinfo["storageadminpw"] |
---|
| 138 | userpw = backendinfo["storageuserpw"] |
---|
| 139 | if asadmin : |
---|
| 140 | return getattr(storagebackend, "Storage")(host, database, admin, adminpw) |
---|
| 141 | else : |
---|
| 142 | return getattr(storagebackend, "Storage")(host, database, user, userpw) |
---|