Changeset 900 for pykota/trunk/bin
- Timestamp:
- 04/10/03 23:47:20 (22 years ago)
- Location:
- pykota/trunk/bin
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r895 r900 23 23 # 24 24 # $Log$ 25 # Revision 1.33 2003/04/10 21:47:20 jalet 26 # Job history added. Upgrade script neutralized for now ! 27 # 25 28 # Revision 1.32 2003/04/08 21:31:39 jalet 26 29 # (anything or 0) = anything !!! Go back to school Jerome ! … … 232 235 def main(self, names, options) : 233 236 """Edit user or group quotas.""" 234 printer names = self.storage.getMatchingPrinters(options["printer"])235 if not printer names :237 printers = self.storage.getMatchingPrinters(options["printer"]) 238 if not printers : 236 239 pname = options["printer"] 237 240 if options["add"] and pname : 238 241 if self.isValidName(pname) : 239 self.storage.addPrinter(pname)240 printer names = [ (pname, 0) ]242 printerid = self.storage.addPrinter(pname) 243 printers = [ (printerid, pname) ] 241 244 else : 242 245 raise PyKotaToolError, _("Invalid printer name %s") % pname … … 263 266 else : 264 267 names = [ "*" ] # all users 265 for (printer , printerpagecounter) in printernames :268 for (printerid, printer) in printers : 266 269 if options["prototype"] : 267 270 if options["groups"] : 268 prototype = self.storage.getGroupPQuota( options["prototype"], printer)271 prototype = self.storage.getGroupPQuota(self.storage.getGroupId(options["prototype"]), printerid) 269 272 else : 270 273 # default is user quota edition 271 prototype = self.storage.getUserPQuota( options["prototype"], printer)274 prototype = self.storage.getUserPQuota(self.storage.getUserId(options["prototype"]), printerid) 272 275 if prototype is None : 273 276 self.logger.log_message(_("Prototype %s not found in Quota Storage for printer %s.") % (options["prototype"], printer)) … … 283 286 if softlimit is not None : 284 287 self.logger.log_message(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer)) 285 if (not options["reset"] and not options["noquota"] ) and ((hardlimit is None) or (softlimit is None)) :288 if (not options["reset"] and not options["noquota"] and not options["prototype"]) and ((hardlimit is None) or (softlimit is None)) : 286 289 raise PyKotaToolError, _("Both hard and soft limits must be set ! Aborting.") 287 290 if options["add"] : 288 all names = names291 allidnames = [(None, n) for n in names] 289 292 else : 290 293 if options["groups"] : 291 all names = self.storage.getPrinterGroups(printer)294 allidnames = self.storage.getPrinterGroups(printerid) 292 295 else : 293 all names = self.storage.getPrinterUsers(printer)294 for name in [n for n in allnames if self.matchString(n, names)]:296 allidnames = self.storage.getPrinterUsers(printerid) 297 for (ident, name) in [(i, n) for (i, n) in allidnames if self.matchString(n, names)]: 295 298 if options["groups"] : 296 quota = self.storage.getGroupPQuota( name, printer)299 quota = self.storage.getGroupPQuota(ident, printerid) 297 300 else : 298 quota = self.storage.getUserPQuota( name, printer)301 quota = self.storage.getUserPQuota(ident, printerid) 299 302 if quota is None : 300 303 # not found … … 306 309 if options["groups"] : 307 310 if self.isValidName(name) : 308 self.storage.addGroupPQuota(name, printer)309 quota = self.storage.getGroupPQuota( name, printer)311 (ident, printerid) = self.storage.addGroupPQuota(name, printerid) 312 quota = self.storage.getGroupPQuota(ident, printerid) 310 313 else : 311 314 self.logger.log_message(_("Invalid group name %s") % name) 312 315 else : 313 316 if self.isValidName(name) : 314 self.storage.addUserPQuota(name, printer)315 quota = self.storage.getUserPQuota( name, printer)317 (ident, printerid) = self.storage.addUserPQuota(name, printerid) 318 quota = self.storage.getUserPQuota(ident, printerid) 316 319 else : 317 320 self.logger.log_message(_("Invalid user name %s") % name) … … 320 323 else : 321 324 if options["groups"] : 322 if options["noquota"] or ((softlimit is not None) and (hardlimit is not None)) :323 self.storage.setGroupPQuota( name, printer, softlimit, hardlimit)325 if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 326 self.storage.setGroupPQuota(ident, printerid, softlimit, hardlimit) 324 327 if options["reset"] : 325 self.storage.resetGroupPQuota(name, printer) 328 self.storage.resetGroupPQuota(ident, printerid) 329 self.warnGroupPQuota(name, printer) 326 330 else : 327 if options["noquota"] or ((softlimit is not None) and (hardlimit is not None)) :328 self.storage.setUserPQuota( name, printer, softlimit, hardlimit)331 if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 332 self.storage.setUserPQuota(ident, printerid, softlimit, hardlimit) 329 333 if options["reset"] : 330 self.storage.resetUserPQuota(name, printer) 334 self.storage.resetUserPQuota(ident, printerid) 335 self.warnUserPQuota(name, printer) 331 336 332 337 if __name__ == "__main__" : -
pykota/trunk/bin/pykota
r887 r900 23 23 # 24 24 # $Log$ 25 # Revision 1.17 2003/04/10 21:47:20 jalet 26 # Job history added. Upgrade script neutralized for now ! 27 # 25 28 # Revision 1.16 2003/04/08 20:38:08 jalet 26 29 # The last job Id is saved now for each printer, this will probably … … 151 154 # can't get actual page counter, assume printer is off, but warns in log 152 155 kotafilter.logger.log_message("%s" % msg, "warn") 156 counterbeforejob = None 153 157 printerIsOff = 1 154 158 else : … … 156 160 157 161 # Get the last page counter and last username from the Quota Storage backend 158 p gc = kotafilter.storage.getPrinterPageCounter(kotafilter.printername)159 if p gcis None :162 printerid = kotafilter.storage.getPrinterId(kotafilter.printername) 163 if printerid is None : 160 164 # The printer is unknown from the Quota Storage perspective 161 165 # we let the job pass through, but log a warning message 162 166 kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 163 167 else : 164 # get last values from Quota Storage 165 (lastpagecounter, lastjobid, lastusername) = (pgc["pagecounter"], pgc["lastjobid"], pgc["lastusername"]) 166 167 # if printer is off then we assume the correct counter value is the last one 168 if printerIsOff : 169 counterbeforejob = lastpagecounter 168 userid = kotafilter.storage.getUserId(username) 169 if userid is None : 170 # The user is unknown from the Quota Storage perspective 171 # we let the job pass through, but log a warning message 172 kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn") 173 else : 174 pgc = kotafilter.storage.getPrinterPageCounter(printerid) 175 if pgc is None : 176 # The printer hasn't been used yet, from PyKota's point of view 177 lasthistoryid = None 178 lastjobid = jobid 179 lastuserid = userid 180 lastusername = username 181 lastpagecounter = counterbeforejob 182 else : 183 # get last values from Quota Storage 184 (lasthistoryid, lastjobid, lastuserid, lastusername, lastpagecounter) = (pgc["id"], pgc["jobid"], pgc["userid"], pgc["username"], pgc["pagecounter"]) 185 186 # if printer is off then we assume the correct counter value is the last one 187 if printerIsOff : 188 counterbeforejob = lastpagecounter 189 190 # Update the quota for the previous user on this printer according 191 # to the job size (difference between actual counter and latest one from storage) 192 jobsize = (counterbeforejob - lastpagecounter) 193 if jobsize >= 0 : 194 kotafilter.storage.updateUserPQuota(lastuserid, printerid, jobsize) 195 kotafilter.storage.updateJobSizeInHistory(lasthistoryid, jobsize) 196 kotafilter.warnUserPQuota(lastusername) 197 else : 198 kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastusername, kotafilter.printername), "error") 199 200 # Is the current user allowed to print at all ? 201 action = kotafilter.warnUserPQuota(username) 170 202 171 # Update the last page counter and last username in the Quota Storage backend 172 # set them to current user and 173 kotafilter.storage.updatePrinterPageCounter(kotafilter.printername, username, counterbeforejob, jobid) 174 175 # Was the printer ever used ? 176 if (lastpagecounter is None) or (lastusername is None) : 177 lastusername = username 178 lastpagecounter = counterbeforejob 203 # adds the current job to history 204 kotafilter.storage.addJobToHistory(jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action) 179 205 180 # Update the quota for the previous user on this printer according 181 # to the job size (difference between actual counter and latest one from storage) 182 jobsize = (counterbeforejob - lastpagecounter) 183 if jobsize >= 0 : 184 kotafilter.storage.updateUserPQuota(lastusername, kotafilter.printername, jobsize) 185 kotafilter.warnUserPQuota(lastusername) 186 else : 187 kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, kotafilter.printername, lastusername), "error") 188 189 # Is the current user allowed to print at all ? 190 # if no then die, else proceed. 191 action = kotafilter.warnUserPQuota(username) 192 if action == "DENY" : 193 # No, just die cleanly 194 return 1 206 # if not allowed to print then die, else proceed. 207 if action == "DENY" : 208 # No, just die cleanly 209 return 1 195 210 196 211 # pass the job untouched to the underlying layer -
pykota/trunk/bin/repykota
r895 r900 23 23 # 24 24 # $Log$ 25 # Revision 1.21 2003/04/10 21:47:20 jalet 26 # Job history added. Upgrade script neutralized for now ! 27 # 25 28 # Revision 1.20 2003/04/08 21:31:39 jalet 26 29 # (anything or 0) = anything !!! Go back to school Jerome ! … … 149 152 def main(self, options) : 150 153 """Print Quota reports generator.""" 151 printer names = self.storage.getMatchingPrinters(options["printer"])152 if not printer names :154 printers = self.storage.getMatchingPrinters(options["printer"]) 155 if not printers : 153 156 raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 154 for (printer , printerpagecounter) in printernames :157 for (printerid, printer) in printers : 155 158 print _("*** Report for %s quota on printer %s") % ((options["users"] and "user") or "group", printer) 156 159 print _("Pages grace time: %idays") % self.config.getGraceDelay(printer) … … 159 162 print _("Group used soft hard grace total") 160 163 print "------------------------------------------------------------" 161 for name in self.storage.getPrinterGroups(printer ) :162 quota = self.storage.getGroupPQuota( name, printer)164 for name in self.storage.getPrinterGroups(printerid) : 165 quota = self.storage.getGroupPQuota(ident, printerid) 163 166 total += self.printQuota(name, quota) 164 167 else : … … 166 169 print _("User used soft hard grace total") 167 170 print "------------------------------------------------------------" 168 for name in self.storage.getPrinterUsers(printer) :169 quota = self.storage.getUserPQuota( name, printer)171 for (ident, name) in self.storage.getPrinterUsers(printerid) : 172 quota = self.storage.getUserPQuota(ident, printerid) 170 173 total += self.printQuota(name, quota) 171 174 if total : 172 175 print (" " * 43) + (_("Total : %9i") % total) 176 printerpagecounter = self.storage.getPrinterPageCounter(printerid) 173 177 if printerpagecounter is None : 174 178 msg = _("unknown") 175 179 else : 176 msg = "%9i" % printerpagecounter 180 msg = "%9i" % printerpagecounter["pagecounter"] 177 181 print (" " * 44) + (_("Real : %s") % msg) 178 182 print -
pykota/trunk/bin/warnpykota
r895 r900 23 23 # 24 24 # $Log$ 25 # Revision 1.15 2003/04/10 21:47:20 jalet 26 # Job history added. Upgrade script neutralized for now ! 27 # 25 28 # Revision 1.14 2003/04/08 21:31:39 jalet 26 29 # (anything or 0) = anything !!! Go back to school Jerome ! … … 134 137 def main(self, options) : 135 138 """Warn users or groups over print quota.""" 136 printer names = self.storage.getMatchingPrinters(options["printer"])137 if not printer names :139 printers = self.storage.getMatchingPrinters(options["printer"]) 140 if not printers : 138 141 raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 139 for (printer , printerpagecounter) in printernames :142 for (printerid, printer) in printers : 140 143 if options["groups"] : 141 for name in self.storage.getPrinterGroups(printer) :144 for (ident, name) in self.storage.getPrinterGroups(printerid) : 142 145 self.warnGroupPQuota(name, printer) 143 146 else : 144 for name in self.storage.getPrinterUsers(printer) :147 for (ident, name) in self.storage.getPrinterUsers(printerid) : 145 148 self.warnUserPQuota(name, printer) 146 149