Changeset 2773 for pykota/trunk/pykota/storages
- Timestamp:
- 03/02/06 12:37:52 (18 years ago)
- Location:
- pykota/trunk/pykota/storages
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r2768 r2773 909 909 910 910 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 912 915 uname = self.userCharsetToDatabase(user.Name) 913 916 newfields = { … … 971 974 dn = "%s=%s,%s" % (self.info["balancerdn"], uname, self.info["balancebase"]) 972 975 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 975 983 976 984 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 978 989 gname = self.userCharsetToDatabase(group.Name) 979 990 newfields = { … … 1014 1025 dn = "%s=%s,%s" % (self.info["grouprdn"], gname, self.info["groupbase"]) 1015 1026 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 1017 1029 1018 1030 def addUserToGroup(self, user, group) : -
pykota/trunk/pykota/storages/mysqlstorage.py
r2741 r2773 130 130 self.cursor.execute(query) 131 131 except self.database.Error, msg : 132 self.tool.logdebug("Query failed : %s" % repr(msg)) 132 133 raise PyKotaStorageError, str(msg) 133 134 else : -
pykota/trunk/pykota/storages/pgstorage.py
r2741 r2773 115 115 result = self.database.query(query) 116 116 except PGError, msg : 117 self.tool.logdebug("Query failed : %s" % repr(msg)) 117 118 raise PyKotaStorageError, str(msg) 118 119 else : -
pykota/trunk/pykota/storages/sqlitestorage.py
r2741 r2773 121 121 self.cursor.execute(query) 122 122 except self.database.Error, msg : 123 self.tool.logdebug("Query failed : %s" % repr(msg)) 123 124 raise PyKotaStorageError, str(msg) 124 125 else : -
pykota/trunk/pykota/storages/sql.py
r2771 r2773 562 562 563 563 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)" % \ 566 567 (self.doQuote(self.userCharsetToDatabase(user.Name)), \ 567 568 self.doQuote(user.LimitBy or 'quota'), \ … … 571 572 self.doQuote(user.OverCharge), \ 572 573 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 574 585 575 586 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 582 600 583 601 def addUserToGroup(self, user, group) : … … 693 711 def writeNewPayment(self, user, amount, comment="") : 694 712 """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)))) 696 717 697 718 def writeLastJobSize(self, lastjob, jobsize, jobprice) :