Changeset 952
- Timestamp:
- 04/24/03 00:13:57 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 44 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r937 r952 3 3 # PyKota Print Quota Editor 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.43 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.42 2003/04/17 13:38:47 jalet 26 29 # Docstring corrected for better manual page … … 252 255 user jerome is put into the groups "coders" and "it" which must 253 256 already exist in the Quota Storage. 254 WARNING : the CUPS PPD file for this printer must still be modified 255 manually, as well as pykota's configuration file for a 256 new printer to be managed successfully. 257 WARNING : the CUPS PPD file for this printer or the /etc/printcap 258 file (depending on your printing backend) must still be 259 modified manually, as well as pykota's configuration file 260 for a new printer to be managed successfully. 257 261 258 262 $ edpykota -g -S 500 -H 550 financial support … … 474 478 if groupid is not None : 475 479 self.storage.addUserToGroup(ident, groupid) 480 else : 481 self.logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname) 476 482 self.warnUserPQuota(name, printer) 477 483 -
pykota/trunk/bin/pykota
r915 r952 3 3 # PyKota accounting filter 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.24 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.23 2003/04/15 11:30:57 jalet 26 29 # More work done on money print charging. … … 115 118 class PyKotaFilter(PyKotaTool) : 116 119 """Class for the PyKota filter.""" 117 def __init__(self , username) :120 def __init__(self) : 118 121 PyKotaTool.__init__(self) 119 self.username = username122 (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile) = self.extractInfoFromCupsOrLprng() 120 123 self.requester = openRequester(self.config, self.printername) 121 self.printerhostname = self.getPrinterHostname() 122 123 def getPrinterHostname(self) : 124 """Returns the printer hostname.""" 125 device_uri = os.environ.get("DEVICE_URI", "") 126 # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp 127 try : 128 (backend, destination) = device_uri.split(":", 1) 129 except ValueError : 130 raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri 131 while destination.startswith("/") : 132 destination = destination[1:] 133 return destination.split("/")[0].split(":")[0] 134 124 135 125 def filterInput(self, inputfile) : 136 126 """Transparent filter.""" … … 148 138 infile.close() 149 139 140 def acceptJob(self) : 141 """Returns the exit code needed by the printing backend to accept the job and print it.""" 142 if self.printingsystem == "CUPS" : 143 return 0 144 elif self.printingsystem == "LPRNG" : 145 return 0 146 else : 147 # UNKNOWN 148 return -1 149 150 def removeJob(self) : 151 """Returns the exit code needed by the printing backend to refuse the job and remove it.""" 152 if self.printingsystem == "CUPS" : 153 return 1 154 elif self.printingsystem == "LPRNG" : 155 return 3 156 else : 157 # UNKNOWN 158 return -1 159 150 160 def main() : 151 161 """Do it, and do it right !""" 162 163 # Initializes the current tool 164 kotafilter = PyKotaFilter() 165 152 166 # 153 # This is a CUPS filter, so we should act and die like a CUPS filter when needed 154 narg = len(sys.argv) 155 if narg not in (6, 7) : 156 sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) 157 return 1 158 elif narg == 7 : 159 # input file 160 inputfile = sys.argv[6] 161 else : 162 # stdin 163 inputfile = None 164 165 # 166 # According to CUPS documentation, the job id is the second command line argument 167 jobid = sys.argv[1].strip() 168 169 # 170 # According to CUPS documentation, the username is the third command line argument 171 username = sys.argv[2].strip() 172 173 # Initializes the current tool 174 kotafilter = PyKotaFilter(username) 167 # If this is a CUPS filter, we should act and die like a CUPS filter when needed 168 if kotafilter.printingsystem == "CUPS" : 169 if len(sys.argv) not in (6, 7) : 170 sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) 171 return kotafilter.removeJob() 175 172 176 173 # Get the page counter directly from the printer itself 177 174 try : 178 counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) # TODO use printername instead, make them match from CUPS' config files175 counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) 179 176 except PyKotaRequesterError, msg : 180 177 # can't get actual page counter, assume printer is off, but warns in log … … 192 189 kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 193 190 else : 194 userid = kotafilter.storage.getUserId( username)191 userid = kotafilter.storage.getUserId(kotafilter.username) 195 192 if userid is None : 196 193 # The user is unknown from the Quota Storage perspective 197 # we let the job pass through, but log a warning message 198 kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn") 194 # Depending on the default policy for this printer, we 195 # either let the job pass through or reject it, but we 196 # log a message in any case. 197 policy = kotafilter.config.getPrinterPolicy(kotafilter.printername) 198 if policy in [None, "ALLOW"] : 199 action = "POLICY_ALLOW" 200 else : 201 action = "POLICY_DENY" 202 kotafilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (kotafilter.username, action, kotafilter.printername), "warn") 203 if action == "POLICY_DENY" : 204 return kotafilter.removeJob() 199 205 else : 200 206 # get last job information for this printer … … 203 209 # The printer hasn't been used yet, from PyKota's point of view 204 210 lasthistoryid = None 205 lastjobid = jobid211 lastjobid = kotafilter.jobid 206 212 lastuserid = userid 207 lastusername = username213 lastusername = kotafilter.username 208 214 lastpagecounter = counterbeforejob 209 215 else : … … 251 257 252 258 # warns the last user if he is over quota 253 kotafilter.warnUserPQuota(lastusername )259 kotafilter.warnUserPQuota(lastusername, kotafilter.printername) 254 260 255 261 # Is the current user allowed to print at all ? 256 action = kotafilter.warnUserPQuota( username)262 action = kotafilter.warnUserPQuota(kotafilter.username, kotafilter.printername) 257 263 258 264 # adds the current job to history 259 kotafilter.storage.addJobToHistory( jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action)265 kotafilter.storage.addJobToHistory(kotafilter.jobid, kotafilter.storage.getUserId(kotafilter.username), printerid, counterbeforejob, action) 260 266 261 267 # if not allowed to print then die, else proceed. 262 268 if action == "DENY" : 263 269 # No, just die cleanly 264 return 1270 return kotafilter.removeJob() 265 271 266 272 # pass the job untouched to the underlying layer 267 kotafilter.filterInput( inputfile)268 269 return 0273 kotafilter.filterInput(kotafilter.inputfile) 274 275 return kotafilter.acceptJob() 270 276 271 277 if __name__ == "__main__" : 272 sys.exit(main() or 0)278 sys.exit(main()) -
pykota/trunk/bin/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/bin/repykota
r950 r952 3 3 # PyKota Print Quota Reports generator 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.32 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.31 2003/04/23 09:58:17 jalet 26 29 # Prices per page/job are now displayed -
pykota/trunk/bin/warnpykota
r934 r952 3 3 # PyKota Print Quota Warning sender 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.18 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.17 2003/04/17 13:32:17 jalet 26 29 # bad documentation string -
pykota/trunk/cgi-bin/printquota.cgi
r941 r952 3 3 # PyKota Print Quota Reports generator 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.6 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.5 2003/04/17 21:30:09 jalet 26 29 # Now includes the logo -
pykota/trunk/cgi-bin/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/conf/pykota.conf.sample
r919 r952 4 4 # usually /etc/cups under the name pykota.conf 5 5 # 6 # PyKota - Print Quotas for CUPS 6 # PyKota - Print Quotas for CUPS and LPRng 7 7 # 8 8 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 30 30 storagebackend: postgresql 31 31 32 # Quota Storage Server hostname (and port)32 # Quota Storage Server hostname (and optional port) 33 33 # e.g. db.mydomain.com:5432 34 34 storageserver: localhost … … 100 100 # 101 101 # Another example, for AppleTalk printers which works fine : 102 # (You need the pap CUPS backend installed, and copy the 103 # pagecount.ps file from untested/netatalk into /etc) 102 # (You may need the pap CUPS backend installed, and copy the 103 # pagecount.ps file from untested/netatalk into /etc or any 104 # appropriate location) 104 105 # requester: external(/usr/bin/pap -p "%(printer)s:LaserWriter" /etc/pagecount.ps 2>/dev/null | grep -v status | grep -v Connect) 105 106 # -
pykota/trunk/conf/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/debian/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/initscripts/pykota-postgresql.sql
r915 r952 1 1 -- 2 -- PyKota - Print Quotas for CUPS 2 -- PyKota - Print Quotas for CUPS and LPRng 3 3 -- 4 4 -- (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 20 20 -- 21 21 -- $Log$ 22 -- Revision 1.14 2003/04/23 22:13:56 jalet 23 -- Preliminary support for LPRng added BUT STILL UNTESTED. 24 -- 22 25 -- Revision 1.13 2003/04/15 11:30:57 jalet 23 26 -- More work done on money print charging. -
pykota/trunk/initscripts/README
r951 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/initscripts/README.postgresql
r951 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/initscripts/upgrade-from-before-1.03.py
r951 r952 3 3 # PyKota Print Quota Warning sender 4 4 # 5 # PyKota - Print Quotas for CUPS 5 # PyKota - Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/initscripts/VERYOLDpykota-upgrade-postgresql.sql
r942 r952 1 1 -- 2 -- PyKota - Print Quotas for CUPS 2 -- PyKota - Print Quotas for CUPS and LPRng 3 3 -- 4 4 -- (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 20 20 -- 21 21 -- $Log$ 22 -- Revision 1.2 2003/04/23 22:13:56 jalet 23 -- Preliminary support for LPRng added BUT STILL UNTESTED. 24 -- 22 25 -- Revision 1.1 2003/04/17 21:33:16 jalet 23 26 -- Version 1.03 is out. -
pykota/trunk/LICENSE
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/logos/README
r932 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/man/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/NEWS
r950 r952 22 22 PyKota NEWS : 23 23 24 - 1.04pre2 : 25 26 - Preliminary support for LPRng added (still untested) 27 24 28 - 1.04pre1 : 25 29 -
pykota/trunk/po/en/pykota.po
r950 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.21 2003/04/23 22:13:56 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.20 2003/04/23 09:58:17 jalet 24 27 # Prices per page/job are now displayed … … 274 277 msgstr "" 275 278 276 msgid "User %s not registered in the PyKota system "279 msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 277 280 msgstr "" 278 281 … … 319 322 msgid "Price per page: %.3f" 320 323 msgstr "" 324 325 msgid "Group %s not found in the PyKota Storage." 326 msgstr "" -
pykota/trunk/po/fr/pykota.po
r950 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.20 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.19 2003/04/23 09:58:17 jalet 24 27 # Prices per page/job are now displayed … … 283 286 msgstr "Fichier de configuration %s non trouv� 284 287 285 msgid "User %s not registered in the PyKota system "286 msgstr "Utilisateur %s non enregistr�ans le syst� PyKota "288 msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 289 msgstr "Utilisateur %s non enregistr�ans le syst� PyKota, action par d�ut (%s) appliqu�sur l'imprimante %s" 287 290 288 291 msgid "Invalid charge amount value %s" … … 332 335 msgid "Price per page: %.3f" 333 336 msgstr "Prix par page: %.3f" 337 338 msgid "Group %s not found in the PyKota Storage." 339 msgstr "Groupe %s non trouv�ans le Quota Storage." -
pykota/trunk/po/pykota.pot
r950 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.21 2003/04/23 22:13:56 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.20 2003/04/23 09:58:17 jalet 24 27 # Prices per page/job are now displayed … … 274 277 msgstr "" 275 278 276 msgid "User %s not registered in the PyKota system "279 msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 277 280 msgstr "" 278 281 … … 319 322 msgid "Price per page: %.3f" 320 323 msgstr "" 324 325 msgid "Group %s not found in the PyKota Storage." 326 msgstr "" -
pykota/trunk/po/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/pykota/config.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.22 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.21 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/__init__.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/pykota/logger.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.6 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.5 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/loggers/__init__.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/pykota/loggers/stderr.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.3 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.2 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/loggers/system.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.6 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.5 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/requester.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.7 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.6 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/requesters/external.py
r873 r952 1 # ! /usr/bin/env python2 3 # PyKota - Print Quotas for CUPS 1 # PyKota 2 # 3 # PyKota - Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.7 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.6 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/requesters/__init__.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/pykota/requesters/snmp.py
r873 r952 1 # ! /usr/bin/env python2 3 # PyKota - Print Quotas for CUPS 1 # PyKota 2 # 3 # PyKota - Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.8 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.7 2003/03/29 13:45:27 jalet 24 27 # GPL paragraphs were incorrectly (from memory) copied into the sources. -
pykota/trunk/pykota/storage.py
r900 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.12 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.11 2003/04/10 21:47:20 jalet 24 27 # Job history added. Upgrade script neutralized for now ! -
pykota/trunk/pykota/storages/__init__.py
r873 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/pykota/storages/postgresql.py
r915 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.8 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.7 2003/04/15 11:30:57 jalet 24 27 # More work done on money print charging. -
pykota/trunk/pykota/storages/sql.py
r929 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.29 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.28 2003/04/17 09:26:21 jalet 24 27 # repykota now reports account balances too. -
pykota/trunk/pykota/tool.py
r929 r952 1 1 #! /usr/bin/env python 2 2 3 # PyKota - Print Quotas for CUPS 3 # PyKota - Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 # $Log$ 23 # Revision 1.35 2003/04/23 22:13:57 jalet 24 # Preliminary support for LPRng added BUT STILL UNTESTED. 25 # 23 26 # Revision 1.34 2003/04/17 09:26:21 jalet 24 27 # repykota now reports account balances too. … … 183 186 self.logger = logger.openLogger(self.config) 184 187 self.storage = storage.openConnection(self.config, asadmin=asadmin) 185 self.printername = os.environ.get("PRINTER", None)186 188 self.smtpserver = self.config.getSMTPServer() 189 190 def extractInfoFromCupsOrLprng(self) : 191 """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter). 192 193 Returns (None, None, None, None, None, None) if no printing system is recognized. 194 """ 195 # Try to detect CUPS 196 if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : 197 if len(sys.argv) == 7 : 198 inputfile = sys.argv[6] 199 else : 200 inputfile = None 201 202 device_uri = os.environ.get("DEVICE_URI", "") 203 # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp 204 try : 205 (backend, destination) = device_uri.split(":", 1) 206 except ValueError : 207 raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri 208 while destination.startswith("/") : 209 destination = destination[1:] 210 printerhostname = destination.split("/")[0].split(":")[0] 211 return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile) 212 else : 213 # Try to detect LPRng 214 jseen = Jseen = Pseen = nseen = rseen = None 215 for arg in sys.argv : 216 if arg.startswith("-j") : 217 jseen = arg[2:].strip() 218 elif arg.startswith("-J") : 219 Jseen = arg[2:].strip() 220 if Jseen == "(STDIN)" : 221 Jseen = None 222 elif arg.startswith("-n") : 223 nseen = arg[2:].strip() 224 elif arg.startswith("-P") : 225 Pseen = arg[2:].strip() 226 elif arg.startswith("-r") : 227 rseen = arg[2:].strip() 228 if jseen and Jseen and Pseen and nseen and rseen : 229 return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen) 230 return (None, None, None, None, None, None) # Unknown printing system 187 231 188 232 def display_version_and_quit(self) : … … 296 340 """Checks the group quota on a printer and deny or accept the job.""" 297 341 printerid = self.storage.getPrinterId(printername) 342 policy = self.config.getPrinterPolicy(printername) 298 343 groupid = self.storage.getGroupId(groupname) 299 344 limitby = self.storage.getGroupLimitBy(groupid) … … 301 346 balance = self.storage.getGroupBalance(groupid) 302 347 if balance is None : 303 policy = self.config.getPrinterPolicy(printername)304 348 if policy in [None, "ALLOW"] : 305 349 action = "POLICY_ALLOW" … … 318 362 if quota is None : 319 363 # Unknown group or printer or combination 320 policy = self.config.getPrinterPolicy(printername)321 364 if policy in [None, "ALLOW"] : 322 365 action = "POLICY_ALLOW" … … 373 416 # then we check the user's own quota 374 417 printerid = self.storage.getPrinterId(printername) 418 policy = self.config.getPrinterPolicy(printername) 375 419 limitby = self.storage.getUserLimitBy(userid) 376 420 if limitby == "balance" : 377 421 balance = self.storage.getUserBalance(userid) 378 422 if balance is None : 379 policy = self.config.getPrinterPolicy(printername)380 423 if policy in [None, "ALLOW"] : 381 424 action = "POLICY_ALLOW" … … 394 437 if quota is None : 395 438 # Unknown user or printer or combination 396 policy = self.config.getPrinterPolicy(printername)397 439 if policy in [None, "ALLOW"] : 398 440 action = "POLICY_ALLOW" … … 438 480 return action 439 481 440 def warnGroupPQuota(self, groupname, printername =None) :482 def warnGroupPQuota(self, groupname, printername) : 441 483 """Checks a group quota and send messages if quota is exceeded on current printer.""" 442 pname = printername or self.printername 443 admin = self.config.getAdmin(pname) 444 adminmail = self.config.getAdminMail(pname) 445 mailto = self.config.getMailTo(pname) 446 action = self.checkGroupPQuota(groupname, pname) 484 admin = self.config.getAdmin(printername) 485 adminmail = self.config.getAdminMail(printername) 486 mailto = self.config.getMailTo(printername) 487 action = self.checkGroupPQuota(groupname, printername) 447 488 groupmembers = self.storage.getGroupMembersNames(groupname) 448 489 if action.startswith("POLICY_") : 449 490 action = action[7:] 450 491 if action == "DENY" : 451 adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, p name)492 adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, printername) 452 493 self.logger.log_message(adminmessage) 453 494 if mailto in [ "BOTH", "ADMIN" ] : … … 455 496 for username in groupmembers : 456 497 if mailto in [ "BOTH", "USER" ] : 457 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour group Print Quota is exceeded on printer %s.") % p name)498 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour group Print Quota is exceeded on printer %s.") % printername) 458 499 elif action == "WARN" : 459 adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, p name)500 adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, printername) 460 501 self.logger.log_message(adminmessage) 461 502 if mailto in [ "BOTH", "ADMIN" ] : … … 463 504 for username in groupmembers : 464 505 if mailto in [ "BOTH", "USER" ] : 465 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour group Print Quota is almost reached on printer %s.") % p name)506 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour group Print Quota is almost reached on printer %s.") % printername) 466 507 return action 467 508 468 def warnUserPQuota(self, username, printername =None) :509 def warnUserPQuota(self, username, printername) : 469 510 """Checks a user quota and send him a message if quota is exceeded on current printer.""" 470 pname = printername or self.printername 471 admin = self.config.getAdmin(pname) 472 adminmail = self.config.getAdminMail(pname) 473 mailto = self.config.getMailTo(pname) 474 action = self.checkUserPQuota(username, pname) 511 admin = self.config.getAdmin(printername) 512 adminmail = self.config.getAdminMail(printername) 513 mailto = self.config.getMailTo(printername) 514 action = self.checkUserPQuota(username, printername) 475 515 if action.startswith("POLICY_") : 476 516 action = action[7:] 477 517 if action == "DENY" : 478 adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, p name)518 adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, printername) 479 519 self.logger.log_message(adminmessage) 480 520 if mailto in [ "BOTH", "USER" ] : 481 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % p name)521 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername) 482 522 if mailto in [ "BOTH", "ADMIN" ] : 483 523 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 484 524 elif action == "WARN" : 485 adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, p name)525 adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, printername) 486 526 self.logger.log_message(adminmessage) 487 527 if mailto in [ "BOTH", "USER" ] : 488 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % p name)528 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername) 489 529 if mailto in [ "BOTH", "ADMIN" ] : 490 530 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) -
pykota/trunk/pykota/version.py
r950 r952 1 1 # PyKota 2 2 # 3 # PyKota : Print Quotas for CUPS 3 # PyKota : Print Quotas for CUPS and LPRng 4 4 # 5 5 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 21 21 # 22 22 23 __version__ = "1.04pre 1-unofficial"23 __version__ = "1.04pre2-unofficial" 24 24 25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS ."""25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 26 26 27 27 __author__ = """Jerome Alet - alet@librelogiciel.com""" -
pykota/trunk/README
r942 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 25 25 26 26 PyKota is a complete Print Quota system for the Common Unix Printing 27 System (aka CUPS) , which works by directly querying the printers28 for the number of pages they have printed.27 System (aka CUPS) or LPR Next Generation (LPRng), which works by directly 28 querying the printers for the number of pages they have printed. 29 29 30 30 Actual working features : 31 31 32 - Supports both CUPS and LPRng backends. 33 32 34 - Per printer user and group quotas. 33 35 … … 35 37 user himself and to the print quota administrator. 36 38 37 - CUPS filter for quota accounting : pykota39 - Filter for quota accounting : pykota 38 40 39 41 - Command line print quota editor : edpykota … … 101 103 of a new job and before the end of the previous job. This depends on 102 104 the printer speed and time between jobs, but so far I've not seen 103 any problem with moderately used printers. This also depends on CUPS104 internal behavior : if CUPS doesn't begin to send a job to a printer105 before the previous one is completely printed, then there's no106 problem.105 any problem with moderately used printers. This also depends on the 106 printing system's internal behavior : if it doesn't begin to send a 107 job to a printer before the previous one is completely printed, then 108 there's no problem. 107 109 108 110 Other querying methods which won't suffer from this possible … … 140 142 You need to have the following tools installed on the CUPS Server : 141 143 142 - CUPS 144 - CUPS or LPRng 143 145 - Python v2.1 or above 144 146 - eGenix' mxDateTime Python extension … … 155 157 - PostgreSQL 156 158 157 PygreSQL and the PostgreSQL client libraries's versions on the CUPS159 PygreSQL and the PostgreSQL client libraries's versions on the Print 158 160 Server must match the PostgreSQL version used on the Quota Storage 159 161 Server. … … 163 165 alternatives. 164 166 165 Of course the CUPSServer and the Quota Storage Server can be the167 Of course the Print Server and the Quota Storage Server can be the 166 168 very same machine if you've got a tiny network, or you can have 167 multiple CUPSServers all storing their quotas on the same Quota169 multiple Print Servers all storing their quotas on the same Quota 168 170 Storage Server if you've got a bigger network. 169 171 … … 196 198 you if needed and you agreed to this action. 197 199 198 Modify the PPD files for each printer on which you want to manage 199 print quotas, for example /etc/cups/ppd/lp.ppd : 200 201 --- Add the line below exactly as-is somewhere near the top --- 202 *cupsFilter: "application/vnd.cups-postscript 0 /usr/bin/pykota" 203 --- Add the line above exactly as-is somewhere near the top --- 204 205 Modify the path to the pykota executable if needed, unfortunately 206 you have to supply the correct absolute path here due to CUPS 207 internals, or put the pykota executable into /usr/lib/cups/filter 208 instead of into /usr/bin. 209 210 Do this for each ppd file present in this directory if you want 211 to enable quota on every printer. 212 213 WARNING : In the case you've got a non-postscript printer, chances 214 are that the *cupsFilter is already filled-in and points 215 to cupsomatic or such a print filter. In this case please 216 check if you can switch your printer to PostScript mode 217 or if there's a way to make it accept PostScript jobs. 218 If yes then ensure that your workstations uses a PostScript 219 printer driver, and replace the *cupsFilter line with the 220 one pointing to the pykota filter. This should work, but 221 is currently untested. 222 If your printer really needs the original *cupsFilter line 223 then you may not be able to use PyKota easily for now. 224 200 - CUPS Print Backend : 201 202 Modify the PPD files for each printer on which you want to manage 203 print quotas, for example /etc/cups/ppd/lp.ppd : 204 205 --- Add the line below exactly as-is somewhere near the top --- 206 *cupsFilter: "application/vnd.cups-postscript 0 /usr/bin/pykota" 207 --- Add the line above exactly as-is somewhere near the top --- 208 209 Modify the path to the pykota executable if needed, unfortunately 210 you have to supply the correct absolute path here due to CUPS 211 internals, or put the pykota executable into /usr/lib/cups/filter 212 instead of into /usr/bin. 213 214 Do this for each ppd file present in this directory if you want 215 to enable quota on every printer. 216 217 WARNING : In the case you've got a non-postscript printer, chances 218 are that the *cupsFilter is already filled-in and points 219 to cupsomatic or such a print filter. In this case please 220 check if you can switch your printer to PostScript mode 221 or if there's a way to make it accept PostScript jobs. 222 If yes then ensure that your workstations uses a PostScript 223 printer driver, and replace the *cupsFilter line with the 224 one pointing to the pykota filter. This should work, but 225 is currently untested. 226 If your printer really needs the original *cupsFilter line 227 then you may not be able to use PyKota easily for now. 228 229 - LPRng Print Backend : 230 231 Modify the /etc/printcap file to add two lines identical to these ones : 232 233 :achk=true 234 :as=|/usr/bin/pykota 235 236 For each printer on which you want to use print accounting. 237 225 238 Add printers and users to the quota system and set their quota values : 226 239 … … 261 274 should make you reasonably safe. 262 275 276 also please ensure that only the printing daemon user 277 can launch the pykota command. Again this is not enforced 278 in the program. 279 263 280 ============================================================ 264 281 -
pykota/trunk/setup.py
r940 r952 3 3 # PyKota 4 4 # 5 # PyKota : Print Quotas for CUPS 5 # PyKota : Print Quotas for CUPS and LPRng 6 6 # 7 7 # (c) 2003 Jerome Alet <alet@librelogiciel.com> … … 23 23 # 24 24 # $Log$ 25 # Revision 1.12 2003/04/23 22:13:56 jalet 26 # Preliminary support for LPRng added BUT STILL UNTESTED. 27 # 25 28 # Revision 1.11 2003/04/17 13:49:29 jalet 26 29 # Typo -
pykota/trunk/TODO
r927 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com> -
pykota/trunk/untested/README
r873 r952 1 1 # $Id$ 2 2 3 PyKota - Print Quota for CUPS 3 PyKota - Print Quota for CUPS and LPRng 4 4 5 5 (c) 2003 Jerome Alet <alet@librelogiciel.com>