Show
Ignore:
Timestamp:
02/10/03 01:42:17 (21 years ago)
Author:
jalet
Message:

External requester should be ok (untested)
New syntax for configuration file wrt requesters

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/requesters/external.py

    r773 r780  
    1515# 
    1616# $Log$ 
     17# Revision 1.3  2003/02/10 00:42:17  jalet 
     18# External requester should be ok (untested) 
     19# New syntax for configuration file wrt requesters 
     20# 
    1721# Revision 1.2  2003/02/09 13:05:43  jalet 
    1822# Internationalization continues... 
     
    2933class Requester : 
    3034    """A class to send queries to printers via external commands.""" 
    31     def __init__(self, config, printername) : 
     35    def __init__(self, config, printername, arguments) : 
    3236        """Sets instance vars depending on the current printer.""" 
    3337        self.printername = printername 
    34         raise PyKotaRequesterError, _("Requester not implemented yet.") 
     38        self.commandline = arguments[0] 
    3539         
    36     def getPrinterPageCounter(self, hostname) : 
    37         """Returns the page counter from the hostname printer via SNMP. 
     40    def getPrinterPageCounter(self, printer) : 
     41        """Returns the page counter from the printer via an external command. 
    3842         
    39            Currently uses the snmpget external command. TODO : do it internally  
     43           The external command must report the life time page number of the printer on stdout. 
    4044        """ 
    41         raise PyKotaRequesterError, _("Requester not implemented yet.") 
     45        commandline = self.commandline % locals() 
     46        if printer is None : 
     47            raise PyKotaRequesterError, _("Unknown printer address in EXTERNAL(%s) for printer %s") % (commandline, self.printername) 
     48        answer = os.popen(commandline) 
     49        try : 
     50            pagecounter = int(answer.readline().strip()) 
     51        except IndexError :     
     52            raise PyKotaRequesterError, _("Unable to query printer %s via EXTERNAL(%s)") % (printer, commandline)  
     53        answer.close() 
     54        return pagecounter 
    4255