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/sql.py

    r2030 r2054  
    2222# 
    2323# $Log$ 
     24# Revision 1.65  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.64  2005/01/18 19:47:50  jalet 
    2532# Big bug fix wrt the datelimit attribute 
     
    273280            user.LifeTimePaid = fields.get("lifetimepaid") 
    274281            user.Email = fields.get("email") 
     282            user.OverCharge = fields.get("overcharge", 1.0) 
    275283            user.Exists = 1 
    276284        return user 
     
    317325                userpquota.HardLimit = fields.get("hardlimit") 
    318326                userpquota.DateLimit = fields.get("datelimit") 
     327                userpquota.WarnCount = fields.get("warncount") 
    319328                userpquota.Exists = 1 
    320329        return userpquota 
     
    359368            lastjob.JobHostName = fields.get("hostname") 
    360369            lastjob.JobSizeBytes = fields.get("jobsizebytes") 
     370            lastjob.JobMD5Sum = fields.get("md5sum") 
     371            lastjob.JobPages = fields.get("pages") 
     372            lastjob.JobBillingCode = fields.get("billingcode") 
    361373            lastjob.Exists = 1 
    362374        return lastjob 
     
    374386                user.LifeTimePaid = record.get("lifetimepaid") 
    375387                user.Email = record.get("email") 
     388                user.OverCharge = record.get("overcharge") 
    376389                user.Exists = 1 
    377390                groupmembers.append(user) 
     
    423436        """Returns the list of users who uses a given printer, along with their quotas.""" 
    424437        usersandquotas = [] 
    425         result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident)) 
     438        result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,overcharge,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit,warncount FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident)) 
    426439        if result : 
    427440            for record in result : 
     
    433446                    user.LifeTimePaid = record.get("lifetimepaid") 
    434447                    user.Email = record.get("email")  
     448                    user.OverCharge = record.get("overcharge") 
    435449                    user.Exists = 1 
    436450                    userpquota = StorageUserPQuota(self, user, printer) 
     
    441455                    userpquota.HardLimit = record.get("hardlimit") 
    442456                    userpquota.DateLimit = record.get("datelimit") 
     457                    userpquota.WarnCount = record.get("warncount") 
    443458                    userpquota.Exists = 1 
    444459                    usersandquotas.append((user, userpquota)) 
     
    466481    def addUser(self, user) :         
    467482        """Adds a user to the quota storage, returns its id.""" 
    468         self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email))) 
     483        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 
    469484        return self.getUser(user.Name) 
    470485         
     
    503518        self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 
    504519         
     520    def writeUserOverCharge(self, user, factor) : 
     521        """Sets the user's overcharging coefficient.""" 
     522        self.doModify("UPDATE users SET overcharge=%s WHERE id=%s" % (self.doQuote(factor), self.doQuote(user.ident))) 
     523         
    505524    def writeUserLimitBy(self, user, limitby) :     
    506525        """Sets the user's limiting factor.""" 
     
    521540    def increaseUserPQuotaPagesCounters(self, userpquota, nbpages) :     
    522541        """Increase page counters for a user print quota.""" 
    523         self.doModify("UPDATE userpquota SET pagecounter=pagecounter+%s,lifepagecounter=lifepagecounter+%s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident))) 
     542        self.doModify("UPDATE userpquota SET pagecounter=pagecounter + %s,lifepagecounter=lifepagecounter + %s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident))) 
    524543        
    525544    def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :     
    526545        """Sets the new page counters permanently for a user print quota.""" 
    527         self.doModify("UPDATE userpquota SET pagecounter=%s, lifepagecounter=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 
     546        self.doModify("UPDATE userpquota SET pagecounter=%s, lifepagecounter=%s, warncount=0, datelimit=NULL WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 
    528547        
    529548    def decreaseUserAccountBalance(self, user, amount) :     
    530549        """Decreases user's account balance from an amount.""" 
    531         self.doModify("UPDATE users SET balance=balance-%s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident))) 
     550        self.doModify("UPDATE users SET balance=balance - %s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident))) 
    532551        
    533552    def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :     
     
    565584    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 
    566585        """Sets soft and hard limits for a user quota.""" 
    567         self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident))) 
     586        self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, warncount=0, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident))) 
     587         
     588    def writeUserPQuotaWarnCount(self, userpquota, warncount) : 
     589        """Sets the warn counter value for a user quota.""" 
     590        self.doModify("UPDATE userpquota SET warncount=%s WHERE id=%s" % (self.doQuote(warncount), self.doQuote(userpquota.ident))) 
     591         
     592    def increaseUserPQuotaWarnCount(self, userpquota) : 
     593        """Increases the warn counter value for a user quota.""" 
     594        self.doModify("UPDATE userpquota SET warncount=warncount+1 WHERE id=%s" % self.doQuote(userpquota.ident)) 
    568595         
    569596    def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) : 
     
    620647                job.JobHostName = fields.get("hostname") 
    621648                job.JobSizeBytes = fields.get("jobsizebytes") 
     649                job.JobMD5Sum = fields.get("md5sum") 
     650                job.JobPages = fields.get("pages") 
     651                job.JobBillingCode = fields.get("billingcode") 
    622652                job.UserName = fields.get("username") 
    623653                job.PrinterName = fields.get("printername")