#! /usr/bin/env python # PyKota Print Quota Warning sender # # PyKota - Print Quotas for CUPS # # (c) 2003 Jerome Alet # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # # $Id$ # # $Log$ # Revision 1.15 2003/04/10 21:47:20 jalet # Job history added. Upgrade script neutralized for now ! # # Revision 1.14 2003/04/08 21:31:39 jalet # (anything or 0) = anything !!! Go back to school Jerome ! # # Revision 1.13 2003/04/08 21:13:44 jalet # Prepare --groups option to work. # # Revision 1.12 2003/04/08 21:10:18 jalet # Checks --groups option presence instead of --users because --users is the default. # # Revision 1.11 2003/03/29 13:45:27 jalet # 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. # # Revision 1.10 2003/03/25 11:45:32 jalet # Clearer help. # # Revision 1.9 2003/03/09 23:39:14 jalet # Simplified translations. # # Revision 1.8 2003/02/10 12:07:30 jalet # Now repykota should output the recorded total page number for each printer too. # # Revision 1.7 2003/02/09 13:40:29 jalet # typo # # Revision 1.6 2003/02/09 12:56:53 jalet # Internationalization begins... # # Revision 1.5 2003/02/07 23:24:38 jalet # Empty line deleted # # Revision 1.4 2003/02/06 23:25:40 jalet # Cleaner docstring # # Revision 1.3 2003/02/06 23:20:02 jalet # warnpykota doesn't need any user/group name argument, mimicing the # warnquota disk quota tool. # # Revision 1.2 2003/02/06 22:54:33 jalet # warnpykota should be ok # # # import sys from pykota import version from pykota.tool import PyKotaTool, PyKotaToolError __doc__ = """warnpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres Sends mail to users over print quota. command line usage : warnpykota [options] options : -v | --version Prints warnpykota's version number then exits. -h | --help Prints this message then exits. -u | --users Warns users over their print quota, this is the default. -g | --groups Warns group administrators instead of users, for each group over its print quota. -P | --printer p Verify quotas on this printer only. Actually p can use wildcards characters to select only some printers. The default value is *, meaning all printers. examples : $ warnpykota --printer lp This will warn all users of the lp printer who have exceeded their print quota. $ warnpykota This will warn all users who have exceeded their print quota on any printer. $ warnpykota --groups --printer "laserjet*" This will warn all group administrators of groups which have exceeded their print quota on any printer which name begins with "laserjet" This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Please e-mail bugs to: %s""" % (version.__version__, version.__author__) class WarnPyKota(PyKotaTool) : """A class for warnpykota.""" def main(self, options) : """Warn users or groups over print quota.""" printers = self.storage.getMatchingPrinters(options["printer"]) if not printers : raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] for (printerid, printer) in printers : if options["groups"] : for (ident, name) in self.storage.getPrinterGroups(printerid) : self.warnGroupPQuota(name, printer) else : for (ident, name) in self.storage.getPrinterUsers(printerid) : self.warnUserPQuota(name, printer) if __name__ == "__main__" : try : defaults = { \ "printer" : "*", \ } short_options = "vhugP:" long_options = ["help", "version", "users", "groups", "printer="] # Initializes the command line tool sender = WarnPyKota(doc=__doc__) # parse and checks the command line (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) # sets long options options["help"] = options["h"] or options["help"] options["version"] = options["v"] or options["version"] options["users"] = options["u"] or options["users"] options["groups"] = options["g"] or options["groups"] options["printer"] = options["P"] or options["printer"] or defaults["printer"] if options["help"] : sender.display_usage_and_quit() elif options["version"] : sender.display_version_and_quit() elif options["users"] and options["groups"] : raise PyKotaToolError, _("incompatible options, see help.") elif options["groups"] : raise PyKotaToolError, _("option --groups is currently not implemented.") elif args : raise PyKotaToolError, _("unused arguments [%s]. Aborting.") % ", ".join(args) else : sys.exit(sender.main(options)) except PyKotaToolError, msg : sys.stderr.write("%s\n" % msg) sys.stderr.flush() sys.exit(-1)