Changeset 2895

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

Introduced the 'askconfirmation' directive in pykota.conf

Location:
pykota/trunk
Files:
4 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. 
  • pykota/trunk/conf/pykota.conf.sample

    r2884 r2895  
    459459#    CANCEL 
    460460# 
    461 # NB : the output is entirely read, and the latest value 
    462 # seen is used, so you command can output several usernames 
     461# NB : the output of your command is entirely read, and the latest  
     462# value seen is used, so you command can output several usernames 
    463463# or billing codes and only the latest ones will be used. 
    464464# If only USERNAME= lines are printed, the billing code, 
     
    475475# overwrite_jobticket : /usr/bin/pknotify --destination $PYKOTAJOBORIGINATINGHOSTNAME:7654 --timeout 180 --denyafter 3 --checkauth --ask "Username:username:$PYKOTAUSERNAME" "Password:password:" 
    476476# overwrite_jobticket : /path/to/some/script/or/command 
     477 
     478 
     479 
     480# Should we ask the end user for a confirmation about their print job ? 
     481# 
     482# Any script can be launched here. If your script prints CANCEL on 
     483# its standard output, the job is cancelled, else processing of the 
     484# job continues to next step. 
     485# 
     486# NB : the output of your command is read until CANCEL is found 
     487# or all lines have been read. 
     488# 
     489# This value can be set either globally or on a per printer basis 
     490# If both are defined, the printer option has priority. 
     491# 
     492# examples : 
     493# 
     494# askconfirmation : /usr/bin/pknotify --destination $PYKOTAJOBORIGINATINGHOSTNAME:7654 --timeout 120 --confirm "Hello $PYKOTAUSERNAME.\nPrint job $PYKOTAJOBID send to printer $PYKOTAPRINTERNAME is $PYKOTAPRECOMPUTEDJOBSIZE pages long\nand will cost you $PYKOTAPRECOMPUTEDJOBPRICE credits.\n\nYou currently have $PYKOTABALANCE credits.\n\nDo you really want to print ?" 
    477495 
    478496 
  • pykota/trunk/NEWS

    r2891 r2895  
    2424    - 1.25alpha4 (2006-05-22) : 
    2525     
     26        - Introduced the 'askconfirmation' directive to interact with 
     27          the end user through any script (pknotify is recommended) 
     28          and see if he really wants to print when knowing the cost 
     29          of the job. 
     30           
    2631        - Now uses pkipplib if present to directly retrieve the job 
    2732          information from the CUPS server over IPP. 
  • pykota/trunk/pykota/config.py

    r2759 r2895  
    249249            return      # No prefix to strip off 
    250250             
     251    def getAskConfirmation(self, printername) :         
     252        """Returns the askconfirmation directive's content, or None if unset.""" 
     253        try : 
     254            return self.getPrinterOption(printername, "askconfirmation").strip() 
     255        except PyKotaConfigError :     
     256            return      # No overwriting will be done 
     257             
    251258    def getOverwriteJobTicket(self, printername) :         
    252259        """Returns the overwrite_jobticket directive's content, or None if unset."""