Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r3411 r3413  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3838        self.isDirty = False 
    3939        self.Exists = False 
    40          
     40 
    4141    def setDescription(self, description=None) : 
    4242        """Sets the object's description.""" 
    4343        if description is not None : 
    4444            self.Description = str(description) 
    45             self.isDirty = True     
    46              
    47     def save(self) :         
     45            self.isDirty = True 
     46 
     47    def save(self) : 
    4848        """Saves the object to the database.""" 
    4949        if self.isDirty : 
    5050            getattr(self.parent, "save%s" % self.__class__.__name__[7:])(self) 
    5151            self.isDirty = False 
    52              
    53          
    54 class StorageUser(StorageObject) :         
     52 
     53 
     54class StorageUser(StorageObject) : 
    5555    """User class.""" 
    5656    def __init__(self, parent, name) : 
     
    6464        self.Payments = [] # TODO : maybe handle this smartly for SQL, for now just don't retrieve them 
    6565        self.PaymentsBacklog = [] 
    66          
    67     def consumeAccountBalance(self, amount) :      
     66 
     67    def consumeAccountBalance(self, amount) : 
    6868        """Consumes an amount of money from the user's account balance.""" 
    6969        self.parent.decreaseUserAccountBalance(self, amount) 
    7070        self.AccountBalance = float(self.AccountBalance or 0.0) - amount 
    71          
     71 
    7272    def setAccountBalance(self, balance, lifetimepaid, comment="") : 
    7373        """Sets the user's account balance in case he pays more money.""" 
     
    7878            self.PaymentsBacklog.append((diff, comment)) 
    7979        self.isDirty = True 
    80          
    81     def save(self) :     
     80 
     81    def save(self) : 
    8282        """Saves an user and flush its payments backlog.""" 
    8383        for (value, comment) in self.PaymentsBacklog : 
    8484            self.parent.writeNewPayment(self, value, comment) 
    85         self.PaymentsBacklog = []     
    86         StorageObject.save(self)     
    87          
    88     def setLimitBy(self, limitby) :     
     85        self.PaymentsBacklog = [] 
     86        StorageObject.save(self) 
     87 
     88    def setLimitBy(self, limitby) : 
    8989        """Sets the user's limiting factor.""" 
    9090        try : 
    9191            limitby = limitby.lower() 
    92         except AttributeError :     
     92        except AttributeError : 
    9393            limitby = "quota" 
    9494        if limitby in ["quota", "balance", \ 
     
    9696            self.LimitBy = limitby 
    9797            self.isDirty = True 
    98          
    99     def setOverChargeFactor(self, factor) :     
     98 
     99    def setOverChargeFactor(self, factor) : 
    100100        """Sets the user's overcharging coefficient.""" 
    101101        self.OverCharge = factor 
    102102        self.isDirty = True 
    103          
    104     def setEmail(self, email) :     
     103 
     104    def setEmail(self, email) : 
    105105        """Sets the user's email address.""" 
    106106        self.Email = email 
    107107        self.isDirty = True 
    108          
    109     def delete(self) :     
     108 
     109    def delete(self) : 
    110110        """Deletes an user from the database.""" 
    111111        self.parent.deleteUser(self) 
     
    116116                    self.parent.flushEntry("USERPQUOTAS", "%s@%s" % (v.User.Name, v.Printer.Name)) 
    117117        self.Exists = False 
    118         self.isDirty = False             
    119          
     118        self.isDirty = False 
     119 
    120120    def refund(self, amount, reason) : 
    121121        """Refunds a number of credits to an user.""" 
    122122        self.consumeAccountBalance(-amount) 
    123123        self.parent.writeNewPayment(self, -amount, reason) 
    124          
    125          
    126 class StorageGroup(StorageObject) :         
     124 
     125 
     126class StorageGroup(StorageObject) : 
    127127    """User class.""" 
    128128    def __init__(self, parent, name) : 
     
    132132        self.AccountBalance = None 
    133133        self.LifeTimePaid = None 
    134          
    135     def setLimitBy(self, limitby) :     
     134 
     135    def setLimitBy(self, limitby) : 
    136136        """Sets the user's limiting factor.""" 
    137137        try : 
    138138            limitby = limitby.lower() 
    139         except AttributeError :     
     139        except AttributeError : 
    140140            limitby = "quota" 
    141141        if limitby in ["quota", "balance", "noquota"] : 
    142142            self.LimitBy = limitby 
    143143            self.isDirty = True 
    144          
     144 
    145145    def addUserToGroup(self, user) : 
    146146        """Adds an user to an users group.""" 
    147147        self.parent.addUserToGroup(user, self) 
    148          
     148 
    149149    def delUserFromGroup(self, user) : 
    150150        """Removes an user from an users group.""" 
    151151        self.parent.delUserFromGroup(user, self) 
    152          
    153     def delete(self) :     
     152 
     153    def delete(self) : 
    154154        """Deletes a group from the database.""" 
    155155        self.parent.deleteGroup(self) 
     
    160160                    self.parent.flushEntry("GROUPPQUOTAS", "%s@%s" % (v.Group.Name, v.Printer.Name)) 
    161161        self.Exists = False 
    162         self.isDirty = False             
    163          
    164          
     162        self.isDirty = False 
     163 
     164 
    165165class StoragePrinter(StorageObject) : 
    166166    """Printer class.""" 
     
    172172        self.MaxJobSize = None 
    173173        self.PassThrough = None 
    174          
    175     def __getattr__(self, name) :     
     174 
     175    def __getattr__(self, name) : 
    176176        """Delays data retrieval until it's really needed.""" 
    177         if name == "LastJob" :  
     177        if name == "LastJob" : 
    178178            self.LastJob = self.parent.getPrinterLastJob(self) 
    179179            self.parent.tool.logdebug("Lazy retrieval of last job for printer %s" % self.Name) 
    180180            return self.LastJob 
    181         elif name == "Coefficients" :     
     181        elif name == "Coefficients" : 
    182182            self.Coefficients = self.parent.tool.config.getPrinterCoefficients(self.Name) 
    183183            self.parent.tool.logdebug("Lazy retrieval of coefficients for printer %s : %s" % (self.Name, self.Coefficients)) 
     
    185185        else : 
    186186            raise AttributeError, name 
    187              
     187 
    188188    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 
    189189        """Adds a job to the printer's history.""" 
    190190        self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost, jobsizebytes, jobmd5sum, jobpages, jobbilling, precomputedsize, precomputedprice) 
    191191        # TODO : update LastJob object ? Probably not needed. 
    192          
    193     def addPrinterToGroup(self, printer) :     
     192 
     193    def addPrinterToGroup(self, printer) : 
    194194        """Adds a printer to a printer group.""" 
    195195        if (printer not in self.parent.getParentPrinters(self)) and (printer.ident != self.ident) : 
    196196            self.parent.writePrinterToGroup(self, printer) 
    197197            # TODO : reset cached value for printer parents, or add new parent to cached value 
    198              
    199     def delPrinterFromGroup(self, printer) :     
     198 
     199    def delPrinterFromGroup(self, printer) : 
    200200        """Deletes a printer from a printer group.""" 
    201201        self.parent.removePrinterFromGroup(self, printer) 
    202202        # TODO : reset cached value for printer parents, or add new parent to cached value 
    203          
    204     def setPrices(self, priceperpage = None, priceperjob = None) :     
     203 
     204    def setPrices(self, priceperpage = None, priceperjob = None) : 
    205205        """Sets the printer's prices.""" 
    206206        if priceperpage is None : 
    207207            priceperpage = self.PricePerPage or 0.0 
    208         else :     
     208        else : 
    209209            self.PricePerPage = float(priceperpage) 
    210         if priceperjob is None :     
     210        if priceperjob is None : 
    211211            priceperjob = self.PricePerJob or 0.0 
    212         else :     
     212        else : 
    213213            self.PricePerJob = float(priceperjob) 
    214         self.isDirty = True     
    215          
     214        self.isDirty = True 
     215 
    216216    def setPassThrough(self, passthrough) : 
    217217        """Sets the printer's passthrough mode.""" 
    218218        self.PassThrough = passthrough 
    219219        self.isDirty = True 
    220          
     220 
    221221    def setMaxJobSize(self, maxjobsize) : 
    222222        """Sets the printer's maximal job size.""" 
    223223        self.MaxJobSize = maxjobsize 
    224224        self.isDirty = True 
    225          
    226     def delete(self) :     
     225 
     226    def delete(self) : 
    227227        """Deletes a printer from the database.""" 
    228228        self.parent.deletePrinter(self) 
     
    236236                    self.parent.flushEntry("GROUPPQUOTAS", "%s@%s" % (v.Group.Name, v.Printer.Name)) 
    237237        self.Exists = False 
    238         self.isDirty = False             
    239          
    240          
     238        self.isDirty = False 
     239 
     240 
    241241class StorageUserPQuota(StorageObject) : 
    242242    """User Print Quota class.""" 
     
    252252        self.WarnCount = None 
    253253        self.MaxJobSize = None 
    254          
    255     def __getattr__(self, name) :     
     254 
     255    def __getattr__(self, name) : 
    256256        """Delays data retrieval until it's really needed.""" 
    257         if name == "ParentPrintersUserPQuota" :  
     257        if name == "ParentPrintersUserPQuota" : 
    258258            self.ParentPrintersUserPQuota = (self.User.Exists and self.Printer.Exists and self.parent.getParentPrintersUserPQuota(self)) or [] 
    259259            return self.ParentPrintersUserPQuota 
    260260        else : 
    261261            raise AttributeError, name 
    262          
    263     def setDateLimit(self, datelimit) :     
     262 
     263    def setDateLimit(self, datelimit) : 
    264264        """Sets the date limit for this quota.""" 
    265265        datelimit = DateTime.ISO.ParseDateTime(str(datelimit)[:19]) 
     
    267267        self.parent.writeUserPQuotaDateLimit(self, date) 
    268268        self.DateLimit = date 
    269          
    270     def setLimits(self, softlimit, hardlimit) :     
     269 
     270    def setLimits(self, softlimit, hardlimit) : 
    271271        """Sets the soft and hard limit for this quota.""" 
    272272        self.SoftLimit = softlimit 
     
    275275        self.WarnCount = 0 
    276276        self.isDirty = True 
    277          
     277 
    278278    def setUsage(self, used) : 
    279279        """Sets the PageCounter and LifePageCounter to used, or if used is + or - prefixed, changes the values of {Life,}PageCounter by that amount.""" 
     
    292292        self.parent.increaseUserPQuotaWarnCount(self) 
    293293        self.WarnCount = (self.WarnCount or 0) + 1 
    294          
     294 
    295295    def resetDenyBannerCounter(self) : 
    296296        """Resets the deny banner counter for this user quota.""" 
    297297        self.parent.writeUserPQuotaWarnCount(self, 0) 
    298298        self.WarnCount = 0 
    299          
    300     def reset(self) :     
     299 
     300    def reset(self) : 
    301301        """Resets page counter to 0.""" 
    302302        self.PageCounter = 0 
    303303        self.DateLimit = None 
    304304        self.isDirty = True 
    305          
    306     def hardreset(self) :     
     305 
     306    def hardreset(self) : 
    307307        """Resets actual and life time page counters to 0.""" 
    308308        self.PageCounter = self.LifePageCounter = 0 
    309309        self.DateLimit = None 
    310310        self.isDirty = True 
    311          
    312     def computeJobPrice(self, jobsize, inkusage=[]) :     
     311 
     312    def computeJobPrice(self, jobsize, inkusage=[]) : 
    313313        """Computes the job price as the sum of all parent printers' prices + current printer's ones.""" 
    314         totalprice = 0.0     
     314        totalprice = 0.0 
    315315        if jobsize : 
    316316            if self.User.OverCharge != 0.0 :    # optimization, but TODO : beware of rounding errors 
     
    320320                    if not inkusage : 
    321321                        totalprice += (jobsize * pageprice) 
    322                     else :     
     322                    else : 
    323323                        for pageindex in range(jobsize) : 
    324324                            try : 
    325325                                usage = inkusage[pageindex] 
    326                             except IndexError :     
     326                            except IndexError : 
    327327                                self.parent.tool.logdebug("No ink usage information. Using base cost of %f credits for page %i." % (pageprice, pageindex+1)) 
    328328                                totalprice += pageprice 
    329                             else :     
     329                            else : 
    330330                                coefficients = upq.Printer.Coefficients 
    331331                                for (ink, value) in usage.items() : 
     
    336336                                    totalprice += inkprice 
    337337        if self.User.OverCharge != 1.0 : # TODO : beware of rounding errors 
    338             overcharged = totalprice * self.User.OverCharge         
     338            overcharged = totalprice * self.User.OverCharge 
    339339            self.parent.tool.logdebug("Overcharging %s by a factor of %s ===> User %s will be charged for %s credits." % (totalprice, self.User.OverCharge, self.User.Name, overcharged)) 
    340340            return overcharged 
    341         else :     
     341        else : 
    342342            return totalprice 
    343              
     343 
    344344    def increasePagesUsage(self, jobsize, inkusage=[]) : 
    345345        """Increase the value of used pages and money.""" 
     
    353353                upq.LifePageCounter = int(upq.LifePageCounter or 0) + jobsize 
    354354        return jobprice 
    355          
    356     def delete(self) :     
     355 
     356    def delete(self) : 
    357357        """Deletes an user print quota entry from the database.""" 
    358358        self.parent.deleteUserPQuota(self) 
     
    361361        self.Exists = False 
    362362        self.isDirty = False 
    363          
    364     def refund(self, nbpages) :     
     363 
     364    def refund(self, nbpages) : 
    365365        """Refunds a number of pages to an user on a particular printer.""" 
    366366        self.parent.increaseUserPQuotaPagesCounters(self, -nbpages) 
    367367        self.PageCounter = int(self.PageCounter or 0) - nbpages 
    368368        self.LifePageCounter = int(self.LifePageCounter or 0) - nbpages 
    369          
    370          
     369 
     370 
    371371class StorageGroupPQuota(StorageObject) : 
    372372    """Group Print Quota class.""" 
     
    381381        self.DateLimit = None 
    382382        self.MaxJobSize = None 
    383          
    384     def __getattr__(self, name) :     
     383 
     384    def __getattr__(self, name) : 
    385385        """Delays data retrieval until it's really needed.""" 
    386         if name == "ParentPrintersGroupPQuota" :  
     386        if name == "ParentPrintersGroupPQuota" : 
    387387            self.ParentPrintersGroupPQuota = (self.Group.Exists and self.Printer.Exists and self.parent.getParentPrintersGroupPQuota(self)) or [] 
    388388            return self.ParentPrintersGroupPQuota 
    389389        else : 
    390390            raise AttributeError, name 
    391          
    392     def reset(self) :     
     391 
     392    def reset(self) : 
    393393        """Resets page counter to 0.""" 
    394394        for user in self.parent.getGroupMembers(self.Group) : 
     
    399399        self.DateLimit = None 
    400400        self.isDirty = True 
    401          
    402     def hardreset(self) :     
     401 
     402    def hardreset(self) : 
    403403        """Resets actual and life time page counters to 0.""" 
    404404        for user in self.parent.getGroupMembers(self.Group) : 
     
    409409        self.DateLimit = None 
    410410        self.isDirty = True 
    411          
    412     def setDateLimit(self, datelimit) :     
     411 
     412    def setDateLimit(self, datelimit) : 
    413413        """Sets the date limit for this quota.""" 
    414414        datelimit = DateTime.ISO.ParseDateTime(str(datelimit)[:19]) 
     
    421421        self.parent.writeGroupPQuotaDateLimit(self, date) 
    422422        self.DateLimit = date 
    423          
    424     def setLimits(self, softlimit, hardlimit) :     
     423 
     424    def setLimits(self, softlimit, hardlimit) : 
    425425        """Sets the soft and hard limit for this quota.""" 
    426426        self.SoftLimit = softlimit 
     
    428428        self.DateLimit = None 
    429429        self.isDirty = True 
    430          
    431     def delete(self) :     
     430 
     431    def delete(self) : 
    432432        """Deletes a group print quota entry from the database.""" 
    433433        self.parent.deleteGroupPQuota(self) 
     
    436436        self.Exists = False 
    437437        self.isDirty = False 
    438          
    439          
     438 
     439 
    440440class StorageJob(StorageObject) : 
    441441    """Printer's Job class.""" 
     
    461461        self.PrecomputedJobSize = None 
    462462        self.PrecomputedJobPrice = None 
    463          
    464     def __getattr__(self, name) :     
     463 
     464    def __getattr__(self, name) : 
    465465        """Delays data retrieval until it's really needed.""" 
    466         if name == "User" :  
     466        if name == "User" : 
    467467            self.User = self.parent.getUser(self.UserName) 
    468468            return self.User 
    469         elif name == "Printer" :     
     469        elif name == "Printer" : 
    470470            self.Printer = self.parent.getPrinter(self.PrinterName) 
    471471            return self.Printer 
    472472        else : 
    473473            raise AttributeError, name 
    474              
    475     def refund(self, reason) :         
     474 
     475    def refund(self, reason) : 
    476476        """Refund a particular print job.""" 
    477477        if (not self.JobSize) or (self.JobAction in ("DENY", "CANCEL", "REFUND")) : 
    478478            return 
    479              
     479 
    480480        basereason = _("Refunded %i pages and %.3f credits by %s (%s) on %s") \ 
    481481                        % (self.JobSize, 
     
    484484                           os.getlogin(), 
    485485                           str(DateTime.now())[:19]) 
    486         if reason :                                                
     486        if reason : 
    487487            reason = "%s : %s" % (basereason, reason) 
    488         else :     
     488        else : 
    489489            reason = basereason 
    490         self.parent.tool.logdebug("Refunding job %s..." % self.ident)     
     490        self.parent.tool.logdebug("Refunding job %s..." % self.ident) 
    491491        self.parent.beginTransaction() 
    492492        try : 
     
    494494                bcode = self.parent.getBillingCode(self.JobBillingCode) 
    495495                bcode.refund(self.JobSize, self.JobPrice) 
    496                  
     496 
    497497            if self.User.Exists : 
    498498                self.User.refund(self.JobPrice, reason) 
    499                 if self.Printer.Exists :     
    500                     upq = self.parent.getUserPQuota(self.User, self.Printer)     
     499                if self.Printer.Exists : 
     500                    upq = self.parent.getUserPQuota(self.User, self.Printer) 
    501501                    if upq.Exists : 
    502502                        upq.refund(self.JobSize) 
    503503            self.parent.refundJob(self.ident) 
    504         except :         
     504        except : 
    505505            self.parent.rollbackTransaction() 
    506506            self.parent.tool.logdebug("Error while refunding job %s." % self.ident) 
    507507            raise 
    508         else :     
     508        else : 
    509509            self.parent.commitTransaction() 
    510510            self.parent.tool.logdebug("Job %s refunded." % self.ident) 
    511          
    512          
     511 
     512 
    513513class StorageLastJob(StorageJob) : 
    514514    """Printer's Last Job class.""" 
     
    517517        self.PrinterName = printer.Name # not needed 
    518518        self.Printer = printer 
    519          
    520          
     519 
     520 
    521521class StorageBillingCode(StorageObject) : 
    522522    """Billing code class.""" 
     
    526526        self.PageCounter = None 
    527527        self.Balance = None 
    528          
    529     def delete(self) :     
     528 
     529    def delete(self) : 
    530530        """Deletes the billing code from the database.""" 
    531531        self.parent.deleteBillingCode(self) 
     
    533533        self.isDirty = False 
    534534        self.Exists = False 
    535          
    536     def reset(self, balance=0.0, pagecounter=0) :     
     535 
     536    def reset(self, balance=0.0, pagecounter=0) : 
    537537        """Resets the pagecounter and balance for this billing code.""" 
    538538        self.Balance = balance 
    539539        self.PageCounter = pagecounter 
    540540        self.isDirty = True 
    541          
     541 
    542542    def consume(self, pages, price) : 
    543543        """Consumes some pages and credits for this billing code.""" 
     
    546546            self.PageCounter += pages 
    547547            self.Balance -= price 
    548             
     548 
    549549    def refund(self, pages, price) : 
    550550        """Refunds a particular billing code.""" 
    551551        self.consume(-pages, -price) 
    552          
    553          
     552 
     553 
    554554class BaseStorage : 
    555555    def __init__(self, pykotatool) : 
     
    572572                            "LASTJOBS" : {}, \ 
    573573                            "BILLINGCODES" : {} } 
    574          
    575     def close(self) :     
     574 
     575    def close(self) : 
    576576        """Must be overriden in children classes.""" 
    577577        raise RuntimeError, "BaseStorage.close() must be overriden !" 
    578          
    579     def __del__(self) :         
     578 
     579    def __del__(self) : 
    580580        """Ensures that the database connection is closed.""" 
    581581        self.close() 
    582          
    583     def querydebug(self, qmsg) :     
     582 
     583    def querydebug(self, qmsg) : 
    584584        """Logs a database query, where all queries are already UTF-8 encoded.""" 
    585585        self.tool.logdebug(qmsg.decode("UTF-8", "replace")) 
    586          
     586 
    587587    def getFromCache(self, cachetype, key) : 
    588588        """Tries to extract something from the cache.""" 
     
    591591            if entry is not None : 
    592592                self.tool.logdebug("Cache hit (%s->%s)" % (cachetype, key)) 
    593             else :     
     593            else : 
    594594                self.tool.logdebug("Cache miss (%s->%s)" % (cachetype, key)) 
    595             return entry     
    596              
    597     def cacheEntry(self, cachetype, key, value) :         
     595            return entry 
     596 
     597    def cacheEntry(self, cachetype, key, value) : 
    598598        """Puts an entry in the cache.""" 
    599599        if self.usecache and getattr(value, "Exists", 0) : 
    600600            self.caches[cachetype][key] = value 
    601601            self.tool.logdebug("Cache store (%s->%s)" % (cachetype, key)) 
    602              
    603     def flushEntry(self, cachetype, key) :         
     602 
     603    def flushEntry(self, cachetype, key) : 
    604604        """Removes an entry from the cache.""" 
    605605        if self.usecache : 
    606606            try : 
    607607                del self.caches[cachetype][key] 
    608             except KeyError :     
     608            except KeyError : 
    609609                pass 
    610             else :     
     610            else : 
    611611                self.tool.logdebug("Cache flush (%s->%s)" % (cachetype, key)) 
    612              
    613     def getUser(self, username) :         
     612 
     613    def getUser(self, username) : 
    614614        """Returns the user from cache.""" 
    615615        user = self.getFromCache("USERS", username) 
     
    617617            user = self.getUserFromBackend(username) 
    618618            self.cacheEntry("USERS", username, user) 
    619         return user     
    620          
    621     def getGroup(self, groupname) :         
     619        return user 
     620 
     621    def getGroup(self, groupname) : 
    622622        """Returns the group from cache.""" 
    623623        group = self.getFromCache("GROUPS", groupname) 
     
    625625            group = self.getGroupFromBackend(groupname) 
    626626            self.cacheEntry("GROUPS", groupname, group) 
    627         return group     
    628          
    629     def getPrinter(self, printername) :         
     627        return group 
     628 
     629    def getPrinter(self, printername) : 
    630630        """Returns the printer from cache.""" 
    631631        printer = self.getFromCache("PRINTERS", printername) 
     
    633633            printer = self.getPrinterFromBackend(printername) 
    634634            self.cacheEntry("PRINTERS", printername, printer) 
    635         return printer     
    636          
    637     def getUserPQuota(self, user, printer) :         
     635        return printer 
     636 
     637    def getUserPQuota(self, user, printer) : 
    638638        """Returns the user quota information from cache.""" 
    639639        useratprinter = "%s@%s" % (user.Name, printer.Name) 
     
    642642            upquota = self.getUserPQuotaFromBackend(user, printer) 
    643643            self.cacheEntry("USERPQUOTAS", useratprinter, upquota) 
    644         return upquota     
    645          
    646     def getGroupPQuota(self, group, printer) :         
     644        return upquota 
     645 
     646    def getGroupPQuota(self, group, printer) : 
    647647        """Returns the group quota information from cache.""" 
    648648        groupatprinter = "%s@%s" % (group.Name, printer.Name) 
     
    651651            gpquota = self.getGroupPQuotaFromBackend(group, printer) 
    652652            self.cacheEntry("GROUPPQUOTAS", groupatprinter, gpquota) 
    653         return gpquota     
    654          
    655     def getPrinterLastJob(self, printer) :         
     653        return gpquota 
     654 
     655    def getPrinterLastJob(self, printer) : 
    656656        """Extracts last job information for a given printer from cache.""" 
    657657        lastjob = self.getFromCache("LASTJOBS", printer.Name) 
     
    659659            lastjob = self.getPrinterLastJobFromBackend(printer) 
    660660            self.cacheEntry("LASTJOBS", printer.Name, lastjob) 
    661         return lastjob     
    662          
    663     def getBillingCode(self, label) :         
     661        return lastjob 
     662 
     663    def getBillingCode(self, label) : 
    664664        """Returns the user from cache.""" 
    665665        code = self.getFromCache("BILLINGCODES", label) 
     
    668668            self.cacheEntry("BILLINGCODES", label, code) 
    669669        return code 
    670          
    671     def getParentPrinters(self, printer) :     
     670 
     671    def getParentPrinters(self, printer) : 
    672672        """Extracts parent printers information for a given printer from cache.""" 
    673673        if self.usecache : 
     
    678678            else : 
    679679                self.tool.logdebug("Cache hit (%s->Parents)" % printer.Name) 
    680         else :         
     680        else : 
    681681            printer.Parents = self.getParentPrintersFromBackend(printer) 
    682         for parent in printer.Parents[:] :     
     682        for parent in printer.Parents[:] : 
    683683            printer.Parents.extend(self.getParentPrinters(parent)) 
    684         uniquedic = {}     
     684        uniquedic = {} 
    685685        for parent in printer.Parents : 
    686686            uniquedic[parent.Name] = parent 
    687         printer.Parents = uniquedic.values()     
     687        printer.Parents = uniquedic.values() 
    688688        return printer.Parents 
    689          
    690     def getGroupMembers(self, group) :         
     689 
     690    def getGroupMembers(self, group) : 
    691691        """Returns the group's members list from in-group cache.""" 
    692692        if self.usecache : 
     
    697697            else : 
    698698                self.tool.logdebug("Cache hit (%s->Members)" % group.Name) 
    699         else :         
     699        else : 
    700700            group.Members = self.getGroupMembersFromBackend(group) 
    701         return group.Members     
    702          
    703     def getUserGroups(self, user) :         
     701        return group.Members 
     702 
     703    def getUserGroups(self, user) : 
    704704        """Returns the user's groups list from in-user cache.""" 
    705705        if self.usecache : 
     
    710710            else : 
    711711                self.tool.logdebug("Cache hit (%s->Groups)" % user.Name) 
    712         else :         
     712        else : 
    713713            user.Groups = self.getUserGroupsFromBackend(user) 
    714         return user.Groups    
    715          
    716     def getParentPrintersUserPQuota(self, userpquota) :      
     714        return user.Groups 
     715 
     716    def getParentPrintersUserPQuota(self, userpquota) : 
    717717        """Returns all user print quota on the printer and all its parents recursively.""" 
    718718        upquotas = [ ] 
     
    721721            if upq.Exists : 
    722722                upquotas.append(upq) 
    723         return upquotas         
    724          
    725     def getParentPrintersGroupPQuota(self, grouppquota) :      
     723        return upquotas 
     724 
     725    def getParentPrintersGroupPQuota(self, grouppquota) : 
    726726        """Returns all group print quota on the printer and all its parents recursively.""" 
    727727        gpquotas = [ ] 
     
    730730            if gpq.Exists : 
    731731                gpquotas.append(gpq) 
    732         return gpquotas         
    733          
    734     def cleanDates(self, startdate, enddate) :     
     732        return gpquotas 
     733 
     734    def cleanDates(self, startdate, enddate) : 
    735735        """Clean the dates to create a correct filter.""" 
    736         if startdate :     
     736        if startdate : 
    737737            startdate = startdate.strip().lower() 
    738         if enddate :     
     738        if enddate : 
    739739            enddate = enddate.strip().lower() 
    740         if (not startdate) and (not enddate) :     
     740        if (not startdate) and (not enddate) : 
    741741            return (None, None) 
    742              
    743         now = DateTime.now()     
     742 
     743        now = DateTime.now() 
    744744        nameddates = ('yesterday', 'today', 'now', 'tomorrow') 
    745         datedict = { "start" : startdate, "end" : enddate }     
     745        datedict = { "start" : startdate, "end" : enddate } 
    746746        for limit in datedict.keys() : 
    747747            dateval = datedict[limit] 
     
    751751                        try : 
    752752                            offset = int(dateval[len(name):]) 
    753                         except :     
     753                        except : 
    754754                            offset = 0 
    755                         dateval = dateval[:len(name)]     
     755                        dateval = dateval[:len(name)] 
    756756                        if limit == "start" : 
    757757                            if dateval == "yesterday" : 
     
    773773                                dateval = (now + 1 + offset).Format("%Y%m%d235959") 
    774774                        break 
    775                          
     775 
    776776                if not dateval.isdigit() : 
    777777                    dateval = None 
    778                 else :     
     778                else : 
    779779                    lgdateval = len(dateval) 
    780780                    if lgdateval == 4 : 
    781                         if limit == "start" :  
     781                        if limit == "start" : 
    782782                            dateval = "%s0101 00:00:00" % dateval 
    783                         else :   
     783                        else : 
    784784                            dateval = "%s1231 23:59:59" % dateval 
    785785                    elif lgdateval == 6 : 
    786                         if limit == "start" :  
     786                        if limit == "start" : 
    787787                            dateval = "%s01 00:00:00" % dateval 
    788                         else :   
     788                        else : 
    789789                            mxdate = DateTime.ISO.ParseDateTime("%s01 00:00:00" % dateval) 
    790790                            dateval = "%s%02i 23:59:59" % (dateval, mxdate.days_in_month) 
    791791                    elif lgdateval == 8 : 
    792                         if limit == "start" :  
     792                        if limit == "start" : 
    793793                            dateval = "%s 00:00:00" % dateval 
    794                         else :   
     794                        else : 
    795795                            dateval = "%s 23:59:59" % dateval 
    796796                    elif lgdateval == 10 : 
    797                         if limit == "start" :  
     797                        if limit == "start" : 
    798798                            dateval = "%s %s:00:00" % (dateval[:8], dateval[8:]) 
    799                         else :   
     799                        else : 
    800800                            dateval = "%s %s:59:59" % (dateval[:8], dateval[8:]) 
    801801                    elif lgdateval == 12 : 
    802                         if limit == "start" :  
     802                        if limit == "start" : 
    803803                            dateval = "%s %s:%s:00" % (dateval[:8], dateval[8:10], dateval[10:]) 
    804                         else :   
     804                        else : 
    805805                            dateval = "%s %s:%s:59" % (dateval[:8], dateval[8:10], dateval[10:]) 
    806                     elif lgdateval == 14 :         
     806                    elif lgdateval == 14 : 
    807807                        dateval = "%s %s:%s:%s" % (dateval[:8], dateval[8:10], dateval[10:12], dateval[12:]) 
    808                     else :     
     808                    else : 
    809809                        dateval = None 
    810                     try :     
     810                    try : 
    811811                        DateTime.ISO.ParseDateTime(dateval[:19]) 
    812                     except :     
     812                    except : 
    813813                        dateval = None 
    814                 datedict[limit] = dateval     
     814                datedict[limit] = dateval 
    815815        (start, end) = (datedict["start"], datedict["end"]) 
    816816        if start and end and (start > end) : 
    817817            (start, end) = (end, start) 
    818         try :     
     818        try : 
    819819            if len(start) == 17 : 
    820820                start = "%s-%s-%s %s" % (start[0:4], start[4:6], start[6:8], start[9:]) 
    821         except TypeError :         
     821        except TypeError : 
    822822            pass 
    823              
    824         try :     
     823 
     824        try : 
    825825            if len(end) == 17 : 
    826826                end = "%s-%s-%s %s" % (end[0:4], end[4:6], end[6:8], end[9:]) 
    827         except TypeError :         
     827        except TypeError : 
    828828            pass 
    829              
    830         return (start, end)     
    831          
     829 
     830        return (start, end) 
     831 
    832832def openConnection(pykotatool) : 
    833833    """Returns a connection handle to the appropriate database.""" 
     
    835835    backend = backendinfo["storagebackend"] 
    836836    try : 
    837         storagebackend = imp.load_source("storagebackend",  
     837        storagebackend = imp.load_source("storagebackend", 
    838838                                         os.path.join(os.path.dirname(__file__), 
    839839                                                      "storages", 
     
    841841    except ImportError : 
    842842        raise PyKotaStorageError, _("Unsupported quota storage backend %s") % backend 
    843     else :     
     843    else : 
    844844        host = backendinfo["storageserver"] 
    845845        database = backendinfo["storagename"]