[695] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | # PyKota - Print Quotas for CUPS |
---|
| 4 | # |
---|
| 5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
[873] | 6 | # This program is free software; you can redistribute it and/or modify |
---|
| 7 | # it under the terms of the GNU General Public License as published by |
---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | # (at your option) any later version. |
---|
[695] | 10 | # |
---|
[873] | 11 | # This program is distributed in the hope that it will be useful, |
---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | # GNU General Public License for more details. |
---|
| 15 | # |
---|
| 16 | # You should have received a copy of the GNU General Public License |
---|
| 17 | # along with this program; if not, write to the Free Software |
---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
[695] | 19 | # |
---|
| 20 | # $Id$ |
---|
| 21 | # |
---|
| 22 | # $Log$ |
---|
[873] | 23 | # Revision 1.7 2003/03/29 13:45:27 jalet |
---|
| 24 | # GPL paragraphs were incorrectly (from memory) copied into the sources. |
---|
| 25 | # Two README files were added. |
---|
| 26 | # Upgrade script for PostgreSQL pre 1.01 schema was added. |
---|
| 27 | # |
---|
[789] | 28 | # Revision 1.6 2003/02/10 11:47:39 jalet |
---|
| 29 | # Moved some code down into the requesters |
---|
| 30 | # |
---|
[780] | 31 | # Revision 1.5 2003/02/10 00:42:17 jalet |
---|
| 32 | # External requester should be ok (untested) |
---|
| 33 | # New syntax for configuration file wrt requesters |
---|
| 34 | # |
---|
[773] | 35 | # Revision 1.4 2003/02/09 13:05:43 jalet |
---|
| 36 | # Internationalization continues... |
---|
| 37 | # |
---|
[744] | 38 | # Revision 1.3 2003/02/07 13:12:41 jalet |
---|
| 39 | # Bad old comment |
---|
| 40 | # |
---|
[705] | 41 | # Revision 1.2 2003/02/05 23:00:12 jalet |
---|
| 42 | # Forgotten import |
---|
| 43 | # Bad datetime conversion |
---|
| 44 | # |
---|
[695] | 45 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 46 | # Initial import into CVS |
---|
| 47 | # |
---|
| 48 | # |
---|
| 49 | # |
---|
| 50 | |
---|
[705] | 51 | import os |
---|
[695] | 52 | from pykota.requester import PyKotaRequesterError |
---|
| 53 | |
---|
| 54 | class Requester : |
---|
| 55 | """A class to send queries to printers via SNMP.""" |
---|
[780] | 56 | def __init__(self, config, printername, arguments) : |
---|
[695] | 57 | """Sets instance vars depending on the current printer.""" |
---|
| 58 | self.printername = printername |
---|
[789] | 59 | args = [x.strip() for x in arguments.split(',')] |
---|
| 60 | self.community = args[0] |
---|
| 61 | self.oid = args[1] |
---|
[695] | 62 | |
---|
| 63 | def getPrinterPageCounter(self, hostname) : |
---|
| 64 | """Returns the page counter from the hostname printer via SNMP. |
---|
| 65 | |
---|
| 66 | Currently uses the snmpget external command. TODO : do it internally |
---|
| 67 | """ |
---|
| 68 | if hostname is None : |
---|
[773] | 69 | raise PyKotaRequesterError, _("Unknown printer address in SNMP(%s, %s) for printer %s") % (self.community, self.oid, self.printername) |
---|
[695] | 70 | answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid)) |
---|
| 71 | try : |
---|
| 72 | pagecounter = int(answer.readline().split()[-1].strip()) |
---|
| 73 | except IndexError : |
---|
[773] | 74 | raise PyKotaRequesterError, _("Unable to query printer %s via SNMP(%s, %s)") % (hostname, self.community, self.oid) |
---|
[695] | 75 | answer.close() |
---|
| 76 | return pagecounter |
---|
| 77 | |
---|