Changeset 728
- Timestamp:
- 02/06/03 23:54:33 (22 years ago)
- Location:
- pykota/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykota
r704 r728 17 17 # 18 18 # $Log$ 19 # Revision 1.6 2003/02/06 22:54:33 jalet 20 # warnpykota should be ok 21 # 19 22 # Revision 1.5 2003/02/05 22:45:25 jalet 20 23 # Forgotten import … … 115 118 116 119 # Is the current user allowed to print at all ? 117 action = tool.warn QuotaPrinter(username)120 action = tool.warnUserPQuota(username) 118 121 if action == "DENY" : 119 122 # No, just die cleanly … … 127 130 if jobsize >= 0: 128 131 tool.storage.updateUserPQuota(lastusername, tool.printername, jobsize) 129 tool.warn QuotaPrinter(lastusername)132 tool.warnUserPQuota(lastusername) 130 133 else : 131 134 tool.logger.log_message("Error in page count value %i for user %s on printer %s" % (jobsize, tool.printername, lastusername), "error") -
pykota/trunk/bin/warnpykota
r696 r728 1 1 #! /usr/bin/env python 2 2 3 # PyKota Print Quota Warn er3 # PyKota Print Quota Warning sender 4 4 # 5 5 # PyKota - Print Quotas for CUPS … … 17 17 # 18 18 # $Log$ 19 # Revision 1. 1 2003/02/05 21:41:09jalet20 # Skeletons added for all command line tools19 # Revision 1.2 2003/02/06 22:54:33 jalet 20 # warnpykota should be ok 21 21 # 22 22 # 23 23 # 24 24 25 import sys 26 27 from pykota import version 28 from pykota.tool import PyKotaTool, PyKotaToolError 29 30 __doc__ = """warnpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres 31 send mail to users over print quota 32 33 command line usage : 34 35 warnpykota [options] user1 user2 ... userN 36 warnpykota [options] group1 group2 ... groupN 37 38 options : 39 40 -v | --version Prints warnpykota's version number then exits. 41 -h | --help Prints this message then exits. 42 43 -u | --users Send mail to users over print quota, this is 44 the default. 45 46 -g | --groups Send mail to group administrators instead of users. 47 48 -P | --printer p Verify quotas on this printer only. Actually p can 49 use wildcards characters to select only 50 some printers. The default value is *, meaning 51 all printers. 52 53 examples : 54 55 $ warnpykota --printer lp 56 57 This will warn all users of the lp printer who have exceeded their 58 print quota. 59 60 $ warnpykota 61 62 This will warn all users who have exceeded their print quota on 63 any printer. 64 65 $ warnpykota --groups --printer "laserjet*" 66 67 This will warn all group administrators of groups which have exceeded 68 their print quota on any printer which name begins with "laserjet" 69 70 This program is free software; you can redistribute it and/or modify 71 it under the terms of the GNU General Public License as published by 72 the Free Software Foundation; either version 2 of the License, or 73 (at your option) any later version. 74 75 This program is distributed in the hope that it will be useful, 76 but WITHOUT ANY WARRANTY; without even the implied warranty of 77 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 78 GNU General Public License for more details. 79 80 You should have received a copy of the GNU General Public License 81 along with this program; if not, write to the Free Software 82 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 83 84 Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 85 86 class WarnPyKota(PyKotaTool) : 87 """A class for warnpykota.""" 88 def main(self, names, options) : 89 """Warn users or groups over print quota.""" 90 printernames = self.storage.getMatchingPrinters(options["printer"]) 91 if not printernames : 92 raise PyKotaToolError, "There's no printer matching %s" % options["printer"] 93 for printer in printernames : 94 for name in names : 95 if options["users"] : 96 self.warnUserPQuota(name, printer) 97 else : 98 self.warnGroupPQuota(name, printer) 99 100 if __name__ == "__main__" : 101 try : 102 defaults = { \ 103 "users" : 1, \ 104 "groups" : 0, \ 105 "printer" : "*", \ 106 } 107 short_options = "vhugP:" 108 long_options = ["help", "version", "users", "groups", "printer="] 109 110 # Initializes the command line tool 111 sender = WarnPyKota(doc=__doc__) 112 113 # parse and checks the command line 114 (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options) 115 116 # sets long options 117 options["help"] = options["h"] or options["help"] 118 options["version"] = options["v"] or options["version"] 119 options["users"] = options["u"] or options["users"] or defaults["users"] 120 options["groups"] = options["g"] or options["groups"] or defaults["groups"] 121 options["printer"] = options["P"] or options["printer"] or defaults["printer"] 122 123 if options["help"] : 124 sender.display_usage_and_quit() 125 elif options["version"] : 126 sender.display_version_and_quit() 127 elif options["users"] and options["groups"] : 128 raise PyKotaToolError, "warnpykota: options --users and --groups are incompatible." 129 elif options["groups"] : 130 raise PyKotaToolError, "warnpykota: options --groups is currently not implemented." 131 else : 132 sys.exit(sender.main(args, options)) 133 except PyKotaToolError, msg : 134 sys.stderr.write("%s\n" % msg) 135 sys.stderr.flush() 136 sys.exit(-1) 137 -
pykota/trunk/pykota/tool.py
r722 r728 15 15 # 16 16 # $Log$ 17 # Revision 1.11 2003/02/06 22:54:33 jalet 18 # warnpykota should be ok 19 # 17 20 # Revision 1.10 2003/02/06 15:03:11 jalet 18 21 # added a method to set the limit date … … 209 212 return (action, (hardlimit - pagecounter), datelimit) 210 213 211 def warn QuotaPrinter(self, username) :214 def warnGroupPQuota(self, username, printername=None) : 212 215 """Checks a user quota and send him a message if quota is exceeded on current printer.""" 213 (action, grace, gracedate) = self.checkUserPQuota(username, self.printername) 216 pname = printername or self.printername 217 raise PyKotaToolError, "Group quotas are currently not implemented." 218 219 def warnUserPQuota(self, username, printername=None) : 220 """Checks a user quota and send him a message if quota is exceeded on current printer.""" 221 pname = printername or self.printername 222 (action, grace, gracedate) = self.checkUserPQuota(username, pname) 214 223 if action == "DENY" : 215 224 if (grace is not None) and (gracedate is not None) : 216 225 # only when both user and printer are known 217 adminmessage = "Print Quota exceeded for user %s on printer %s" % (username, self.printername)226 adminmessage = "Print Quota exceeded for user %s on printer %s" % (username, pname) 218 227 self.logger.log_message(adminmessage) 219 self.sendMessageToUser(username, "Print Quota Exceeded", "You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s." % self.printername)228 self.sendMessageToUser(username, "Print Quota Exceeded", "You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s." % pname) 220 229 self.sendMessageToAdmin("Print Quota", adminmessage) 221 230 elif action == "WARN" : 222 adminmessage = "Print Quota soft limit exceeded for user %s on printer %s" % (username, self.printername)231 adminmessage = "Print Quota soft limit exceeded for user %s on printer %s" % (username, pname) 223 232 self.logger.log_message(adminmessage) 224 self.sendMessageToUser(username, "Print Quota Exceeded", "You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s." % self.printername)233 self.sendMessageToUser(username, "Print Quota Exceeded", "You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s." % pname) 225 234 self.sendMessageToAdmin("Print Quota", adminmessage) 226 235 return action