Show
Ignore:
Timestamp:
09/23/04 21:18:12 (20 years ago)
Author:
jalet
Message:

Now loops when the external hardware accounter fails, until it returns a correct value

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/hardware.py

    r1737 r1739  
    2222# 
    2323# $Log$ 
     24# Revision 1.23  2004/09/23 19:18:12  jalet 
     25# Now loops when the external hardware accounter fails, until it returns a correct value 
     26# 
    2427# Revision 1.22  2004/09/22 19:48:01  jalet 
    2528# Logs the looping message as debug instead of as info 
     
    179182                    break 
    180183                # In reality, and if I'm not mistaken, we will NEVER get there.     
    181                 self.parent.filter.logdebug(_("Waiting for printer to be idle or printing..."))     
     184                self.parent.filter.logdebug(_("Waiting for printer %s to be idle or printing...") % self.parent.filter.printername)     
    182185                time.sleep(SNMPDELAY) 
    183186             
     
    198201                else :     
    199202                    idle_num = 0 
    200                 self.parent.filter.logdebug(_("Waiting for printer's idle status to stabilize..."))     
     203                self.parent.filter.logdebug(_("Waiting for printer %s's idle status to stabilize...") % self.parent.filter.printername)     
    201204                time.sleep(SNMPDELAY) 
    202205     
     
    209212    def getPrinterInternalPageCounter(self) :     
    210213        """Returns the printer's internal page counter.""" 
    211         self.filter.logdebug("Reading printer's internal page counter...") 
     214        self.filter.logdebug("Reading printer %s's internal page counter..." % self.filter.printername) 
    212215        counter = self.askPrinterPageCounter(self.filter.printerhostname) 
    213         self.filter.logdebug("Printer's internal page counter value is : %s" % str(counter)) 
     216        self.filter.logdebug("Printer %s's internal page counter value is : %s" % (self.filter.printername, str(counter))) 
    214217        return counter     
    215218         
     
    289292        if printer is None : 
    290293            raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.printername) 
    291         self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 
    292         pagecounter = None 
    293         child = popen2.Popen4(commandline)     
    294         try : 
    295             answer = child.fromchild.read() 
    296         except IOError :     
    297             # we were interrupted by a signal, certainely a SIGTERM 
    298             # caused by the user cancelling the current job 
     294        while 1 :     
     295            self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 
     296            pagecounter = None 
     297            child = popen2.Popen4(commandline)     
    299298            try : 
    300                 os.kill(child.pid, signal.SIGTERM) 
    301             except :     
    302                 pass # already killed ? 
    303             self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 
    304         else :     
    305             lines = [l.strip() for l in answer.split("\n")] 
    306             for i in range(len(lines)) :  
     299                answer = child.fromchild.read() 
     300            except IOError :     
     301                # we were interrupted by a signal, certainely a SIGTERM 
     302                # caused by the user cancelling the current job 
    307303                try : 
    308                     pagecounter = int(lines[i]) 
    309                 except (AttributeError, ValueError) : 
    310                     self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 
    311                 else :     
    312                     break 
    313         child.fromchild.close()     
    314         child.tochild.close() 
    315         try : 
    316             status = child.wait() 
    317         except OSError, msg :     
    318             self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 
    319         else :     
    320             if os.WIFEXITED(status) : 
    321                 status = os.WEXITSTATUS(status) 
    322             self.filter.printInfo(_("Hardware accounter %s exit code is %s") % (self.arguments, str(status))) 
    323              
    324         if pagecounter is None : 
    325             message = _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline) 
    326             if self.onerror == "CONTINUE" : 
    327                 self.filter.printInfo(message, "error") 
    328             else : 
    329                 raise PyKotaAccounterError, message  
    330         return pagecounter         
     304                    os.kill(child.pid, signal.SIGTERM) 
     305                except :     
     306                    pass # already killed ? 
     307                self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 
     308            else :     
     309                lines = [l.strip() for l in answer.split("\n")] 
     310                for i in range(len(lines)) :  
     311                    try : 
     312                        pagecounter = int(lines[i]) 
     313                    except (AttributeError, ValueError) : 
     314                        self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 
     315                    else :     
     316                        break 
     317            child.fromchild.close()     
     318            child.tochild.close() 
     319            try : 
     320                status = child.wait() 
     321            except OSError, msg :     
     322                self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 
     323            else :     
     324                if os.WIFEXITED(status) : 
     325                    status = os.WEXITSTATUS(status) 
     326                self.filter.printInfo(_("Hardware accounter %s exit code is %s") % (self.arguments, str(status))) 
     327                 
     328            if pagecounter is None : 
     329                message = _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline) 
     330                if self.onerror == "CONTINUE" : 
     331                    self.filter.printInfo(message, "error") 
     332                else : 
     333                    raise PyKotaAccounterError, message  
     334            else :         
     335                return pagecounter         
    331336         
    332337    def askWithSNMP(self, printer) : 
     
    343348                raise 
    344349            else :     
    345                 self.filter.printInfo(_("SNMP querying stage interrupted. Using latest value seen for internal page counter (%s).") % acc.printerInternalPageCounter, "warn") 
     350                self.filter.printInfo(_("SNMP querying stage interrupted. Using latest value seen for internal page counter (%s) on printer %s.") % (acc.printerInternalPageCounter, self.filter.printername), "warn") 
    346351        return acc.printerInternalPageCounter