Show
Ignore:
Timestamp:
02/13/05 23:02:29 (19 years ago)
Author:
jalet
Message:

Big database structure changes. Upgrade script is now included as well as
the new LDAP schema.
Introduction of the -o | --overcharge command line option to edpykota.
The output of repykota is more complete, but doesn't fit in 80 columns anymore.
Introduction of the new 'maxdenybanners' directive.

Files:
1 modified

Legend:

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

    r2042 r2054  
    2222# 
    2323# $Log$ 
     24# Revision 1.100  2005/02/13 22:02:29  jalet 
     25# Big database structure changes. Upgrade script is now included as well as 
     26# the new LDAP schema. 
     27# Introduction of the -o | --overcharge command line option to edpykota. 
     28# The output of repykota is more complete, but doesn't fit in 80 columns anymore. 
     29# Introduction of the new 'maxdenybanners' directive. 
     30# 
    2431# Revision 1.99  2005/01/24 17:44:17  jalet 
    2532# Same fix for group print quota entries wrt LDAP performance 
     
    647654        """Extracts user information given its name.""" 
    648655        user = StorageUser(self, username) 
    649         result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"]], base=self.info["userbase"]) 
     656        result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "pykotaOverCharge"], base=self.info["userbase"]) 
    650657        if result : 
    651658            fields = result[0][1] 
    652659            user.ident = result[0][0] 
    653660            user.Name = fields.get("pykotaUserName", [username])[0]  
    654             user.Email = fields.get(self.info["usermail"]) 
    655             if user.Email is not None : 
    656                 user.Email = user.Email[0] 
    657             user.LimitBy = fields.get("pykotaLimitBy") 
    658             if user.LimitBy is not None : 
    659                 user.LimitBy = user.LimitBy[0] 
    660             else :     
    661                 user.LimitBy = "quota" 
     661            user.Email = fields.get(self.info["usermail"], [None])[0] 
     662            user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 
     663            user.OverCharge = float(fields.get("pykotaOverCharge", [1.0])[0]) 
    662664            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"]) 
    663665            if not result : 
     
    695697            group.ident = result[0][0] 
    696698            group.Name = fields.get("pykotaGroupName", [groupname])[0]  
    697             group.LimitBy = fields.get("pykotaLimitBy") 
    698             if group.LimitBy is not None : 
    699                 group.LimitBy = group.LimitBy[0] 
    700             else :     
    701                 group.LimitBy = "quota" 
     699            group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 
    702700            group.AccountBalance = 0.0 
    703701            group.LifeTimePaid = 0.0 
     
    717715            printer.ident = result[0][0] 
    718716            printer.Name = fields.get("pykotaPrinterName", [printername])[0]  
    719             printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0] or 0.0) 
    720             printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
     717            printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 
     718            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) 
    721719            printer.uniqueMember = fields.get("uniqueMember", []) 
    722720            printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0])  
     
    732730            else :     
    733731                base = self.info["userquotabase"] 
    734             result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=base) 
     732            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 
    735733            if result : 
    736734                fields = result[0][1] 
    737735                userpquota.ident = result[0][0] 
    738                 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0) 
    739                 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0) 
     736                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 
     737                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0]) 
     738                userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0]) 
    740739                userpquota.SoftLimit = fields.get("pykotaSoftLimit") 
    741740                if userpquota.SoftLimit is not None : 
     
    815814            result = None 
    816815            try : 
    817                 result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 
     816                result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "pykotaBillingCode", "pykotaPages", "pykotaMD5Sum", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 
    818817            except PyKotaStorageError :     
    819818                pass # Last job entry exists, but job probably doesn't exist anymore.  
     
    823822                lastjob.JobId = fields.get("pykotaJobId")[0] 
    824823                lastjob.UserName = fields.get("pykotaUserName")[0] 
    825                 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0] or 0) 
     824                lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 
    826825                try : 
    827826                    lastjob.JobSize = int(fields.get("pykotaJobSize", [0])[0]) 
     
    839838                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
    840839                lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
     840                lastjob.JobBillingCode = fields.get("pykotaMD5Sum", [None])[0] 
     841                lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 
     842                lastjob.JobPages = fields.get("pykotaPages", [""])[0] 
    841843                date = fields.get("createTimestamp", ["19700101000000"])[0] 
    842844                year = int(date[:4]) 
     
    924926        else : 
    925927           base = self.info["userquotabase"] 
    926         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=base) 
     928        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 
    927929        if result : 
    928930            for (userquotaid, fields) in result : 
     
    930932                userpquota = StorageUserPQuota(self, user, printer) 
    931933                userpquota.ident = userquotaid 
    932                 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0) 
    933                 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0) 
     934                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 
     935                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0]) 
     936                userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0]) 
    934937                userpquota.SoftLimit = fields.get("pykotaSoftLimit") 
    935938                if userpquota.SoftLimit is not None : 
     
    990993                       "pykotaUserName" : user.Name, 
    991994                       "pykotaLimitBy" : (user.LimitBy or "quota"), 
     995                       "pykotaOverCharge" : str(user.OverCharge), 
    992996                    }    
    993997                        
     
    10481052        newfields = {  
    10491053                      "pykotaGroupName" : group.Name, 
    1050                       "pykotaLimitBY" : (group.LimitBy or "quota"), 
     1054                      "pykotaLimitBy" : (group.LimitBy or "quota"), 
    10511055                    }  
    10521056        mustadd = 1 
     
    11021106                   "pykotaPageCounter" : "0", 
    11031107                   "pykotaLifePageCounter" : "0", 
     1108                   "pykotaWarnCount" : "0", 
    11041109                 }  
    11051110        if self.info["userquotabase"].lower() == "user" : 
     
    11411146        self.doModify(printer.ident, fields) 
    11421147         
     1148    def writeUserOverCharge(self, user, factor) : 
     1149        """Sets the user's overcharging coefficient.""" 
     1150        fields = { 
     1151                   "pykotaOverCharge" : str(factor), 
     1152                 } 
     1153        self.doModify(user.ident, fields) 
     1154         
    11431155    def writeUserLimitBy(self, user, limitby) :     
    11441156        """Sets the user's limiting factor.""" 
     
    11831195                   "pykotaLifePageCounter" : str(newlifepagecounter), 
    11841196                   "pykotaDateLimit" : None, 
     1197                   "pykotaWarnCount" : "0", 
    11851198                 }   
    11861199        return self.doModify(userpquota.ident, fields)          
     
    12461259                   "pykotaHostName" : str(clienthost),  
    12471260                   "pykotaJobSizeBytes" : str(jobsizebytes), 
     1261                   # TODO : add the 3 missing fields 
    12481262                 } 
    12491263        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    12781292                   "pykotaHardLimit" : str(hardlimit), 
    12791293                   "pykotaDateLimit" : "None", 
     1294                   "pykotaWarnCount" : "0", 
    12801295                 } 
    12811296        self.doModify(userpquota.ident, fields) 
     1297         
     1298    def writeUserPQuotaWarnCount(self, userpquota, warncount) : 
     1299        """Sets the warn counter value for a user quota.""" 
     1300        fields = {  
     1301                   "pykotaWarnCount" : str(warncount or 0), 
     1302                 } 
     1303        self.doModify(userpquota.ident, fields) 
     1304         
     1305    def increaseUserPQuotaWarnCount(self, userpquota) : 
     1306        """Increases the warn counter value for a user quota.""" 
     1307        fields = { 
     1308                   "pykotaWarnCount" : { "operator" : "+", "value" : 1, "convert" : int }, 
     1309                 } 
     1310        return self.doModify(userpquota.ident, fields)          
    12821311         
    12831312    def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :