Changeset 2706

Show
Ignore:
Timestamp:
02/17/06 23:51:17 (18 years ago)
Author:
jerome
Message:

pkusers now mostly works. Removing an user from a group with
LDAP is not yet done though. Also no test was done with
LDAP yet.
filldb now really creates users (it uses pkusers instead
of edpykota)

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkusers

    r2705 r2706  
    297297                    usersgroups = [] 
    298298                         
    299                 if options["description"] : 
     299                description = options["description"] 
     300                if description : 
    300301                    description = options["description"].strip() 
     302                     
     303                comment = options["comment"] 
     304                if comment : 
     305                    comment = options["comment"].strip() 
    301306                     
    302307                nbtotal = len(entries) 
    303308                for i in range(nbtotal) :         
    304309                    entry = entries[i] 
    305                     if description is not None :        # NB : "" is allowed ! 
     310                    if description is not None : # NB : "" is allowed ! 
    306311                        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                             
    307319                    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                                         
    309332                        for ugroup in usersgroups : 
    310333                            if options["remove"] : 
     
    312335                            else : 
    313336                                ugroup.addUserToGroup(entry) 
     337                                 
    314338                    percent = 100.0 * float(i) / float(nbtotal) 
    315339                    self.display("\r%.02f%%" % percent) 
  • pykota/trunk/pykota/storage.py

    r2699 r2706  
    9696        if limitby in ["quota", "balance", \ 
    9797                       "noquota", "noprint", "nochange"] : 
    98             self.parent.writeUserLimitBy(self, limitby) 
    9998            self.LimitBy = limitby 
     99            self.isDirty = True 
    100100         
    101101    def setOverChargeFactor(self, factor) :     
    102102        """Sets the user's overcharging coefficient.""" 
    103         self.parent.writeUserOverCharge(self, factor) 
    104103        self.OverCharge = factor 
     104        self.isDirty = True 
    105105         
    106106    def delete(self) :     
     
    137137            limitby = "quota" 
    138138        if limitby in ["quota", "balance", "noquota"] : 
    139             self.parent.writeGroupLimitBy(self, limitby) 
    140139            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) 
    141149         
    142150    def delete(self) :     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2697 r2706  
    982982                group.Members.append(user) 
    983983                 
     984    def delUserFromGroup(self, user, group) :     
     985        """Removes an user from a group.""" 
     986        raise "Not Implemented !" # TODO !!! 
     987                 
    984988    def addUserPQuota(self, user, printer) : 
    985989        """Initializes a user print quota on a printer.""" 
     
    10321036        self.doModify(printer.ident, fields) 
    10331037         
    1034     def writeUserOverCharge(self, user, factor) : 
    1035         """Sets 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) 
    10541058         
    10551059    def writeUserPQuotaDateLimit(self, userpquota, datelimit) :     
  • pykota/trunk/pykota/storages/sql.py

    r2698 r2706  
    545545            self.doModify("INSERT INTO groupsmembers (groupid, userid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(user.ident))) 
    546546             
     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             
    547552    def addUserPQuota(self, user, printer) : 
    548553        """Initializes a user print quota on a printer.""" 
     
    564569                                 self.doQuote(printer.PricePerJob), \ 
    565570                                 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))) 
    578587         
    579588    def writeUserPQuotaDateLimit(self, userpquota, datelimit) :     
  • pykota/trunk/tests/filldb.py

    r2702 r2706  
    6565    argsfile.close()     
    6666    before = time.time() 
    67     os.system('edpykota --arguments arguments.list')  
     67    os.system('pkusers --arguments arguments.list')  
    6868    showTiming(number, before) 
    6969 
     
    7272    sys.stdout.write("Deleting users...\n") 
    7373    before = time.time() 
    74     os.system('edpykota --delete "test-user-*"')  
     74    os.system('pkusers --delete "test-user-*"')  
    7575    showTiming(number, before) 
    7676