[695] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | # PyKota - Print Quotas for CUPS |
---|
| 4 | # |
---|
| 5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 6 | # You're welcome to redistribute this software under the |
---|
| 7 | # terms of the GNU General Public Licence version 2.0 |
---|
| 8 | # or, at your option, any higher version. |
---|
| 9 | # |
---|
| 10 | # You can read the complete GNU GPL in the file COPYING |
---|
| 11 | # which should come along with this software, or visit |
---|
| 12 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
| 13 | # |
---|
| 14 | # $Id$ |
---|
| 15 | # |
---|
| 16 | # $Log$ |
---|
[780] | 17 | # Revision 1.5 2003/02/10 00:42:17 jalet |
---|
| 18 | # External requester should be ok (untested) |
---|
| 19 | # New syntax for configuration file wrt requesters |
---|
| 20 | # |
---|
[773] | 21 | # Revision 1.4 2003/02/09 13:05:43 jalet |
---|
| 22 | # Internationalization continues... |
---|
| 23 | # |
---|
[744] | 24 | # Revision 1.3 2003/02/07 13:12:41 jalet |
---|
| 25 | # Bad old comment |
---|
| 26 | # |
---|
[705] | 27 | # Revision 1.2 2003/02/05 23:00:12 jalet |
---|
| 28 | # Forgotten import |
---|
| 29 | # Bad datetime conversion |
---|
| 30 | # |
---|
[695] | 31 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 32 | # Initial import into CVS |
---|
| 33 | # |
---|
| 34 | # |
---|
| 35 | # |
---|
| 36 | |
---|
[705] | 37 | import os |
---|
[695] | 38 | from pykota.requester import PyKotaRequesterError |
---|
| 39 | |
---|
| 40 | class Requester : |
---|
| 41 | """A class to send queries to printers via SNMP.""" |
---|
[780] | 42 | def __init__(self, config, printername, arguments) : |
---|
[695] | 43 | """Sets instance vars depending on the current printer.""" |
---|
| 44 | self.printername = printername |
---|
[780] | 45 | self.community = arguments[0] |
---|
| 46 | self.oid = arguments[1] |
---|
[695] | 47 | |
---|
| 48 | def getPrinterPageCounter(self, hostname) : |
---|
| 49 | """Returns the page counter from the hostname printer via SNMP. |
---|
| 50 | |
---|
| 51 | Currently uses the snmpget external command. TODO : do it internally |
---|
| 52 | """ |
---|
| 53 | if hostname is None : |
---|
[773] | 54 | raise PyKotaRequesterError, _("Unknown printer address in SNMP(%s, %s) for printer %s") % (self.community, self.oid, self.printername) |
---|
[695] | 55 | answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid)) |
---|
| 56 | try : |
---|
| 57 | pagecounter = int(answer.readline().split()[-1].strip()) |
---|
| 58 | except IndexError : |
---|
[773] | 59 | raise PyKotaRequesterError, _("Unable to query printer %s via SNMP(%s, %s)") % (hostname, self.community, self.oid) |
---|
[695] | 60 | answer.close() |
---|
| 61 | return pagecounter |
---|
| 62 | |
---|