Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 2042)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 2054)
@@ -22,4 +22,11 @@
 #
 # $Log$
+# Revision 1.100  2005/02/13 22:02:29  jalet
+# 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.
+#
 # Revision 1.99  2005/01/24 17:44:17  jalet
 # Same fix for group print quota entries wrt LDAP performance
@@ -647,17 +654,12 @@
         """Extracts user information given its name."""
         user = StorageUser(self, username)
-        result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"]], base=self.info["userbase"])
+        result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "pykotaOverCharge"], base=self.info["userbase"])
         if result :
             fields = result[0][1]
             user.ident = result[0][0]
             user.Name = fields.get("pykotaUserName", [username])[0] 
-            user.Email = fields.get(self.info["usermail"])
-            if user.Email is not None :
-                user.Email = user.Email[0]
-            user.LimitBy = fields.get("pykotaLimitBy")
-            if user.LimitBy is not None :
-                user.LimitBy = user.LimitBy[0]
-            else :    
-                user.LimitBy = "quota"
+            user.Email = fields.get(self.info["usermail"], [None])[0]
+            user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0]
+            user.OverCharge = float(fields.get("pykotaOverCharge", [1.0])[0])
             result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"])
             if not result :
@@ -695,9 +697,5 @@
             group.ident = result[0][0]
             group.Name = fields.get("pykotaGroupName", [groupname])[0] 
-            group.LimitBy = fields.get("pykotaLimitBy")
-            if group.LimitBy is not None :
-                group.LimitBy = group.LimitBy[0]
-            else :    
-                group.LimitBy = "quota"
+            group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0]
             group.AccountBalance = 0.0
             group.LifeTimePaid = 0.0
@@ -717,6 +715,6 @@
             printer.ident = result[0][0]
             printer.Name = fields.get("pykotaPrinterName", [printername])[0] 
-            printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0] or 0.0)
-            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0)
+            printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0])
+            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0])
             printer.uniqueMember = fields.get("uniqueMember", [])
             printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) 
@@ -732,10 +730,11 @@
             else :    
                 base = self.info["userquotabase"]
-            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=base)
+            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base)
             if result :
                 fields = result[0][1]
                 userpquota.ident = result[0][0]
-                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0)
-                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0)
+                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0])
+                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0])
+                userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0])
                 userpquota.SoftLimit = fields.get("pykotaSoftLimit")
                 if userpquota.SoftLimit is not None :
@@ -815,5 +814,5 @@
             result = None
             try :
-                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)
+                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)
             except PyKotaStorageError :    
                 pass # Last job entry exists, but job probably doesn't exist anymore. 
@@ -823,5 +822,5 @@
                 lastjob.JobId = fields.get("pykotaJobId")[0]
                 lastjob.UserName = fields.get("pykotaUserName")[0]
-                lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0] or 0)
+                lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0])
                 try :
                     lastjob.JobSize = int(fields.get("pykotaJobSize", [0])[0])
@@ -839,4 +838,7 @@
                 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0]
                 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0]
+                lastjob.JobBillingCode = fields.get("pykotaMD5Sum", [None])[0]
+                lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0]
+                lastjob.JobPages = fields.get("pykotaPages", [""])[0]
                 date = fields.get("createTimestamp", ["19700101000000"])[0]
                 year = int(date[:4])
@@ -924,5 +926,5 @@
         else :
            base = self.info["userquotabase"]
-        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)
+        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)
         if result :
             for (userquotaid, fields) in result :
@@ -930,6 +932,7 @@
                 userpquota = StorageUserPQuota(self, user, printer)
                 userpquota.ident = userquotaid
-                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0)
-                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0)
+                userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0])
+                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0])
+                userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0])
                 userpquota.SoftLimit = fields.get("pykotaSoftLimit")
                 if userpquota.SoftLimit is not None :
@@ -990,4 +993,5 @@
                        "pykotaUserName" : user.Name,
                        "pykotaLimitBy" : (user.LimitBy or "quota"),
+                       "pykotaOverCharge" : str(user.OverCharge),
                     }   
                        
@@ -1048,5 +1052,5 @@
         newfields = { 
                       "pykotaGroupName" : group.Name,
-                      "pykotaLimitBY" : (group.LimitBy or "quota"),
+                      "pykotaLimitBy" : (group.LimitBy or "quota"),
                     } 
         mustadd = 1
@@ -1102,4 +1106,5 @@
                    "pykotaPageCounter" : "0",
                    "pykotaLifePageCounter" : "0",
+                   "pykotaWarnCount" : "0",
                  } 
         if self.info["userquotabase"].lower() == "user" :
@@ -1141,4 +1146,11 @@
         self.doModify(printer.ident, fields)
         
+    def writeUserOverCharge(self, user, factor) :
+        """Sets the user's overcharging coefficient."""
+        fields = {
+                   "pykotaOverCharge" : str(factor),
+                 }
+        self.doModify(user.ident, fields)
+        
     def writeUserLimitBy(self, user, limitby) :    
         """Sets the user's limiting factor."""
@@ -1183,4 +1195,5 @@
                    "pykotaLifePageCounter" : str(newlifepagecounter),
                    "pykotaDateLimit" : None,
+                   "pykotaWarnCount" : "0",
                  }  
         return self.doModify(userpquota.ident, fields)         
@@ -1246,4 +1259,5 @@
                    "pykotaHostName" : str(clienthost), 
                    "pykotaJobSizeBytes" : str(jobsizebytes),
+                   # TODO : add the 3 missing fields
                  }
         if (not self.disablehistory) or (not printer.LastJob.Exists) :
@@ -1278,6 +1292,21 @@
                    "pykotaHardLimit" : str(hardlimit),
                    "pykotaDateLimit" : "None",
+                   "pykotaWarnCount" : "0",
                  }
         self.doModify(userpquota.ident, fields)
+        
+    def writeUserPQuotaWarnCount(self, userpquota, warncount) :
+        """Sets the warn counter value for a user quota."""
+        fields = { 
+                   "pykotaWarnCount" : str(warncount or 0),
+                 }
+        self.doModify(userpquota.ident, fields)
+        
+    def increaseUserPQuotaWarnCount(self, userpquota) :
+        """Increases the warn counter value for a user quota."""
+        fields = {
+                   "pykotaWarnCount" : { "operator" : "+", "value" : 1, "convert" : int },
+                 }
+        return self.doModify(userpquota.ident, fields)         
         
     def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :
