Changeset 2717

Show
Ignore:
Timestamp:
02/20/06 22:12:24 (18 years ago)
Author:
jerome
Message:

Added deletion methods for user and group print quota entries.

Location:
pykota/trunk/pykota
Files:
3 modified

Legend:

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

    r2707 r2717  
    2626 
    2727class PyKotaStorageError(Exception): 
    28     """An exception for Quota Storage related stuff.""" 
     28    """An exception for database related stuff.""" 
    2929    def __init__(self, message = ""): 
    3030        self.message = message 
     
    3535         
    3636class StorageObject : 
    37     """Object present in the Quota Storage.""" 
     37    """Object present in the database.""" 
    3838    def __init__(self, parent) : 
    3939        "Initialize minimal data.""" 
     
    9898         
    9999    def delete(self) :     
    100         """Deletes an user from the Quota Storage.""" 
     100        """Deletes an user from the database.""" 
    101101        self.parent.beginTransaction() 
    102102        try : 
     
    142142         
    143143    def delete(self) :     
    144         """Deletes a group from the Quota Storage.""" 
     144        """Deletes a group from the database.""" 
    145145        self.parent.beginTransaction() 
    146146        try : 
     
    216216         
    217217    def delete(self) :     
    218         """Deletes a printer from the Quota Storage.""" 
     218        """Deletes a printer from the database.""" 
    219219        self.parent.beginTransaction() 
    220220        try : 
     
    343343        return jobprice 
    344344         
     345    def delete(self) :     
     346        """Deletes an user print quota entry from the database.""" 
     347        self.parent.beginTransaction() 
     348        try : 
     349            self.parent.deleteUserPQuota(self) 
     350        except PyKotaStorageError, msg :     
     351            self.parent.rollbackTransaction() 
     352            raise PyKotaStorageError, msg 
     353        else :     
     354            self.parent.commitTransaction() 
     355            if self.parent.usecache : 
     356                for (k, v) in self.parent.caches["USERPQUOTAS"].items() : 
     357                    if v.User.Name == self.User.Name : 
     358                        self.parent.flushEntry("USERPQUOTAS", "%s@%s" % (v.User.Name, v.Printer.Name)) 
     359            self.Exists = 0 
     360         
    345361class StorageGroupPQuota(StorageObject) : 
    346362    """Group Print Quota class.""" 
     
    413429        self.HardLimit = hardlimit 
    414430        self.DateLimit = None 
     431         
     432    def delete(self) :     
     433        """Deletes a group print quota entry from the database.""" 
     434        self.parent.beginTransaction() 
     435        try : 
     436            self.parent.deleteGroupPQuota(self) 
     437        except PyKotaStorageError, msg :     
     438            self.parent.rollbackTransaction() 
     439            raise PyKotaStorageError, msg 
     440        else :     
     441            self.parent.commitTransaction() 
     442            if self.parent.usecache : 
     443                for (k, v) in self.parent.caches["GROUPPQUOTAS"].items() : 
     444                    if v.Group.Name == self.Group.Name : 
     445                        self.parent.flushEntry("GROUPPQUOTAS", "%s@%s" % (v.Group.Name, v.Printer.Name)) 
     446            self.Exists = 0 
    415447         
    416448class StorageJob(StorageObject) : 
     
    773805         
    774806def openConnection(pykotatool) : 
    775     """Returns a connection handle to the appropriate Quota Storage Database.""" 
     807    """Returns a connection handle to the appropriate database.""" 
    776808    backendinfo = pykotatool.config.getStorageBackend() 
    777809    backend = backendinfo["storagebackend"] 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2707 r2717  
    14051405                self.doDelete(group.ident) 
    14061406                 
     1407    def deleteUserPQuota(self, upquota) :     
     1408        """Completely deletes an user print quota entry from the database.""" 
     1409        uname = self.userCharsetToDatabase(upquota.User.Name) 
     1410        pname = self.userCharsetToDatabase(upquota.Printer.Name) 
     1411        result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s)(pykotaPrinterName=%s))" \ 
     1412                                   % (uname, pname), \ 
     1413                                   base=self.info["jobbase"]) 
     1414        for (ident, fields) in result : 
     1415            self.doDelete(ident) 
     1416        self.doDelete(upquota.ident) 
     1417         
     1418    def deleteGroupPQuota(self, gpquota) :     
     1419        """Completely deletes a group print quota entry from the database.""" 
     1420        self.doDelete(gpquota.ident) 
     1421                 
    14071422    def deletePrinter(self, printer) :     
    14081423        """Completely deletes a printer from the Quota Storage.""" 
  • pykota/trunk/pykota/storages/sql.py

    r2707 r2717  
    729729         
    730730    def deleteUser(self, user) :     
    731         """Completely deletes an user from the Quota Storage.""" 
     731        """Completely deletes an user from the database.""" 
    732732        # TODO : What should we do if we delete the last person who used a given printer ? 
    733733        # TODO : we can't reassign the last job to the previous one, because next user would be 
     
    741741                  ] : 
    742742            self.doModify(q) 
     743             
     744    def deleteUserPQuota(self, upquota) :     
     745        """Completely deletes an user print quota entry from the database.""" 
     746        for q in [  
     747                    "DELETE FROM jobhistory WHERE userid=%s" % self.doQuote(upquota.User.ident), 
     748                    "DELETE FROM userpquota WHERE userid=%s" % self.doQuote(upquota.ident), 
     749                  ] : 
     750            self.doModify(q) 
     751         
     752    def deleteGroupPQuota(self, gpquota) :     
     753        """Completely deletes a group print quota entry from the database.""" 
     754        for q in [  
     755                    "DELETE FROM grouppquota WHERE groupid=%s" % self.doQuote(gpquota.ident), 
     756                  ] : 
     757            self.doModify(q) 
    743758         
    744759    def deleteGroup(self, group) :     
    745         """Completely deletes a group from the Quota Storage.""" 
     760        """Completely deletes a group from the database.""" 
    746761        for q in [ 
    747762                   "DELETE FROM groupsmembers WHERE groupid=%s" % self.doQuote(group.ident), 
     
    752767             
    753768    def deletePrinter(self, printer) :     
    754         """Completely deletes a printer from the Quota Storage.""" 
     769        """Completely deletes a printer from the database.""" 
    755770        for q in [  
    756771                    "DELETE FROM printergroupsmembers WHERE groupid=%s OR printerid=%s" % (self.doQuote(printer.ident), self.doQuote(printer.ident)), 
     
    763778             
    764779    def deleteBillingCode(self, code) :     
    765         """Completely deletes a billing code from the Quota Storage.""" 
     780        """Completely deletes a billing code from the database.""" 
    766781        for q in [ 
    767782                   "DELETE FROM billingcodes WHERE id=%s" % self.doQuote(code.ident),