Show
Ignore:
Timestamp:
02/06/03 23:54:33 (21 years ago)
Author:
jalet
Message:

warnpykota should be ok

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/warnpykota

    r696 r728  
    11#! /usr/bin/env python 
    22 
    3 # PyKota Print Quota Warner  
     3# PyKota Print Quota Warning sender 
    44# 
    55# PyKota - Print Quotas for CUPS 
     
    1717# 
    1818# $Log$ 
    19 # Revision 1.1  2003/02/05 21:41:09  jalet 
    20 # Skeletons added for all command line tools 
     19# Revision 1.2  2003/02/06 22:54:33  jalet 
     20# warnpykota should be ok 
    2121# 
    2222# 
    2323# 
    2424 
     25import sys 
     26 
     27from pykota import version 
     28from pykota.tool import PyKotaTool, PyKotaToolError 
     29 
     30__doc__ = """warnpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres 
     31send mail to users over print quota 
     32 
     33command line usage : 
     34 
     35  warnpykota [options] user1 user2 ... userN 
     36  warnpykota [options] group1 group2 ... groupN 
     37 
     38options : 
     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   
     53examples :                               
     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 
     70This program is free software; you can redistribute it and/or modify 
     71it under the terms of the GNU General Public License as published by 
     72the Free Software Foundation; either version 2 of the License, or 
     73(at your option) any later version. 
     74 
     75This program is distributed in the hope that it will be useful, 
     76but WITHOUT ANY WARRANTY; without even the implied warranty of 
     77MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     78GNU General Public License for more details. 
     79 
     80You should have received a copy of the GNU General Public License 
     81along with this program; if not, write to the Free Software 
     82Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     83 
     84Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 
     85         
     86class 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                      
     100if __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