Changeset 952 for pykota/trunk/bin
- Timestamp:
- 04/24/03 00:13:57 (22 years ago)
- Location:
- pykota/trunk/bin
- Files:
-
- 5 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