Changeset 2763

Show
Ignore:
Timestamp:
02/28/06 00:14:02 (19 years ago)
Author:
jerome
Message:

Added some multiple deletions routines.

Location:
pykota/trunk/pykota/storages
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2756 r2763  
    14621462                self.doDelete(group.ident) 
    14631463                 
     1464    def deleteManyBillingCodesFromNames(self, billingcodes) :         
     1465        """Deletes many billing codes from their names.""" 
     1466        for bcode in self.getMatchingBillingCodes(",".join(billingcodes)) : 
     1467            bcode.delete() 
     1468         
     1469    def deleteManyUsersFromNames(self, usernames) :         
     1470        """Deletes many users from their names.""" 
     1471        for user in self.getMatchingUsers(",".join(usernames)) :  
     1472            user.delete() 
     1473             
     1474    def deleteManyGroupsFromNames(self, groupnames) :         
     1475        """Deletes many groups from their names.""" 
     1476        for group in self.getMatchingGroups(",".join(groupnames)) :  
     1477            group.delete() 
     1478         
     1479    def deleteManyPrintersFromNames(self, printernames) :         
     1480        """Deletes many printers from their names.""" 
     1481        for printer in self.getMatchingPrinters(",".join(printernames)) : 
     1482            printer.delete() 
     1483         
    14641484    def deleteManyUserPQuotas(self, printers, users) :         
    14651485        """Deletes many user print quota entries.""" 
  • pykota/trunk/pykota/storages/sql.py

    r2758 r2763  
    801801            self.doModify(q) 
    802802             
     803    def deleteInTransaction(self, queries) :         
     804        """Does many deletions in a single transaction.""" 
     805        self.beginTransaction() 
     806        try : 
     807            for q in queries : 
     808                self.doModify(q) 
     809        except :     
     810            self.rollbackTransaction() 
     811            raise 
     812        else :     
     813            self.commitTransaction() 
     814             
     815    def deleteManyBillingCodesFromNames(self, billingcodes) :         
     816        """Deletes many billing codes from their names.""" 
     817        codelabels = ", ".join(["%s" % self.doQuote(b) for b in billingcodes]) 
     818        self.deleteInTransaction([  
     819                    "DELETE FROM billingcodes WHERE billingcode IN (%s)" % codelabels,]) 
     820             
     821    def deleteManyUsersFromNames(self, usernames) :         
     822        """Deletes many users from their names.""" 
     823        usernames = ", ".join(["%s" % self.doQuote(u) for u in usernames]) 
     824        self.deleteInTransaction([  
     825                    "DELETE FROM payments WHERE userid IN (SELECT id FROM users WHERE username IN %s)" % usernames, 
     826                    "DELETE FROM groupsmembers WHERE userid IN (SELECT id FROM users WHERE username IN %s)" % usernames, 
     827                    "DELETE FROM jobhistory WHERE userid IN (SELECT id FROM users WHERE username IN %s)" % usernames, 
     828                    "DELETE FROM userpquota WHERE userid IN (SELECT id FROM users WHERE username IN %s)" % usernames, 
     829                    "DELETE FROM users WHERE username IN %s" % usernames,]) 
     830         
     831    def deleteManyPrintersFromNames(self, printernames) :         
     832        """Deletes many printers from their names.""" 
     833        printernames = ", ".join(["%s" % self.doQuote(p) for p in printernames]) 
     834        self.deleteInTransaction([  
     835                    "DELETE FROM printergroupsmembers WHERE groupid=%s OR printerid=%s" % (self.doQuote(printer.ident), self.doQuote(printer.ident)), 
     836                    "DELETE FROM jobhistory WHERE printerid=%s" % self.doQuote(printer.ident), 
     837                    "DELETE FROM grouppquota WHERE printerid=%s" % self.doQuote(printer.ident), 
     838                    "DELETE FROM userpquota WHERE printerid=%s" % self.doQuote(printer.ident), 
     839                    "DELETE FROM printers WHERE id=%s" % self.doQuote(printer.ident),]) 
     840         
    803841    def deleteManyUserPQuotas(self, printers, users) :         
    804842        """Deletes many user print quota entries.""" 
    805843        printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 
    806844        userids = ", ".join(["%s" % self.doQuote(u.ident) for u in users]) 
    807         for q in [  
     845        self.deleteInTransaction([  
    808846                    "DELETE FROM jobhistory WHERE userid IN (%s) AND printerid IN (%s)" \ 
    809847                                 % (userids, printerids), 
    810848                    "DELETE FROM userpquota WHERE userid IN (%s) AND printerid IN (%s)" \ 
    811                                  % (userids, printerids), 
    812                   ] : 
    813             self.doModify(q) 
     849                                 % (userids, printerids),]) 
    814850             
    815851    def deleteManyGroupPQuotas(self, printers, groups) : 
     
    817853        printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 
    818854        groupids = ", ".join(["%s" % self.doQuote(g.ident) for g in groups]) 
    819         for q in [  
     855        self.deleteInTransaction([  
    820856                    "DELETE FROM grouppquota WHERE groupid IN (%s) AND printerid IN (%s)" \ 
    821                                  % (groupids, printerids), 
    822                   ] : 
    823             self.doModify(q) 
     857                                 % (groupids, printerids),]) 
    824858         
    825859    def deleteUserPQuota(self, upquota) :