Changeset 2755

Show
Ignore:
Timestamp:
02/24/06 09:23:04 (18 years ago)
Author:
jerome
Message:

This time is the good one (tm) (c) (etc...)

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r2749 r2755  
    1 #! /usr/bin/env python 
     1#!/usr/bin/python 
    22# -*- coding: ISO-8859-15 -*- 
    33 
     
    153153class EdPyKota(PyKotaTool) :         
    154154    """A class for edpykota.""" 
     155    def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used) : 
     156        """Modifies a print quota entry.""" 
     157        if noquota or ((softlimit is not None) and (hardlimit is not None)) : 
     158            pqentry.setLimits(softlimit, hardlimit) 
     159        if increase : 
     160            newsoft = (pqentry.SoftLimit or 0) + increase          
     161            newhard = (pqentry.HardLimit or 0) + increase          
     162            if (newsoft >= 0) and (newhard >= 0) : 
     163                pqentry.setLimits(newsoft, newhard) 
     164            else :     
     165                self.printInfo(_("You can't set negative limits for %s") % pqkey, "error") 
     166        if reset : 
     167            pqentry.reset() 
     168        if hardreset :     
     169            pqentry.hardreset() 
     170        if suffix == "User" : 
     171            if used : 
     172                pqentry.setUsage(used) 
     173     
    155174    def main(self, names, options) : 
    156175        """Edit user or group quotas.""" 
     
    173192            self.display("\n") 
    174193            self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
     194        elif options["list"] : 
     195            for printer in printers : 
     196                for entry in entries : 
     197                    pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 
     198                    if pqentry.Exists : 
     199                        print "%s@%s" % (entry.Name, printer.Name) 
     200                        print "    %s" % (_("Page counter : %s") % pqentry.PageCounter) 
     201                        print "    %s" % (_("Lifetime page counter : %s") % pqentry.LifePageCounter) 
     202                        print "    %s" % (_("Soft limit : %s") % pqentry.SoftLimit) 
     203                        print "    %s" % (_("Hard limit : %s") % pqentry.HardLimit) 
     204                        print "    %s" % (_("Date limit : %s") % pqentry.DateLimit) 
     205                        print "    %s (Not supported yet)" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited"))) 
     206                        if hasattr(pqentry, "WarnCount") : 
     207                            print "    %s" % (_("Warning banners printed : %s") % pqentry.WarnCount) 
     208                        print 
    175209        else : 
     210            self.display("\n")     
    176211            skipexisting = options["skipexisting"] 
    177212            used = options["used"] 
     
    190225                    raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase 
    191226             
     227            noquota = options["noquota"] 
     228            reset = options["reset"]         
     229            hardreset = options["hardreset"] 
    192230            softlimit = hardlimit = None 
    193             noquota = options["noquota"] 
    194231            if not noquota : 
    195232                if options["softlimit"] : 
     
    220257                        self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit)) 
    221258                         
    222             pqentries = []             
    223259            if options["add"] : 
    224                 self.display("\n%s...\n" % _("Creation")) 
     260                self.display("%s...\n" % _("Creation")) 
    225261                dicnames = {} 
    226262                for m in entries : 
     
    239275                        pqkey = "%s@%s" % (ename, pname) 
    240276                        pqentry = factory(self.storage, entry, printer) 
    241                         if noquota or ((softlimit is not None) and (hardlimit is not None)) : 
    242                             pqentry.setLimits(softlimit, hardlimit) 
    243                              
    244                         if increase : 
    245                             newsoft = (pqentry.SoftLimit or 0) + increase          
    246                             newhard = (pqentry.HardLimit or 0) + increase          
    247                             if (newsoft >= 0) and (newhard >= 0) : 
    248                                 pqentry.setLimits(newsoft, newhard) 
    249                             else :     
    250                                 self.printInfo(_("You can't set negative limits."), "error") 
    251                          
    252                         if options["reset"] : 
    253                             pqentry.reset() 
    254                              
    255                         if options["hardreset"] :     
    256                             pqentry.hardreset() 
    257                              
    258                         if not options["groups"] : 
    259                             if used : 
    260                                 pqentry.setUsage(used) 
    261                          
     277                        self.modifyPQEntry(pqkey, pqentry, noquota, \ 
     278                                                    softlimit, hardlimit, \ 
     279                                                    increase, reset, \ 
     280                                                    hardreset, suffix, used) 
    262281                        oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) 
    263282                        if oldpqentry is not None :     
    264283                            if skipexisting : 
    265                                 self.printInfo(_("%s print quota entry %s@%s already exists, skipping.") % (suffix, ename, pname)) 
     284                                self.logdebug("%s print quota entry %s@%s already exists, skipping." % (suffix, ename, pname)) 
    266285                            else :     
    267                                 self.printInfo(_("%s print quota entry %s@%s already exists, will be modified.") % (suffix, ename, pname)) 
    268                                 pqentries.append(oldpqentry) 
     286                                self.logdebug("%s print quota entry %s@%s already exists, will be modified." % (suffix, ename, pname)) 
     287                                self.modifyPQEntry(pqkey, oldpqentry, noquota, \ 
     288                                                    softlimit, hardlimit, \ 
     289                                                    increase, reset, \ 
     290                                                    hardreset, suffix, used) 
     291                                oldpqentry.save()                     
    269292                        i += 1 
    270293                        percent = 100.0 * float(i) / float(nbtotal) 
    271294                        self.display("\r%.02f%%" % percent) 
    272                 self.display("\r100.00%%\r        \r%s" % _("Done.")) 
    273             else :     
    274                 for printer in printers : 
    275                     for entry in entries : 
    276                         pqentries.append(getattr(self.storage, "get%sPQuota" % suffix)(entry, printer)) 
    277                 if not pqentries :         
    278                     raise PyKotaCommandLineError, _("There's no %s print quota entry matching %s") % (suffix.lower(), " ".join(names)) 
    279                      
    280             if options["list"] : 
    281                 for pqentry in pqentries : 
    282                     if pqentry.Exists : 
    283                         print "%s@%s" % (getattr(pqentry, suffix).Name, pqentry.Printer.Name) 
    284                         print "    %s" % (_("Page counter : %s") % pqentry.PageCounter) 
    285                         print "    %s" % (_("Lifetime page counter : %s") % pqentry.LifePageCounter) 
    286                         print "    %s" % (_("Soft limit : %s") % pqentry.SoftLimit) 
    287                         print "    %s" % (_("Hard limit : %s") % pqentry.HardLimit) 
    288                         print "    %s" % (_("Date limit : %s") % pqentry.DateLimit) 
    289                         print "    %s (Not supported yet)" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited"))) 
    290                         if hasattr(pqentry, "WarnCount") : 
    291                             print "    %s" % (_("Warning banners printed : %s") % pqentry.WarnCount) 
    292                         print 
    293             else : 
    294                 self.display("\n") 
    295                 nbtotal = len(pqentries)     
     295            else :         
     296                nbtotal = len(entries) * len(printers) 
    296297                if nbtotal : 
    297298                    self.display("%s...\n" % _("Modification")) 
    298299                    i = 0 
    299                     for pqentry in pqentries : 
    300                         ename = getattr(pqentry, suffix).Name 
    301                         pname = pqentry.Printer.Name 
    302                         if pqentry.Exists :      
    303                             if noquota or ((softlimit is not None) and (hardlimit is not None)) : 
    304                                 pqentry.setLimits(softlimit, hardlimit) 
    305                                  
    306                             if increase : 
    307                                 newsoft = (pqentry.SoftLimit or 0) + increase          
    308                                 newhard = (pqentry.HardLimit or 0) + increase          
    309                                 if (newsoft >= 0) and (newhard >= 0) : 
    310                                     pqentry.setLimits(newsoft, newhard) 
    311                                 else :     
    312                                     self.printInfo(_("You can't set negative limits for %s@%s") % (ename, pname), "error") 
    313                              
    314                             if options["reset"] : 
    315                                 pqentry.reset() 
    316                                  
    317                             if options["hardreset"] :     
    318                                 pqentry.hardreset() 
    319                                  
    320                             if not options["groups"] : 
    321                                 if used : 
    322                                     pqentry.setUsage(used) 
    323                                      
    324                             pqentry.save()         
    325                         i += 1             
    326                         percent = 100.0 * float(i) / float(nbtotal) 
    327                         self.display("\r%.02f%%" % percent) 
    328                     self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
     300                    for printer in printers : 
     301                        for entry in entries : 
     302                            pqkey = "%s@%s" % (entry.Name, printer.Name) 
     303                            pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 
     304                            if pqentry.Exists :      
     305                                self.modifyPQEntry(pqkey, pqentry, noquota, \ 
     306                                                    softlimit, hardlimit, \ 
     307                                                    increase, reset, \ 
     308                                                    hardreset, suffix, used) 
     309                                pqentry.save()         
     310                            i += 1             
     311                            percent = 100.0 * float(i) / float(nbtotal) 
     312                            self.display("\r%.02f%%" % percent) 
     313            self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
    329314                      
    330315if __name__ == "__main__" :  
  • pykota/trunk/NEWS

    r2746 r2755  
    2222PyKota NEWS : 
    2323        
     24    - 1.24alpha14 : 
     25     
     26        - Finished optimizations in edpykota and fixed some minor 
     27          problems with LDAP. 
     28           
    2429    - 1.24alpha13 : 
    2530     
  • pykota/trunk/pykota/version.py

    r2746 r2755  
    2222# 
    2323 
    24 __version__ = "1.24alpha13_unofficial" 
     24__version__ = "1.24alpha14_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."