Changeset 1680

Show
Ignore:
Timestamp:
08/26/04 00:34:39 (20 years ago)
Author:
jalet
Message:

Now both software and hardware accounting raise an exception when no valid
result can be extracted from the subprocess' output.
Hardware accounting now reads subprocess' output until an integer is read
or data is exhausted : it now behaves just like software accounting in this
aspect.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r1678 r1680  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha3 : 
     25        
     26        - Now hardware accounting method works like software 
     27          accounting method wrt the subprocess' output. 
     28           
    2429    - 1.20alpha2 : 
    2530     
  • pykota/trunk/pykota/accounters/hardware.py

    r1624 r1680  
    2222# 
    2323# $Log$ 
     24# Revision 1.9  2004/08/25 22:34:39  jalet 
     25# Now both software and hardware accounting raise an exception when no valid 
     26# result can be extracted from the subprocess' output. 
     27# Hardware accounting now reads subprocess' output until an integer is read 
     28# or data is exhausted : it now behaves just like software accounting in this 
     29# aspect. 
     30# 
    2431# Revision 1.8  2004/07/22 22:41:48  jalet 
    2532# Hardware accounting for LPRng should be OK now. UNTESTED. 
     
    122129            raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.printername) 
    123130        self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 
    124         error = 1 
    125131        pagecounter = None 
    126132        child = popen2.Popen4(commandline)     
    127133        try : 
    128             line = child.fromchild.readline() 
    129             pagecounter = int(line.strip()) 
    130         except ValueError :     
    131             self.filter.printInfo(_("Incorrect answer : %s") % repr(line), "error") 
     134            answer = child.fromchild.read() 
    132135        except IOError :     
    133136            # we were interrupted by a signal, certainely a SIGTERM 
     
    139142            self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 
    140143        else :     
    141             error = 0 
     144            lines = [l.strip() for l in answer.split("\n")] 
     145            for i in range(len(lines)) :  
     146                try : 
     147                    pagecounter = int(lines[i]) 
     148                except (AttributeError, ValueError) : 
     149                    self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 
     150                else :     
     151                    break 
    142152        child.fromchild.close()     
    143153        child.tochild.close() 
     
    146156        except OSError, msg :     
    147157            self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 
    148             error = 1 
    149         if (not error) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 
     158        if (pagecounter is not None) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 
    150159            return pagecounter 
    151160        else :     
  • pykota/trunk/pykota/accounters/software.py

    r1678 r1680  
    2222# 
    2323# $Log$ 
     24# Revision 1.9  2004/08/25 22:34:39  jalet 
     25# Now both software and hardware accounting raise an exception when no valid 
     26# result can be extracted from the subprocess' output. 
     27# Hardware accounting now reads subprocess' output until an integer is read 
     28# or data is exhausted : it now behaves just like software accounting in this 
     29# aspect. 
     30# 
    2431# Revision 1.8  2004/08/22 14:04:47  jalet 
    2532# Tries to fix problem with subprocesses outputting more datas than needed 
     
    7481            self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) 
    7582         
    76         pagecount = 0 
     83        pagecounter = None 
    7784        try : 
    7885            answer = child.fromchild.read() 
     
    8491            for i in range(len(lines)) :  
    8592                try : 
    86                     pagecount = int(lines[i]) 
     93                    pagecounter = int(lines[i]) 
    8794                except (AttributeError, ValueError) : 
    88                     self.filter.printInfo(_("Unable to compute job size with accounter %s") % self.arguments) 
    89                     self.filter.printInfo(_("Line skipped in accounter's output. Trying again...")) 
     95                    self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 
    9096                else :     
    9197                    break 
     
    102108                status = retcode 
    103109            self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) 
    104         self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecount)) 
    105         return pagecount     
    106110             
     111        if pagecounter is None :     
     112            raise PyKotaAccounterError, _("Unable to compute job size with accounter %s") % self.arguments 
     113             
     114        self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecounter)) 
     115        return pagecounter     
     116             
  • pykota/trunk/pykota/version.py

    r1676 r1680  
    2222# 
    2323 
    24 __version__ = "1.20alpha2_unofficial" 
     24__version__ = "1.20alpha3_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""