Changeset 1041 for pykota/trunk/bin/warnpykota
- Timestamp:
- 06/25/03 16:10:01 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/warnpykota
r975 r1041 23 23 # 24 24 # $Log$ 25 # Revision 1.20 2003/06/25 14:10:01 jalet 26 # Hey, it may work (edpykota --reset excepted) ! 27 # 25 28 # Revision 1.19 2003/04/29 22:03:38 jalet 26 29 # Better error handling. … … 84 87 85 88 import sys 89 import os 90 import pwd 91 import grp 86 92 87 93 from pykota import version … … 96 102 command line usage : 97 103 98 warnpykota [options]104 warnpykota [options] [names] 99 105 100 106 options : … … 125 131 any printer. 126 132 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. 131 142 132 143 This program is free software; you can redistribute it and/or modify … … 148 159 class WarnPyKota(PyKotaTool) : 149 160 """A class for warnpykota.""" 150 def main(self, options) :161 def main(self, ugnames, options) : 151 162 """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 152 180 printers = self.storage.getMatchingPrinters(options["printer"]) 153 181 if not printers : 154 182 raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 155 for (printerid, printer)in printers :183 for printer in printers : 156 184 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) 159 187 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) 162 190 163 191 if __name__ == "__main__" : … … 188 216 elif options["users"] and options["groups"] : 189 217 raise PyKotaToolError, _("incompatible options, see help.") 190 elif args :191 raise PyKotaToolError, _("unused arguments [%s]. Aborting.") % ", ".join(args)192 218 else : 193 sys.exit(sender.main( options))219 sys.exit(sender.main(args, options)) 194 220 except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg : 195 221 sys.stderr.write("%s\n" % msg)