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

Revision 873, 5.6 kB (checked in by jalet, 21 years ago)

GPL paragraphs were incorrectly (from memory) copied into the sources.
Two README files were added.
Upgrade script for PostgreSQL pre 1.01 schema was added.

  • 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# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19#
20# $Id$
21#
22# $Log$
23# Revision 1.10  2003/03/29 13:45:27  jalet
24# GPL paragraphs were incorrectly (from memory) copied into the sources.
25# Two README files were added.
26# Upgrade script for PostgreSQL pre 1.01 schema was added.
27#
28# Revision 1.9  2003/02/17 22:55:01  jalet
29# More options can now be set per printer or globally :
30#
31#       admin
32#       adminmail
33#       gracedelay
34#       requester
35#
36# the printer option has priority when both are defined.
37#
38# Revision 1.8  2003/02/17 22:05:50  jalet
39# Storage backend now supports admin and user passwords (untested)
40#
41# Revision 1.7  2003/02/10 12:07:31  jalet
42# Now repykota should output the recorded total page number for each printer too.
43#
44# Revision 1.6  2003/02/09 13:05:43  jalet
45# Internationalization continues...
46#
47# Revision 1.5  2003/02/08 22:39:46  jalet
48# --reset command line option added
49#
50# Revision 1.4  2003/02/08 09:59:59  jalet
51# Added preliminary base class for all storages
52#
53# Revision 1.3  2003/02/05 22:10:29  jalet
54# Typos
55#
56# Revision 1.2  2003/02/05 22:02:22  jalet
57# __import__ statement didn't work as expected
58#
59# Revision 1.1  2003/02/05 21:28:17  jalet
60# Initial import into CVS
61#
62#
63#
64
65class PyKotaStorageError(Exception):
66    """An exception for Quota Storage related stuff."""
67    def __init__(self, message = ""):
68        self.message = message
69        Exception.__init__(self, message)
70    def __repr__(self):
71        return self.message
72    __str__ = __repr__
73   
74class BaseStorage :   
75    """Base class for all storages."""
76    def getMatchingPrinters(self, printerpattern) :
77        """Returns the list of all printers tuples (name, pagecounter) which match a certain pattern for the printer name."""
78        pass
79           
80    def addPrinter(self, printername) :       
81        """Adds a printer to the quota storage."""
82        pass
83       
84    def getPrinterUsers(self, printername) :       
85        """Returns the list of usernames which uses a given printer."""
86        pass
87       
88    def getPrinterGroups(self, printername) :       
89        """Returns the list of groups which uses a given printer."""
90        pass
91       
92    def getPrinterPageCounter(self, printername) :
93        """Returns the last page counter value for a printer given its name."""
94        pass
95       
96    def updatePrinterPageCounter(self, printername, username, pagecount) :
97        """Updates the last page counter information for a printer given its name, last username and pagecount."""
98        pass
99       
100    def addUserPQuota(self, username, printername) :
101        """Initializes a user print quota on a printer, adds the printer and the user to the quota storage if needed."""
102        pass
103       
104    def getUPIds(self, username, printername) :   
105        """Returns a tuple (userid, printerid) given a username and a printername."""
106        pass
107       
108    def getUserPQuota(self, username, printername) :
109        """Returns the Print Quota information for a given (username, printername)."""
110        pass
111       
112    def setUserPQuota(self, username, printername, softlimit, hardlimit) :
113        """Sets soft and hard limits for a user quota on a specific printer given (username, printername)."""
114        pass
115       
116    def resetUserPQuota(self, username, printername) :   
117        """Resets the page counter to zero. Life time page counter is kept unchanged."""
118        pass
119       
120    def setDateLimit(self, username, printername, datelimit) :
121        """Sets the limit date for a soft limit to become an hard one given (username, printername)."""
122        pass
123       
124    def updateUserPQuota(self, username, printername, pagecount) :
125        """Updates the used user Quota information given (username, printername) and a job size in pages."""
126        pass
127       
128    def buyUserPQuota(self, username, printername, pagebought) :
129        """Buys pages for a given (username, printername)."""
130        pass
131       
132def openConnection(config, asadmin=0) :
133    """Returns a connection handle to the appropriate Quota Storage Database."""
134    backendinfo = config.getStorageBackend()
135    backend = backendinfo["storagebackend"]
136    try :
137        if not backend.isalpha() :
138            # don't trust user input
139            raise ImportError
140        exec "from pykota.storages import %s as storagebackend" % backend.lower()   
141    except ImportError :
142        raise PyKotaStorageError, _("Unsupported quota storage backend %s") % backend
143    else :   
144        host = backendinfo["storageserver"]
145        database = backendinfo["storagename"]
146        admin = backendinfo["storageadmin"]
147        user = backendinfo["storageuser"]
148        adminpw = backendinfo["storageadminpw"]
149        userpw = backendinfo["storageuserpw"]
150        if asadmin :
151            return getattr(storagebackend, "Storage")(host, database, admin, adminpw)
152        else :   
153            return getattr(storagebackend, "Storage")(host, database, user, userpw)
Note: See TracBrowser for help on using the browser.