Changeset 1343 for pykota

Show
Ignore:
Timestamp:
02/09/04 14:07:06 (21 years ago)
Author:
jalet
Message:

Should now be able to handle network + pjl printers

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkhint

    r1342 r1343  
    2424# 
    2525# $Log$ 
     26# Revision 1.5  2004/02/09 13:07:06  jalet 
     27# Should now be able to handle network + pjl printers 
     28# 
    2629# Revision 1.4  2004/02/09 12:35:19  jalet 
    2730# De-uglyfication. 
     
    9396              '/usr/bin/snmpwalk -v 1 -Cc -c public -Ov %(printer)s 2>/dev/null | grep Counter32 | tail -2 | head -1 | cut -d " " -f2', \ 
    9497            ] 
     98             
     99NETPJLTESTS = [ \ 
     100                '/usr/bin/pagecount.pl %(printer)s %(port)s 2>/dev/null', \ 
     101                '/bin/nc -w 2 %(printer)s %(port)s </usr/share/pykota/pagecount.pjl 2>/dev/null | /usr/bin/tail -2', \ 
     102              ] 
    95103 
    96104class PKHint(PyKotaTool) : 
     
    166174        return destination.split("/")[0] 
    167175         
    168     def accepts(self, printer, commands) :     
     176    def accepts(self, commands, printer, port=None) :     
    169177        """Tries to get the printer's internal page counter via SNMP.""" 
    170178        for command in commands : 
     
    185193        devicestypes = self.extractDevices() # TODO : IT'S CUPS ONLY FOR NOW 
    186194        configuration = [] 
    187         for (printer, device) in printers.items() : 
     195        for (printer, deviceuri) in printers.items() : 
    188196            if self.matchString(printer, args) : 
    189                 devicetype = self.searchDeviceType(devicestypes, device) 
    190                 device = self.extractDeviceFromURI(device) 
     197                devicetype = self.searchDeviceType(devicestypes, deviceuri) 
     198                device = self.extractDeviceFromURI(deviceuri) 
    191199                if devicetype is None : 
    192200                    sys.stderr.write("Unknown device %s for printer %s\n" % (device, printer)) 
     
    196204                    except ValueError :     
    197205                        hostname = device 
    198                     snmpcommand = self.accepts(hostname, SNMPTESTS) 
     206                        port = 9100             # TODO : may cause problems with other protocols. 
     207                         
     208                    snmpcommand = self.accepts(SNMPTESTS, hostname) 
    199209                    if snmpcommand is not None : 
    200210                        accounter = "querying" 
    201211                        requester = 'external(/usr/bin/waitprinter.sh %(printer)s && ' + snmpcommand + ')' 
    202212                        configuration.append((printer, accounter, requester)) 
     213                    else :     
     214                        netpjlcommand = self.accepts(NETPJLTESTS, hostname, port) 
     215                        if netpjlcommand is not None : 
     216                            accounter = "querying" 
     217                            requester = 'external(' + netpjlcommand + ')' 
     218                            configuration.append((printer, accounter, requester)) 
    203219                elif devicetype == "direct" :  
    204220                    sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer))