root / pykota / trunk / pykota / storage.py @ 802

Revision 802, 5.0 kB (checked in by jalet, 21 years ago)

More options can now be set per printer or globally :

admin
adminmail
gracedelay
requester

the printer option has priority when both are defined.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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$
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#
27# Revision 1.8  2003/02/17 22:05:50  jalet
28# Storage backend now supports admin and user passwords (untested)
29#
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#
33# Revision 1.6  2003/02/09 13:05:43  jalet
34# Internationalization continues...
35#
36# Revision 1.5  2003/02/08 22:39:46  jalet
37# --reset command line option added
38#
39# Revision 1.4  2003/02/08 09:59:59  jalet
40# Added preliminary base class for all storages
41#
42# Revision 1.3  2003/02/05 22:10:29  jalet
43# Typos
44#
45# Revision 1.2  2003/02/05 22:02:22  jalet
46# __import__ statement didn't work as expected
47#
48# Revision 1.1  2003/02/05 21:28:17  jalet
49# Initial import into CVS
50#
51#
52#
53
54class 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   
63class BaseStorage :   
64    """Base class for all storages."""
65    def getMatchingPrinters(self, printerpattern) :
66        """Returns the list of all printers tuples (name, pagecounter) which match a certain pattern for the printer name."""
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) :
90        """Initializes a user print quota on a printer, adds the printer and the user to the quota storage if needed."""
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       
105    def resetUserPQuota(self, username, printername) :   
106        """Resets the page counter to zero. Life time page counter is kept unchanged."""
107        pass
108       
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       
121def openConnection(config, asadmin=0) :
122    """Returns a connection handle to the appropriate Quota Storage Database."""
123    backendinfo = config.getStorageBackend()
124    backend = backendinfo["storagebackend"]
125    try :
126        if not backend.isalpha() :
127            # don't trust user input
128            raise ImportError
129        exec "from pykota.storages import %s as storagebackend" % backend.lower()   
130    except ImportError :
131        raise PyKotaStorageError, _("Unsupported quota storage backend %s") % backend
132    else :   
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)
Note: See TracBrowser for help on using the browser.