Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

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

    r3411 r3413  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3636        AccounterBase.__init__(self, kotabackend, arguments, ispreaccounter, name) 
    3737        self.isSoftware = 0 
    38          
    39     def getPrinterInternalPageCounter(self) :     
     38 
     39    def getPrinterInternalPageCounter(self) : 
    4040        """Returns the printer's internal page counter.""" 
    4141        self.filter.logdebug("Reading printer %s's internal page counter..." % self.filter.PrinterName) 
    4242        counter = self.askPrinterPageCounter(self.filter.PrinterHostName) 
    4343        self.filter.logdebug("Printer %s's internal page counter value is : %s" % (self.filter.PrinterName, str(counter))) 
    44         return counter     
    45          
    46     def beginJob(self, printer) :     
     44        return counter 
     45 
     46    def beginJob(self, printer) : 
    4747        """Saves printer internal page counter at start of job.""" 
    4848        # save page counter before job 
    4949        self.LastPageCounter = self.getPrinterInternalPageCounter() 
    5050        self.fakeBeginJob() 
    51          
    52     def fakeBeginJob(self) :     
     51 
     52    def fakeBeginJob(self) : 
    5353        """Fakes a begining of a job.""" 
    5454        self.counterbefore = self.getLastPageCounter() 
    55          
    56     def endJob(self, printer) :     
     55 
     56    def endJob(self, printer) : 
    5757        """Saves printer internal page counter at end of job.""" 
    5858        # save page counter after job 
    5959        self.LastPageCounter = self.counterafter = self.getPrinterInternalPageCounter() 
    60          
    61     def getJobSize(self, printer) :     
     60 
     61    def getJobSize(self, printer) : 
    6262        """Returns the actual job size.""" 
    6363        if (not self.counterbefore) or (not self.counterafter) : 
     
    6767                # if there's a previous job, use the last value from database 
    6868                self.filter.printInfo(_("Retrieving printer %s's page counter from database instead.") % printer.Name, "warn") 
    69                 if not self.counterbefore :  
     69                if not self.counterbefore : 
    7070                    self.counterbefore = printer.LastJob.PrinterPageCounter or 0 
    7171                if not self.counterafter : 
    7272                    self.counterafter = printer.LastJob.PrinterPageCounter or 0 
    73                 before = min(self.counterbefore, self.counterafter)     
    74                 after = max(self.counterbefore, self.counterafter)     
     73                before = min(self.counterbefore, self.counterafter) 
     74                after = max(self.counterbefore, self.counterafter) 
    7575                self.counterbefore = before 
    7676                self.counterafter = after 
     
    8585                self.counterbefore = 0 
    8686                self.counterafter = 1 
    87                  
    88         jobsize = (self.counterafter - self.counterbefore)     
     87 
     88        jobsize = (self.counterafter - self.counterbefore) 
    8989        if jobsize < 0 : 
    90             # Try to take care of HP printers  
     90            # Try to take care of HP printers 
    9191            # Their internal page counter is saved to NVRAM 
    9292            # only every 10 pages. If the printer was switched 
    9393            # off then back on during the job, and that the 
    94             # counters difference is negative, we know  
     94            # counters difference is negative, we know 
    9595            # the formula (we can't know if more than eleven 
    9696            # pages were printed though) : 
    9797            if jobsize > -10 : 
    9898                jobsize += 10 
    99             else :     
     99            else : 
    100100                # here we may have got a printer being replaced 
    101101                # DURING the job. This is HIGHLY improbable (but already happened) ! 
     
    104104                jobsize = 1 
    105105        return jobsize 
    106          
     106 
    107107    def askPrinterPageCounter(self, printer) : 
    108108        """Returns the page counter from the printer via an external command. 
    109          
     109 
    110110           The external command must report the life time page number of the printer on stdout. 
    111111        """ 
     
    117117        elif (cmdlower == "pjl") or cmdlower.startswith("pjl:") : 
    118118            return pjl.Handler(self, printer, skipinitialwait).retrieveInternalPageCounter() 
    119              
     119 
    120120        if printer is None : 
    121121            raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.PrinterName) 
    122         while 1 :     
     122        while 1 : 
    123123            self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 
    124124            pagecounter = None 
    125             child = popen2.Popen4(commandline)     
     125            child = popen2.Popen4(commandline) 
    126126            try : 
    127127                answer = child.fromchild.read() 
    128             except IOError :     
     128            except IOError : 
    129129                # we were interrupted by a signal, certainely a SIGTERM 
    130130                # caused by the user cancelling the current job 
    131131                try : 
    132132                    os.kill(child.pid, signal.SIGTERM) 
    133                 except :     
     133                except : 
    134134                    pass # already killed ? 
    135135                self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 
    136             else :     
     136            else : 
    137137                lines = [l.strip() for l in answer.split("\n")] 
    138                 for i in range(len(lines)) :  
     138                for i in range(len(lines)) : 
    139139                    try : 
    140140                        pagecounter = int(lines[i]) 
    141141                    except (AttributeError, ValueError) : 
    142142                        self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 
    143                     else :     
     143                    else : 
    144144                        break 
    145             child.fromchild.close()     
     145            child.fromchild.close() 
    146146            child.tochild.close() 
    147147            try : 
    148148                status = child.wait() 
    149             except OSError, msg :     
     149            except OSError, msg : 
    150150                self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 
    151             else :     
     151            else : 
    152152                if os.WIFEXITED(status) : 
    153153                    status = os.WEXITSTATUS(status) 
    154154                self.filter.printInfo(_("Hardware accounter %s exit code is %s") % (self.arguments, str(status))) 
    155                  
     155 
    156156            if pagecounter is None : 
    157157                message = _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline) 
     
    159159                    self.filter.printInfo(message, "error") 
    160160                else : 
    161                     raise PyKotaAccounterError, message  
    162             else :         
    163                 return pagecounter         
     161                    raise PyKotaAccounterError, message 
     162            else : 
     163                return pagecounter