Changeset 1342
- Timestamp:
- 02/09/04 13:35:19 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkhint
r1340 r1342 24 24 # 25 25 # $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 # 26 30 # Revision 1.3 2004/02/07 13:56:03 jalet 27 31 # Help … … 84 88 85 89 SNMPTESTS = [ \ 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', \ 90 94 ] 91 95 … … 135 139 def searchDeviceType(self, devicestypes, device) : 136 140 """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:] 137 146 for (k, v) in devicestypes.items() : 138 147 if device.startswith(k) : … … 157 166 return destination.split("/")[0] 158 167 159 def accepts SNMP(self, printer) :168 def accepts(self, printer, commands) : 160 169 """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()) 163 172 value = inp.readline().strip() 164 173 inp.close() … … 172 181 def main(self, args, options) : 173 182 """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..." 175 184 printers = self.extractPrintersInformation() 176 185 devicestypes = self.extractDevices() # TODO : IT'S CUPS ONLY FOR NOW 186 configuration = [] 177 187 for (printer, device) in printers.items() : 178 188 if self.matchString(printer, args) : 179 print "[%s]" % printer180 189 devicetype = self.searchDeviceType(devicestypes, device) 181 190 device = self.extractDeviceFromURI(device) … … 187 196 except ValueError : 188 197 hostname = device 189 snmpcommand = self.accepts SNMP(hostname)198 snmpcommand = self.accepts(hostname, SNMPTESTS) 190 199 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)) 193 203 elif devicetype == "direct" : 194 204 sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer)) … … 197 207 else : 198 208 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 199 219 print 200 220