Show
Ignore:
Timestamp:
05/23/06 23:28:39 (18 years ago)
Author:
jerome
Message:

Introduced the 'askconfirmation' directive in pykota.conf

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2891 r2895  
    371371        self.logdebug("Job's attributes sanitizing done.") 
    372372                 
     373    def didUserConfirm(self) : 
     374        """Asks for user confirmation through an external script. 
     375         
     376           returns False if the end user wants to cancel the job, else True. 
     377        """ 
     378        self.logdebug("Checking if we have to ask for user's confirmation...") 
     379        answer = None                          
     380        confirmationcommand = self.config.getAskConfirmation(self.PrinterName) 
     381        if confirmationcommand : 
     382            self.logdebug("Launching subprocess [%s] to ask for user confirmation." \ 
     383                                     % confirmationcommand) 
     384            inputfile = os.popen(confirmationcommand, "r") 
     385            try : 
     386                for answer in inputfile.xreadlines() : 
     387                    answer = answer.strip().upper() 
     388                    if answer == "CANCEL" : 
     389                        break 
     390            except IOError, msg :             
     391                self.logdebug("IOError while reading subprocess' output : %s" % msg) 
     392            inputfile.close()     
     393            self.logdebug("User's confirmation received : %s" % (((answer == "CANCEL") and "CANCEL") or "CONTINUE")) 
     394        else :     
     395            self.logdebug("No need to ask for user's confirmation, job processing will continue.") 
     396        return (answer != "CANCEL")     
     397         
    373398    def overwriteJobTicket(self) :     
    374399        """Should we overwrite the job's ticket (username and billingcode) ?""" 
    375400        self.logdebug("Checking if we need to overwrite the job ticket...") 
    376401        jobticketcommand = self.config.getOverwriteJobTicket(self.PrinterName) 
    377         if jobticketcommand is not None : 
     402        if jobticketcommand : 
    378403            username = billingcode = action = None 
    379404            self.logdebug("Launching subprocess [%s] to overwrite the job ticket." \ 
     
    10201045         
    10211046        if self.Action not in ("DENY", "CANCEL") :  
     1047            if not self.didUserConfirm() : 
     1048                self.Action = "CANCEL" 
     1049                self.Reason = _("Print job cancelled.") 
     1050                os.environ["PYKOTASTATUS"] = "CANCELLED" 
     1051                 
     1052        if self.Action not in ("DENY", "CANCEL") :  
    10221053            if self.Printer.MaxJobSize and (self.softwareJobSize > self.Printer.MaxJobSize) : 
    10231054                # This printer was set to refuse jobs this large.