Changeset 2388

Show
Ignore:
Timestamp:
07/27/05 15:17:28 (19 years ago)
Author:
jerome
Message:

Fixed an LDAP filtering problem when several billing codes were passed on pkbcodes' command line.
The unknown_billingcode directive now works as expected.
The billing code's page counter and balance are updated when printing.
Severity : If you need full management of billing codes, this is for you.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2314 r2388  
    220220                (chtype, clienthost) = ippmessage.operation_attributes.get("job-originating-host-name", \ 
    221221                                          ippmessage.job_attributes.get("job-originating-host-name", (None, None))) 
    222                 (jbtype, billingcode) = ippmessage.job_attributes.get("job-billing", (None, None)) 
     222                (jbtype, bcode) = ippmessage.job_attributes.get("job-billing", (None, None)) 
    223223            except AttributeError :     
    224224                clienthost = None 
    225                 billingcode = None 
     225                bcode = None 
    226226            if clienthost is None : 
    227                 (billingcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 
     227                (bcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 
    228228            self.logdebug("Client Hostname : %s" % (clienthost or "Unknown"))     
    229             self.logdebug("Billing Code : %s" % (billingcode or "None"))     
     229            self.logdebug("Billing Code : %s" % (bcode or "None"))     
    230230             
    231231            os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = str(clienthost or "") 
    232             os.environ["PYKOTAJOBBILLING"] = str(billingcode or "") 
     232            os.environ["PYKOTAJOBBILLING"] = str(bcode or "") 
    233233             
    234234            # enters first phase 
     
    269269                    else :     
    270270                        self.printMoreInfo(user, printer, _("Job is a duplicate. Printing is allowed by subprocess."), "warn") 
    271                         action = "ALLOW" # just to be sure, in the case the external command returns something else... 
     271                        action = self.warnUserPQuota(userpquota) 
    272272            else :     
    273273                # checks the user's quota 
    274274                action = self.warnUserPQuota(userpquota) 
     275             
     276            # Now handle the billing code 
     277            if bcode is not None : 
     278                billingcode = self.storage.getBillingCode(bcode) 
     279                if billingcode.Exists : 
     280                    self.logdebug("Billing code [%s] exists in database." % bcode) 
     281                else : 
     282                    msg = "Unknown billing code [%s] : " % bcode 
     283                    (newaction, script) = self.config.getUnknownBillingCode(printer.Name) 
     284                    if newaction == "CREATE" : 
     285                        self.logdebug(msg + "will be created.") 
     286                        billingcode = self.storage.addBillingCode(bcode) 
     287                        if billingcode.Exists : 
     288                            self.logdebug(msg + "has been created.") 
     289                        else :     
     290                            self.printInfo(msg + "couldn't be created.", "error") 
     291                    else :     
     292                        self.logdebug(msg + "job will be denied.") 
     293                        action = newaction 
     294                        if script is not None :  
     295                            self.logdebug(msg + "launching subprocess [%s] to notify user." % script) 
     296                            os.system(script) 
     297            else :     
     298                billingcode = None 
    275299             
    276300            # exports some new environment variables 
     
    386410                                    action, jobsize, jobprice, self.preserveinputfile, \ 
    387411                                    self.title, self.copies, self.options, clienthost, \ 
    388                                     self.jobSizeBytes, self.checksum, None, billingcode) 
     412                                    self.jobSizeBytes, self.checksum, None, bcode) 
    389413            self.printMoreInfo(user, printer, _("Job added to history.")) 
    390414             
     415            if billingcode and billingcode.Exists : 
     416                billingcode.consume(jobsize, jobprice) 
     417                self.printMoreInfo(user, printer, _("Billing code %s was updated.") % billingcode.BillingCode) 
     418                 
    391419            # exports some new environment variables 
    392420            os.environ["PYKOTAJOBSIZE"] = str(jobsize) 
  • pykota/trunk/pykota/storage.py

    r2342 r2388  
    304304                    upq.PageCounter = int(upq.PageCounter or 0) + jobsize 
    305305                    upq.LifePageCounter = int(upq.LifePageCounter or 0) + jobsize 
    306                 # TODO : consume from the billing code as well 
    307306            except PyKotaStorageError, msg :     
    308307                self.parent.rollbackTransaction() 
     
    433432    def reset(self, balance=0.0, pagecounter=0) :     
    434433        """Resets the pagecounter and balance for this billing code.""" 
    435         self.parent.setBillingCodeValues(self, balance, pagecounter) 
     434        self.parent.setBillingCodeValues(self, pagecounter, balance) 
    436435        self.Balance = balance 
    437436        self.PageCounter = pagecounter 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2386 r2388  
    14201420        """Returns the list of all billing codes which match a certain pattern.""" 
    14211421        codes = [] 
    1422         result = self.doSearch("(&(objectClass=pykotaBilling)%s)" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \ 
     1422        result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \ 
    14231423                                ["pykotaBillingCode", "description", "pykotaPageCounter", "pykotaBalance"], \ 
    14241424                                base=self.info["billingcodebase"]) 
     
    14371437        return codes         
    14381438         
    1439     def setBillingCodeValues(self, code, newbalance, newpagecounter) :     
     1439    def setBillingCodeValues(self, code, newpagecounter, newbalance) : 
    14401440        """Sets the new page counter and balance for a billing code.""" 
    14411441        fields = { 
     
    14451445        return self.doModify(code.ident, fields)          
    14461446        
    1447     def consumeBillingCode(self, code, balance, pagecounter) : 
     1447    def consumeBillingCode(self, code, pagecounter, balance) : 
    14481448        """Consumes from a billing code.""" 
    14491449        fields = { 
  • pykota/trunk/pykota/storages/sql.py

    r2374 r2388  
    495495        self.doModify("UPDATE billingcodes SET description=%s WHERE id=%s" % (self.doQuote(self.userCharsetToDatabase(code.Description or "")), self.doQuote(code.ident))) 
    496496        
    497     def setBillingCodeValues(self, code, newbalance, newpagecounter) :     
     497    def setBillingCodeValues(self, code, newpagecounter, newbalance) :     
    498498        """Sets the new page counter and balance for a billing code.""" 
    499499        self.doModify("UPDATE billingcodes SET balance=%s, pagecounter=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newpagecounter), self.doQuote(code.ident))) 
    500500        
    501     def consumeBillingCode(self, code, balance, pagecounter) : 
     501    def consumeBillingCode(self, code, pagecounter, balance) : 
    502502        """Consumes from a billing code.""" 
    503503        self.doModify("UPDATE billingcodes SET balance=balance + %s, pagecounter=pagecounter + %s WHERE id=%s" % (self.doQuote(balance), self.doQuote(pagecounter), self.doQuote(code.ident)))