Show
Ignore:
Timestamp:
06/25/03 16:10:01 (21 years ago)
Author:
jalet
Message:

Hey, it may work (edpykota --reset excepted) !

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/warnpykota

    r975 r1041  
    2323# 
    2424# $Log$ 
     25# Revision 1.20  2003/06/25 14:10:01  jalet 
     26# Hey, it may work (edpykota --reset excepted) ! 
     27# 
    2528# Revision 1.19  2003/04/29 22:03:38  jalet 
    2629# Better error handling. 
     
    8487 
    8588import sys 
     89import os 
     90import pwd 
     91import grp 
    8692 
    8793from pykota import version 
     
    96102command line usage : 
    97103 
    98   warnpykota [options]  
     104  warnpykota  [options]  [names] 
    99105 
    100106options : 
     
    125131  any printer. 
    126132 
    127   $ warnpykota --groups --printer "laserjet*" 
    128    
    129   This will warn all users of groups which have exceeded  
    130   their print quota on any printer which name begins with "laserjet" 
     133  $ warnpykota --groups --printer "laserjet*" "dev*" 
     134   
     135  This will warn all users of groups which names begins with "dev" and 
     136  who have exceeded their print quota on any printer which name begins  
     137  with "laserjet" 
     138   
     139  If launched by a non-root user, additionnal arguments representing 
     140  users or groups names are ignored, and only the current user/group 
     141  is warned. 
    131142 
    132143This program is free software; you can redistribute it and/or modify 
     
    148159class WarnPyKota(PyKotaTool) :         
    149160    """A class for warnpykota.""" 
    150     def main(self, options) : 
     161    def main(self, ugnames, options) : 
    151162        """Warn users or groups over print quota.""" 
     163        uid = os.geteuid() 
     164        if not uid : 
     165            # root user 
     166            if not ugnames : 
     167                # no username, means all usernames 
     168                ugnames = [ "*" ] 
     169        else :         
     170            # not the root user 
     171            # warns only the current user 
     172            # the utility of this is discutable, but at least it 
     173            # protects other users from mail bombing if they are 
     174            # over quota. 
     175            if options["groups"] : 
     176                ugnames = [ grp.getgrgid(pwd.getpwuid(uid)[3])[0] ] 
     177            else : 
     178                ugnames = [ pwd.getpwuid(uid)[0] ] 
     179         
    152180        printers = self.storage.getMatchingPrinters(options["printer"]) 
    153181        if not printers : 
    154182            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    155         for (printerid, printer) in printers : 
     183        for printer in printers : 
    156184            if options["groups"] : 
    157                 for (ident, name) in self.storage.getPrinterGroups(printerid) : 
    158                     self.warnGroupPQuota(name, printer) 
     185                for (group, grouppquota) in self.storage.getPrinterGroupsAndQuotas(printer, ugnames) : 
     186                    self.warnGroupPQuota(grouppquota) 
    159187            else : 
    160                 for (ident, name) in self.storage.getPrinterUsers(printerid) : 
    161                     self.warnUserPQuota(name, printer) 
     188                for (user, userpquota) in self.storage.getPrinterUsersAndQuotas(printer, ugnames) : 
     189                    self.warnUserPQuota(userpquota) 
    162190                      
    163191if __name__ == "__main__" :  
     
    188216        elif options["users"] and options["groups"] :     
    189217            raise PyKotaToolError, _("incompatible options, see help.") 
    190         elif args :     
    191             raise PyKotaToolError, _("unused arguments [%s]. Aborting.") % ", ".join(args) 
    192218        else : 
    193             sys.exit(sender.main(options)) 
     219            sys.exit(sender.main(args, options)) 
    194220    except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :             
    195221        sys.stderr.write("%s\n" % msg)