Changeset 900 for pykota/trunk/bin

Show
Ignore:
Timestamp:
04/10/03 23:47:20 (22 years ago)
Author:
jalet
Message:

Job history added. Upgrade script neutralized for now !

Location:
pykota/trunk/bin
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r895 r900  
    2323# 
    2424# $Log$ 
     25# Revision 1.33  2003/04/10 21:47:20  jalet 
     26# Job history added. Upgrade script neutralized for now ! 
     27# 
    2528# Revision 1.32  2003/04/08 21:31:39  jalet 
    2629# (anything or 0) = anything !!! Go back to school Jerome ! 
     
    232235    def main(self, names, options) : 
    233236        """Edit user or group quotas.""" 
    234         printernames = self.storage.getMatchingPrinters(options["printer"]) 
    235         if not printernames : 
     237        printers = self.storage.getMatchingPrinters(options["printer"]) 
     238        if not printers : 
    236239            pname = options["printer"] 
    237240            if options["add"] and pname : 
    238241                if self.isValidName(pname) : 
    239                     self.storage.addPrinter(pname) 
    240                     printernames = [ (pname, 0) ] 
     242                    printerid = self.storage.addPrinter(pname) 
     243                    printers = [ (printerid, pname) ] 
    241244                else :     
    242245                    raise PyKotaToolError, _("Invalid printer name %s") % pname 
     
    263266            else :     
    264267                names = [ "*" ] # all users 
    265         for (printer, printerpagecounter) in printernames : 
     268        for (printerid, printer) in printers : 
    266269            if options["prototype"] : 
    267270                if options["groups"] : 
    268                     prototype = self.storage.getGroupPQuota(options["prototype"], printer) 
     271                    prototype = self.storage.getGroupPQuota(self.storage.getGroupId(options["prototype"]), printerid) 
    269272                else :      
    270273                    # default is user quota edition 
    271                     prototype = self.storage.getUserPQuota(options["prototype"], printer) 
     274                    prototype = self.storage.getUserPQuota(self.storage.getUserId(options["prototype"]), printerid) 
    272275                if prototype is None : 
    273276                    self.logger.log_message(_("Prototype %s not found in Quota Storage for printer %s.") % (options["prototype"], printer)) 
     
    283286                if softlimit is not None : 
    284287                    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)) : 
    286289                raise PyKotaToolError, _("Both hard and soft limits must be set ! Aborting.") 
    287290            if options["add"] :     
    288                 allnames = names 
     291                allidnames = [(None, n) for n in names] 
    289292            else :    
    290293                if options["groups"] :     
    291                     allnames = self.storage.getPrinterGroups(printer) 
     294                    allidnames = self.storage.getPrinterGroups(printerid) 
    292295                else :     
    293                     allnames = 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)]: 
    295298                if options["groups"] : 
    296                     quota = self.storage.getGroupPQuota(name, printer) 
     299                    quota = self.storage.getGroupPQuota(ident, printerid) 
    297300                else : 
    298                     quota = self.storage.getUserPQuota(name, printer) 
     301                    quota = self.storage.getUserPQuota(ident, printerid) 
    299302                if quota is None : 
    300303                    # not found 
     
    306309                        if options["groups"] : 
    307310                            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) 
    310313                            else :     
    311314                                self.logger.log_message(_("Invalid group name %s") % name) 
    312315                        else : 
    313316                            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) 
    316319                            else :     
    317320                                self.logger.log_message(_("Invalid user name %s") % name) 
     
    320323                else :     
    321324                    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) 
    324327                        if options["reset"] : 
    325                             self.storage.resetGroupPQuota(name, printer) 
     328                            self.storage.resetGroupPQuota(ident, printerid) 
     329                        self.warnGroupPQuota(name, printer)     
    326330                    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) 
    329333                        if options["reset"] : 
    330                             self.storage.resetUserPQuota(name, printer) 
     334                            self.storage.resetUserPQuota(ident, printerid) 
     335                        self.warnUserPQuota(name, printer)     
    331336                      
    332337if __name__ == "__main__" :  
  • pykota/trunk/bin/pykota

    r887 r900  
    2323# 
    2424# $Log$ 
     25# Revision 1.17  2003/04/10 21:47:20  jalet 
     26# Job history added. Upgrade script neutralized for now ! 
     27# 
    2528# Revision 1.16  2003/04/08 20:38:08  jalet 
    2629# The last job Id is saved now for each printer, this will probably 
     
    151154        # can't get actual page counter, assume printer is off, but warns in log 
    152155        kotafilter.logger.log_message("%s" % msg, "warn") 
     156        counterbeforejob = None 
    153157        printerIsOff = 1 
    154158    else :     
     
    156160         
    157161    # Get the last page counter and last username from the Quota Storage backend 
    158     pgc = kotafilter.storage.getPrinterPageCounter(kotafilter.printername)     
    159     if pgc is None : 
     162    printerid = kotafilter.storage.getPrinterId(kotafilter.printername) 
     163    if printerid is None : 
    160164        # The printer is unknown from the Quota Storage perspective 
    161165        # we let the job pass through, but log a warning message 
    162166        kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 
    163167    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) 
    170202             
    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) 
    179205             
    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 
    195210         
    196211    # pass the job untouched to the underlying layer 
  • pykota/trunk/bin/repykota

    r895 r900  
    2323# 
    2424# $Log$ 
     25# Revision 1.21  2003/04/10 21:47:20  jalet 
     26# Job history added. Upgrade script neutralized for now ! 
     27# 
    2528# Revision 1.20  2003/04/08 21:31:39  jalet 
    2629# (anything or 0) = anything !!! Go back to school Jerome ! 
     
    149152    def main(self, options) : 
    150153        """Print Quota reports generator.""" 
    151         printernames = self.storage.getMatchingPrinters(options["printer"]) 
    152         if not printernames : 
     154        printers = self.storage.getMatchingPrinters(options["printer"]) 
     155        if not printers : 
    153156            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    154         for (printer, printerpagecounter) in printernames : 
     157        for (printerid, printer) in printers : 
    155158            print _("*** Report for %s quota on printer %s") % ((options["users"] and "user") or "group", printer) 
    156159            print _("Pages grace time: %idays") % self.config.getGraceDelay(printer) 
     
    159162                print _("Group            used     soft     hard   grace        total") 
    160163                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)  
    163166                    total += self.printQuota(name, quota) 
    164167            else : 
     
    166169                print _("User             used     soft     hard   grace        total") 
    167170                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) 
    170173                    total += self.printQuota(name, quota) 
    171174            if total :         
    172175                print (" " * 43) + (_("Total : %9i") % total) 
     176            printerpagecounter = self.storage.getPrinterPageCounter(printerid) 
    173177            if printerpagecounter is None :     
    174178                msg = _("unknown") 
    175179            else : 
    176                 msg = "%9i" % printerpagecounter 
     180                msg = "%9i" % printerpagecounter["pagecounter"] 
    177181            print (" " * 44) + (_("Real : %s") % msg) 
    178182            print         
  • pykota/trunk/bin/warnpykota

    r895 r900  
    2323# 
    2424# $Log$ 
     25# Revision 1.15  2003/04/10 21:47:20  jalet 
     26# Job history added. Upgrade script neutralized for now ! 
     27# 
    2528# Revision 1.14  2003/04/08 21:31:39  jalet 
    2629# (anything or 0) = anything !!! Go back to school Jerome ! 
     
    134137    def main(self, options) : 
    135138        """Warn users or groups over print quota.""" 
    136         printernames = self.storage.getMatchingPrinters(options["printer"]) 
    137         if not printernames : 
     139        printers = self.storage.getMatchingPrinters(options["printer"]) 
     140        if not printers : 
    138141            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    139         for (printer, printerpagecounter) in printernames : 
     142        for (printerid, printer) in printers : 
    140143            if options["groups"] : 
    141                 for name in self.storage.getPrinterGroups(printer) : 
     144                for (ident, name) in self.storage.getPrinterGroups(printerid) : 
    142145                    self.warnGroupPQuota(name, printer) 
    143146            else : 
    144                 for name in self.storage.getPrinterUsers(printer) : 
     147                for (ident, name) in self.storage.getPrinterUsers(printerid) : 
    145148                    self.warnUserPQuota(name, printer) 
    146149