Show
Ignore:
Timestamp:
03/02/06 12:37:52 (18 years ago)
Author:
jerome
Message:

pkusers is now optimized like pkprinters, pkbcodes and edpykota.

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

Legend:

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

    r2768 r2773  
    909909         
    910910    def addUser(self, user) :         
    911         """Adds a user to the quota storage, returns it.""" 
     911        """Adds a user to the quota storage, returns the old value if it already exists.""" 
     912        oldentry = self.getUser(user.Name) 
     913        if oldentry.Exists : 
     914            return oldentry # we return the existing entry 
    912915        uname = self.userCharsetToDatabase(user.Name) 
    913916        newfields = { 
     
    971974                dn = "%s=%s,%s" % (self.info["balancerdn"], uname, self.info["balancebase"]) 
    972975                self.doAdd(dn, fields) 
    973              
    974         return self.getUser(user.Name) 
     976        user.idbalance = dn 
     977        if user.PaymentsBacklog : 
     978            for (value, comment) in user.PaymentsBacklog : 
     979                self.writeNewPayment(user, value, comment) 
     980            user.PaymentsBacklog = [] 
     981        user.isDirty = False 
     982        return None # the entry created doesn't need further modification 
    975983         
    976984    def addGroup(self, group) :         
    977         """Adds a group to the quota storage, returns it.""" 
     985        """Adds a group to the quota storage, returns the old value if it already exists.""" 
     986        oldentry = self.getGroup(group.Name) 
     987        if oldentry.Exists : 
     988            return oldentry # we return the existing entry 
    978989        gname = self.userCharsetToDatabase(group.Name) 
    979990        newfields = {  
     
    10141025            dn = "%s=%s,%s" % (self.info["grouprdn"], gname, self.info["groupbase"]) 
    10151026            self.doAdd(dn, fields) 
    1016         return self.getGroup(group.Name) 
     1027        group.isDirty = False 
     1028        return None # the entry created doesn't need further modification 
    10171029         
    10181030    def addUserToGroup(self, user, group) :     
  • pykota/trunk/pykota/storages/mysqlstorage.py

    r2741 r2773  
    130130            self.cursor.execute(query) 
    131131        except self.database.Error, msg :     
     132            self.tool.logdebug("Query failed : %s" % repr(msg)) 
    132133            raise PyKotaStorageError, str(msg) 
    133134        else :     
  • pykota/trunk/pykota/storages/pgstorage.py

    r2741 r2773  
    115115            result = self.database.query(query) 
    116116        except PGError, msg :     
     117            self.tool.logdebug("Query failed : %s" % repr(msg)) 
    117118            raise PyKotaStorageError, str(msg) 
    118119        else :     
  • pykota/trunk/pykota/storages/sqlitestorage.py

    r2741 r2773  
    121121            self.cursor.execute(query) 
    122122        except self.database.Error, msg :     
     123            self.tool.logdebug("Query failed : %s" % repr(msg)) 
    123124            raise PyKotaStorageError, str(msg) 
    124125        else :     
  • pykota/trunk/pykota/storages/sql.py

    r2771 r2773  
    562562         
    563563    def addUser(self, user) :         
    564         """Adds a user to the quota storage, returns it.""" 
    565         self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ 
     564        """Adds a user to the quota storage, returns the old value if it already exists.""" 
     565        try : 
     566            self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ 
    566567                                         (self.doQuote(self.userCharsetToDatabase(user.Name)), \ 
    567568                                          self.doQuote(user.LimitBy or 'quota'), \ 
     
    571572                                          self.doQuote(user.OverCharge), \ 
    572573                                          self.doQuote(self.userCharsetToDatabase(user.Description)))) 
    573         return self.getUser(user.Name) 
     574        except PyKotaStorageError :     
     575            # TODO : check if this is an error different from a duplicate insert 
     576            # return the existing entry which has to be modified 
     577            return self.getUser(user.Name) 
     578        else :     
     579            if user.PaymentsBacklog : 
     580                for (value, comment) in user.PaymentsBacklog : 
     581                    self.writeNewPayment(user, value, comment) 
     582                user.PaymentsBacklog = [] 
     583            user.isDirty = False 
     584            return None # the entry created doesn't need further modification 
    574585         
    575586    def addGroup(self, group) :         
    576         """Adds a group to the quota storage, returns it.""" 
    577         self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ 
    578                                           (self.doQuote(self.userCharsetToDatabase(group.Name)), \ 
    579                                            self.doQuote(group.LimitBy or "quota"), \ 
    580                                            self.doQuote(self.userCharsetToDatabase(group.Description)))) 
    581         return self.getGroup(group.Name) 
     587        """Adds a group to the quota storage, returns the old value if it already exists.""" 
     588        try : 
     589            self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ 
     590                                  (self.doQuote(self.userCharsetToDatabase(group.Name)), \ 
     591                                   self.doQuote(group.LimitBy or "quota"), \ 
     592                                   self.doQuote(self.userCharsetToDatabase(group.Description)))) 
     593        except PyKotaStorageError :     
     594            # TODO : check if this is an error different from a duplicate insert 
     595            # return the existing entry which has to be modified 
     596            return self.getGroup(group.Name) 
     597        else :     
     598            group.isDirty = False 
     599            return None # the entry created doesn't need further modification 
    582600 
    583601    def addUserToGroup(self, user, group) :     
     
    693711    def writeNewPayment(self, user, amount, comment="") : 
    694712        """Adds a new payment to the payments history.""" 
    695         self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
     713        if user.ident is not None : 
     714            self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
     715        else :     
     716            self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(self.userCharsetToDatabase(user.Name)), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
    696717         
    697718    def writeLastJobSize(self, lastjob, jobsize, jobprice) :