[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$ |
---|
[800] | 17 | # Revision 1.8 2003/02/17 22:05:50 jalet |
---|
| 18 | # Storage backend now supports admin and user passwords (untested) |
---|
| 19 | # |
---|
[791] | 20 | # Revision 1.7 2003/02/10 12:07:31 jalet |
---|
| 21 | # Now repykota should output the recorded total page number for each printer too. |
---|
| 22 | # |
---|
[773] | 23 | # Revision 1.6 2003/02/09 13:05:43 jalet |
---|
| 24 | # Internationalization continues... |
---|
| 25 | # |
---|
[768] | 26 | # Revision 1.5 2003/02/08 22:39:46 jalet |
---|
| 27 | # --reset command line option added |
---|
| 28 | # |
---|
[759] | 29 | # Revision 1.4 2003/02/08 09:59:59 jalet |
---|
| 30 | # Added preliminary base class for all storages |
---|
| 31 | # |
---|
[698] | 32 | # Revision 1.3 2003/02/05 22:10:29 jalet |
---|
| 33 | # Typos |
---|
| 34 | # |
---|
[697] | 35 | # Revision 1.2 2003/02/05 22:02:22 jalet |
---|
| 36 | # __import__ statement didn't work as expected |
---|
| 37 | # |
---|
[695] | 38 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 39 | # Initial import into CVS |
---|
| 40 | # |
---|
| 41 | # |
---|
| 42 | # |
---|
| 43 | |
---|
| 44 | class PyKotaStorageError(Exception): |
---|
| 45 | """An exception for Quota Storage related stuff.""" |
---|
| 46 | def __init__(self, message = ""): |
---|
| 47 | self.message = message |
---|
| 48 | Exception.__init__(self, message) |
---|
| 49 | def __repr__(self): |
---|
| 50 | return self.message |
---|
| 51 | __str__ = __repr__ |
---|
| 52 | |
---|
[759] | 53 | class BaseStorage : |
---|
| 54 | """Base class for all storages.""" |
---|
| 55 | def getMatchingPrinters(self, printerpattern) : |
---|
[791] | 56 | """Returns the list of all printers tuples (name, pagecounter) which match a certain pattern for the printer name.""" |
---|
[759] | 57 | pass |
---|
| 58 | |
---|
| 59 | def addPrinter(self, printername) : |
---|
| 60 | """Adds a printer to the quota storage.""" |
---|
| 61 | pass |
---|
| 62 | |
---|
| 63 | def getPrinterUsers(self, printername) : |
---|
| 64 | """Returns the list of usernames which uses a given printer.""" |
---|
| 65 | pass |
---|
| 66 | |
---|
| 67 | def getPrinterGroups(self, printername) : |
---|
| 68 | """Returns the list of groups which uses a given printer.""" |
---|
| 69 | pass |
---|
| 70 | |
---|
| 71 | def getPrinterPageCounter(self, printername) : |
---|
| 72 | """Returns the last page counter value for a printer given its name.""" |
---|
| 73 | pass |
---|
| 74 | |
---|
| 75 | def updatePrinterPageCounter(self, printername, username, pagecount) : |
---|
| 76 | """Updates the last page counter information for a printer given its name, last username and pagecount.""" |
---|
| 77 | pass |
---|
| 78 | |
---|
| 79 | def addUserPQuota(self, username, printername) : |
---|
[768] | 80 | """Initializes a user print quota on a printer, adds the printer and the user to the quota storage if needed.""" |
---|
[759] | 81 | pass |
---|
| 82 | |
---|
| 83 | def getUPIds(self, username, printername) : |
---|
| 84 | """Returns a tuple (userid, printerid) given a username and a printername.""" |
---|
| 85 | pass |
---|
| 86 | |
---|
| 87 | def getUserPQuota(self, username, printername) : |
---|
| 88 | """Returns the Print Quota information for a given (username, printername).""" |
---|
| 89 | pass |
---|
| 90 | |
---|
| 91 | def setUserPQuota(self, username, printername, softlimit, hardlimit) : |
---|
| 92 | """Sets soft and hard limits for a user quota on a specific printer given (username, printername).""" |
---|
| 93 | pass |
---|
| 94 | |
---|
[768] | 95 | def resetUserPQuota(self, username, printername) : |
---|
| 96 | """Resets the page counter to zero. Life time page counter is kept unchanged.""" |
---|
| 97 | pass |
---|
| 98 | |
---|
[759] | 99 | def setDateLimit(self, username, printername, datelimit) : |
---|
| 100 | """Sets the limit date for a soft limit to become an hard one given (username, printername).""" |
---|
| 101 | pass |
---|
| 102 | |
---|
| 103 | def updateUserPQuota(self, username, printername, pagecount) : |
---|
| 104 | """Updates the used user Quota information given (username, printername) and a job size in pages.""" |
---|
| 105 | pass |
---|
| 106 | |
---|
| 107 | def buyUserPQuota(self, username, printername, pagebought) : |
---|
| 108 | """Buys pages for a given (username, printername).""" |
---|
| 109 | pass |
---|
| 110 | |
---|
[695] | 111 | def openConnection(config, asadmin=0) : |
---|
| 112 | """Returns a connection handle to the appropriate Quota Storage Database.""" |
---|
| 113 | (backend, host, database, admin, user) = config.getStorageBackend() |
---|
[800] | 114 | backendinfo = config.getStorageBackend() |
---|
| 115 | backend = backendinfo["storagebackend"] |
---|
[695] | 116 | try : |
---|
[698] | 117 | if not backend.isalpha() : |
---|
[697] | 118 | # don't trust user input |
---|
| 119 | raise ImportError |
---|
| 120 | exec "from pykota.storages import %s as storagebackend" % backend.lower() |
---|
[695] | 121 | except ImportError : |
---|
[773] | 122 | raise PyKotaStorageError, _("Unsupported quota storage backend %s") % backend |
---|
[695] | 123 | else : |
---|
[800] | 124 | host = backendinfo["storageserver"] |
---|
| 125 | database = backendinfo["storagename"] |
---|
| 126 | admin = backendinfo["storageadmin"] |
---|
| 127 | user = backendinfo["storageuser"] |
---|
| 128 | adminpw = backendinfo["storageadminpw"] |
---|
| 129 | userpw = backendinfo["storageuserpw"] |
---|
| 130 | if asadmin : |
---|
| 131 | return getattr(storagebackend, "Storage")(host, database, admin, adminpw) |
---|
| 132 | else : |
---|
| 133 | return getattr(storagebackend, "Storage")(host, database, user, userpw) |
---|