Changeset 2706
- Timestamp:
- 02/17/06 23:51:17 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkusers
r2705 r2706 297 297 usersgroups = [] 298 298 299 if options["description"] : 299 description = options["description"] 300 if description : 300 301 description = options["description"].strip() 302 303 comment = options["comment"] 304 if comment : 305 comment = options["comment"].strip() 301 306 302 307 nbtotal = len(entries) 303 308 for i in range(nbtotal) : 304 309 entry = entries[i] 305 if description is not None : 310 if description is not None : # NB : "" is allowed ! 306 311 entry.setDescription(description) 312 if limitby : 313 entry.setLimitBy(limitby) 314 315 if suffix == "User" : 316 if overcharge is not None : # NB : 0 is allowed ! 317 entry.setOverChargeFactor(overcharge) 318 307 319 entry.save() 308 if not options["groups"] : 320 321 if suffix == "User" : 322 if balance : 323 if balance.startswith("+") or balance.startswith("-") : 324 newbalance = float(entry.AccountBalance or 0.0) + balancevalue 325 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue 326 entry.setAccountBalance(newbalance, newlifetimepaid, comment) 327 else : 328 diff = balancevalue - float(entry.AccountBalance or 0.0) 329 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff 330 entry.setAccountBalance(balancevalue, newlifetimepaid, comment) 331 309 332 for ugroup in usersgroups : 310 333 if options["remove"] : … … 312 335 else : 313 336 ugroup.addUserToGroup(entry) 337 314 338 percent = 100.0 * float(i) / float(nbtotal) 315 339 self.display("\r%.02f%%" % percent) -
pykota/trunk/pykota/storage.py
r2699 r2706 96 96 if limitby in ["quota", "balance", \ 97 97 "noquota", "noprint", "nochange"] : 98 self.parent.writeUserLimitBy(self, limitby)99 98 self.LimitBy = limitby 99 self.isDirty = True 100 100 101 101 def setOverChargeFactor(self, factor) : 102 102 """Sets the user's overcharging coefficient.""" 103 self.parent.writeUserOverCharge(self, factor)104 103 self.OverCharge = factor 104 self.isDirty = True 105 105 106 106 def delete(self) : … … 137 137 limitby = "quota" 138 138 if limitby in ["quota", "balance", "noquota"] : 139 self.parent.writeGroupLimitBy(self, limitby)140 139 self.LimitBy = limitby 140 self.isDirty = True 141 142 def addUserToGroup(self, user) : 143 """Adds an user to an users group.""" 144 self.parent.addUserToGroup(user, self) 145 146 def delUserFromGroup(self, user) : 147 """Removes an user from an users group.""" 148 self.parent.delUserFromGroup(user, self) 141 149 142 150 def delete(self) : -
pykota/trunk/pykota/storages/ldapstorage.py
r2697 r2706 982 982 group.Members.append(user) 983 983 984 def delUserFromGroup(self, user, group) : 985 """Removes an user from a group.""" 986 raise "Not Implemented !" # TODO !!! 987 984 988 def addUserPQuota(self, user, printer) : 985 989 """Initializes a user print quota on a printer.""" … … 1032 1036 self.doModify(printer.ident, fields) 1033 1037 1034 def writeUserOverCharge(self, user, factor) :1035 """S ets the user's overcharging coefficient."""1036 fields = {1037 "pykotaOverCharge" : str(factor),1038 }1039 self.doModify(user.ident, fields)1040 1041 def writeUserLimitBy(self, user, limitby) :1042 """Sets the user's limiting factor."""1043 fields = {1044 "pykotaLimitBy" : limitby,1045 }1046 self.doModify(user.ident, fields)1047 1048 def writeGroupLimitBy(self, group, limitby) :1049 """Sets the group's limiting factor."""1050 fields = {1051 "pykotaLimitBy" : limitby,1052 }1053 self.doModify(group.ident, fields)1038 def saveUser(self, user) : 1039 """Saves the user to the database in a single operation.""" 1040 newfields = { 1041 "pykotaLimitBy" : (user.LimitBy or "quota"), 1042 "pykotaOverCharge" : str(user.OverCharge), 1043 } 1044 if user.Email : 1045 newfields.update({self.info["usermail"]: user.Email}) 1046 if user.Description is not None : 1047 newfields.update({"description": self.userCharsetToDatabase(user.Description)}) 1048 self.doModify(user.ident, newfields) 1049 1050 def saveGroup(self, group) : 1051 """Saves the group to the database in a single operation.""" 1052 newfields = { 1053 "pykotaLimitBy" : (group.LimitBy or "quota"), 1054 } 1055 if group.Description is not None : 1056 newfields.update({"description": self.userCharsetToDatabase(group.Description)}) 1057 self.doModify(group.ident, newfields) 1054 1058 1055 1059 def writeUserPQuotaDateLimit(self, userpquota, datelimit) : -
pykota/trunk/pykota/storages/sql.py
r2698 r2706 545 545 self.doModify("INSERT INTO groupsmembers (groupid, userid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(user.ident))) 546 546 547 def delUserFromGroup(self, user, group) : 548 """Removes an user from a group.""" 549 self.doModify("DELETE FROM groupsmembers WHERE groupid=%s AND userid=%s" % \ 550 (self.doQuote(group.ident), self.doQuote(user.ident))) 551 547 552 def addUserPQuota(self, user, printer) : 548 553 """Initializes a user print quota on a printer.""" … … 564 569 self.doQuote(printer.PricePerJob), \ 565 570 self.doQuote(printer.ident))) 566 567 def writeUserOverCharge(self, user, factor) : 568 """Sets the user's overcharging coefficient.""" 569 self.doModify("UPDATE users SET overcharge=%s WHERE id=%s" % (self.doQuote(factor), self.doQuote(user.ident))) 570 571 def writeUserLimitBy(self, user, limitby) : 572 """Sets the user's limiting factor.""" 573 self.doModify("UPDATE users SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(user.ident))) 574 575 def writeGroupLimitBy(self, group, limitby) : 576 """Sets the group's limiting factor.""" 577 self.doModify("UPDATE groups SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(group.ident))) 571 572 def saveUser(self, user) : 573 """Saves the user to the database in a single operation.""" 574 self.doModify("UPDATE users SET limitby=%s, email=%s, overcharge=%s, description=%s WHERE id=%s" \ 575 % (self.doQuote(user.LimitBy or 'quota'), \ 576 self.doQuote(user.Email), \ 577 self.doQuote(user.OverCharge), \ 578 self.doQuote(self.userCharsetToDatabase(user.Description)), \ 579 self.doQuote(user.ident))) 580 581 def saveGroup(self, group) : 582 """Saves the group to the database in a single operation.""" 583 self.doModify("UPDATE groups SET limitby=%s, description=%s WHERE id=%s" \ 584 % (self.doQuote(group.LimitBy or 'quota'), \ 585 self.doQuote(self.userCharsetToDatabase(group.Description)), \ 586 self.doQuote(group.ident))) 578 587 579 588 def writeUserPQuotaDateLimit(self, userpquota, datelimit) : -
pykota/trunk/tests/filldb.py
r2702 r2706 65 65 argsfile.close() 66 66 before = time.time() 67 os.system(' edpykota--arguments arguments.list')67 os.system('pkusers --arguments arguments.list') 68 68 showTiming(number, before) 69 69 … … 72 72 sys.stdout.write("Deleting users...\n") 73 73 before = time.time() 74 os.system(' edpykota--delete "test-user-*"')74 os.system('pkusers --delete "test-user-*"') 75 75 showTiming(number, before) 76 76