Changeset 3434 for pykota/trunk

Show
Ignore:
Timestamp:
10/05/08 22:50:54 (16 years ago)
Author:
jerome
Message:

Moved the progress report code to its own module.

Location:
pykota/trunk
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r3432 r3434  
    3030from pykota.commandline import PyKotaOptionParser 
    3131from pykota.errors import PyKotaCommandLineError 
    32 from pykota.tool import Percent, PyKotaTool 
     32from pykota.tool import PyKotaTool 
    3333from pykota.storage import StorageUserPQuota, StorageGroupPQuota 
     34from pykota.progressbar import Percent 
    3435 
    3536class EdPyKota(PyKotaTool) : 
  • pykota/trunk/bin/pkbcodes

    r3417 r3434  
    3232from pykota.commandline import PyKotaOptionParser 
    3333from pykota.errors import PyKotaCommandLineError 
    34 from pykota.tool import Percent, PyKotaTool 
     34from pykota.tool import PyKotaTool 
    3535from pykota.storage import StorageBillingCode 
     36from pykota.progressbar import Percent 
    3637 
    3738class PKBcodes(PyKotaTool) : 
  • pykota/trunk/bin/pkinvoice

    r3429 r3434  
    5454from pykota.pdfutils import getPageSize 
    5555from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
    56 from pykota.tool import Percent, PyKotaTool 
     56from pykota.tool import PyKotaTool 
     57from pykota.progressbar import Percent 
    5758 
    5859class PKInvoice(PyKotaTool) : 
  • pykota/trunk/bin/pkprinters

    r3427 r3434  
    3232from pykota.commandline import PyKotaOptionParser 
    3333from pykota.errors import PyKotaCommandLineError 
    34 from pykota.tool import Percent, PyKotaTool 
     34from pykota.tool import PyKotaTool 
    3535from pykota.storage import StoragePrinter 
     36from pykota.progressbar import Percent 
    3637 
    3738from pkipplib import pkipplib 
  • pykota/trunk/bin/pkrefund

    r3429 r3434  
    5353from pykota.pdfutils import getPageSize 
    5454from pykota.errors import PyKotaToolError, PyKotaCommandLineError 
    55 from pykota.tool import Percent, PyKotaTool 
     55from pykota.tool import PyKotaTool 
     56from pykota.progressbar import Percent 
    5657 
    5758class PKRefund(PyKotaTool) : 
  • pykota/trunk/bin/pkusers

    r3432 r3434  
    3333from pykota.commandline import PyKotaOptionParser 
    3434from pykota.errors import PyKotaCommandLineError 
    35 from pykota.tool import Percent, PyKotaTool 
     35from pykota.tool import PyKotaTool 
    3636from pykota.storage import StorageUser, StorageGroup 
     37from pykota.progressbar import Percent 
    3738 
    3839class PKUsers(PyKotaTool) : 
  • pykota/trunk/pykota/tool.py

    r3432 r3434  
    4242from pykota import config, storage, logger 
    4343from pykota.version import __version__, __author__, __years__, __gplblurb__ 
    44  
    45 class Percent : 
    46     """A class to display progress.""" 
    47     def __init__(self, app, size=None) : 
    48         """Initializes the engine.""" 
    49         self.isatty = sys.stdout.isatty() 
    50         self.app = app 
    51         self.size = None 
    52         if size : 
    53             self.setSize(size) 
    54         self.previous = None 
    55         self.before = time.time() 
    56  
    57     def setSize(self, size) : 
    58         """Sets the total size.""" 
    59         self.number = 0 
    60         self.size = size 
    61         if size : 
    62             self.factor = 100.0 / float(size) 
    63  
    64     def display(self, msg) : 
    65         """Displays the value.""" 
    66         if self.isatty : 
    67             self.app.display(msg) 
    68             sys.stdout.flush() 
    69  
    70     def oneMore(self) : 
    71         """Increments internal counter.""" 
    72         if self.size : 
    73             self.number += 1 
    74             percent = "%.02f" % (float(self.number) * self.factor) 
    75             if percent != self.previous : # optimize for large number of items 
    76                 self.display("\r%s%%" % percent) 
    77                 self.previous = percent 
    78  
    79     def done(self) : 
    80         """Displays the 'done' message.""" 
    81         after = time.time() 
    82         if self.size : 
    83             try : 
    84                 speed = self.size / ((after - self.before) + 0.00000000001) # adds an epsilon to avoid an user's problem I can't reproduce... 
    85             except ZeroDivisionError : 
    86                 speed = 1 # Fake value in case of division by zero, shouldn't happen anyway with the epsilon above... 
    87             self.display("\r100.00%%\r        \r%s. %s : %.2f %s.\n" \ 
    88                      % (_("Done"), _("Average speed"), speed, _("entries per second"))) 
    89         else : 
    90             self.display("\r100.00%%\r        \r%s.\n" % _("Done")) 
    9144 
    9245class Tool : 
     
    342295        for c in list(invalidchars) : 
    343296            if c in name : 
    344                 return 0 
    345         return 1 
     297                return False 
     298        return True 
    346299 
    347300    def _checkUserPQuota(self, userpquota) : 
     
    466419 
    467420        # indicates that a warning needs to be sent 
    468         warned = 0 
     421        warned = False 
    469422 
    470423        # first we check any group the user is a member of 
     
    480433                            return action 
    481434                        elif action == "WARN" : 
    482                             warned = 1 
     435                            warned = True 
    483436 
    484437        # Then we check the user's account balance 
     
    515468        else : 
    516469            # Then check the user quota on current printer and all its parents. 
    517             policyallowed = 0 
     470            policyallowed = False 
    518471            for upquota in [ userpquota ] + userpquota.ParentPrintersUserPQuota : 
    519472                action = self._checkUserPQuota(upquota) 
     
    521474                    return action 
    522475                elif action == "WARN" : 
    523                     warned = 1 
     476                    warned = True 
    524477                elif action == "POLICY_ALLOW" : 
    525                     policyallowed = 1 
     478                    policyallowed = True 
    526479            if warned : 
    527480                return "WARN"