Changeset 1342

Show
Ignore:
Timestamp:
02/09/04 13:35:19 (21 years ago)
Author:
jalet
Message:

De-uglyfication.
Now works with older CUPS (1.14) which don't detect the cupspykota backend but accept it anyway.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkhint

    r1340 r1342  
    2424# 
    2525# $Log$ 
     26# Revision 1.4  2004/02/09 12:35:19  jalet 
     27# De-uglyfication. 
     28# Now works with older CUPS (1.14) which don't detect the cupspykota backend but accept it anyway. 
     29# 
    2630# Revision 1.3  2004/02/07 13:56:03  jalet 
    2731# Help 
     
    8488         
    8589SNMPTESTS = [ \ 
    86               '/usr/bin/npadmin --pagecount %(printer)s', \ 
    87               '/usr/bin/snmpget -v1 -c public -Ov %(printer)s mib-2.43.10.2.1.4.1.1 | cut -f 2,2 -d " "', \ 
    88               '/usr/bin/snmpwalk -v 1 -Cc -c public %(printer)s | grep mib-2.43.10.2.1.4.1.1 | cut -d " " -f4', \ 
    89               '/usr/bin/snmpwalk -v 1 -Cc -c public -Ov %(printer)s | grep Counter32 | tail -2 | head -1 | cut -d " " -f2', \ 
     90              '/usr/bin/npadmin --pagecount %(printer)s 2>/dev/null', \ 
     91              '/usr/bin/snmpget -v1 -c public -Ov %(printer)s mib-2.43.10.2.1.4.1.1 2>/dev/null | cut -f 2,2 -d " "', \ 
     92              '/usr/bin/snmpwalk -v 1 -Cc -c public %(printer)s 2>/dev/null | grep mib-2.43.10.2.1.4.1.1 | cut -d " " -f4', \ 
     93              '/usr/bin/snmpwalk -v 1 -Cc -c public -Ov %(printer)s 2>/dev/null | grep Counter32 | tail -2 | head -1 | cut -d " " -f2', \ 
    9094            ] 
    9195 
     
    135139    def searchDeviceType(self, devicestypes, device) :     
    136140        """Returns the device type for current device.""" 
     141        if device.startswith("cupspykota:") : 
     142            fulldevice = device[:] 
     143            device = fulldevice[len("cupspykota:"):] 
     144            if device.startswith("//") : 
     145                device = device[2:] 
    137146        for (k, v) in devicestypes.items() : 
    138147            if device.startswith(k) : 
     
    157166        return destination.split("/")[0] 
    158167         
    159     def acceptsSNMP(self, printer) :     
     168    def accepts(self, printer, commands) :     
    160169        """Tries to get the printer's internal page counter via SNMP.""" 
    161         for command in SNMPTESTS : 
    162             inp = os.popen((command + " 2>/dev/null") % locals()) 
     170        for command in commands : 
     171            inp = os.popen(command % locals()) 
    163172            value = inp.readline().strip() 
    164173            inp.close() 
     
    172181    def main(self, args, options) : 
    173182        """Main work is done here.""" 
    174         print "Put the following lines into your /etc/pykota/pykota.conf file :\n" 
     183        print "\nPlease wait while pkhint analyzes your printing system's configuration..." 
    175184        printers = self.extractPrintersInformation() 
    176185        devicestypes = self.extractDevices() # TODO : IT'S CUPS ONLY FOR NOW 
     186        configuration = [] 
    177187        for (printer, device) in printers.items() : 
    178188            if self.matchString(printer, args) : 
    179                 print "[%s]" % printer 
    180189                devicetype = self.searchDeviceType(devicestypes, device) 
    181190                device = self.extractDeviceFromURI(device) 
     
    187196                    except ValueError :     
    188197                        hostname = device 
    189                     snmpcommand = self.acceptsSNMP(hostname) 
     198                    snmpcommand = self.accepts(hostname, SNMPTESTS) 
    190199                    if snmpcommand is not None : 
    191                         print "accounter: querying" 
    192                         print 'requester: external(/usr/bin/waitprinter.sh %(printer)s && ' + snmpcommand + ')' 
     200                        accounter = "querying" 
     201                        requester = 'external(/usr/bin/waitprinter.sh %(printer)s && ' + snmpcommand + ')' 
     202                        configuration.append((printer, accounter, requester)) 
    193203                elif devicetype == "direct" :  
    194204                    sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer)) 
     
    197207                else : 
    198208                    sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer)) 
     209                     
     210        if not configuration :             
     211            print "\nSorry, pkhint can't help you for now. Please configure PyKota manually." 
     212        else : 
     213            print "\nPut the following lines into your /etc/pykota/pykota.conf file :\n" 
     214            for (printer, accounter, requester) in configuration : 
     215                print "[%s]" % printer 
     216                print "accounter: %s" % accounter 
     217                if requester is not None : 
     218                    print "requester: %s" % requester 
    199219                print     
    200220