1 | # PyKota |
---|
2 | # |
---|
3 | # PyKota - Print Quotas for CUPS and LPRng |
---|
4 | # |
---|
5 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
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. |
---|
10 | # |
---|
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. |
---|
19 | # |
---|
20 | # $Id$ |
---|
21 | # |
---|
22 | # $Log$ |
---|
23 | # Revision 1.8 2003/04/23 22:13:57 jalet |
---|
24 | # Preliminary support for LPRng added BUT STILL UNTESTED. |
---|
25 | # |
---|
26 | # Revision 1.7 2003/03/29 13:45:27 jalet |
---|
27 | # GPL paragraphs were incorrectly (from memory) copied into the sources. |
---|
28 | # Two README files were added. |
---|
29 | # Upgrade script for PostgreSQL pre 1.01 schema was added. |
---|
30 | # |
---|
31 | # Revision 1.6 2003/02/10 11:47:39 jalet |
---|
32 | # Moved some code down into the requesters |
---|
33 | # |
---|
34 | # Revision 1.5 2003/02/10 00:42:17 jalet |
---|
35 | # External requester should be ok (untested) |
---|
36 | # New syntax for configuration file wrt requesters |
---|
37 | # |
---|
38 | # Revision 1.4 2003/02/09 13:05:43 jalet |
---|
39 | # Internationalization continues... |
---|
40 | # |
---|
41 | # Revision 1.3 2003/02/07 13:12:41 jalet |
---|
42 | # Bad old comment |
---|
43 | # |
---|
44 | # Revision 1.2 2003/02/05 23:00:12 jalet |
---|
45 | # Forgotten import |
---|
46 | # Bad datetime conversion |
---|
47 | # |
---|
48 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
49 | # Initial import into CVS |
---|
50 | # |
---|
51 | # |
---|
52 | # |
---|
53 | |
---|
54 | import os |
---|
55 | from pykota.requester import PyKotaRequesterError |
---|
56 | |
---|
57 | class Requester : |
---|
58 | """A class to send queries to printers via SNMP.""" |
---|
59 | def __init__(self, config, printername, arguments) : |
---|
60 | """Sets instance vars depending on the current printer.""" |
---|
61 | self.printername = printername |
---|
62 | args = [x.strip() for x in arguments.split(',')] |
---|
63 | self.community = args[0] |
---|
64 | self.oid = args[1] |
---|
65 | |
---|
66 | def getPrinterPageCounter(self, hostname) : |
---|
67 | """Returns the page counter from the hostname printer via SNMP. |
---|
68 | |
---|
69 | Currently uses the snmpget external command. TODO : do it internally |
---|
70 | """ |
---|
71 | if hostname is None : |
---|
72 | raise PyKotaRequesterError, _("Unknown printer address in SNMP(%s, %s) for printer %s") % (self.community, self.oid, self.printername) |
---|
73 | answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid)) |
---|
74 | try : |
---|
75 | pagecounter = int(answer.readline().split()[-1].strip()) |
---|
76 | except IndexError : |
---|
77 | raise PyKotaRequesterError, _("Unable to query printer %s via SNMP(%s, %s)") % (hostname, self.community, self.oid) |
---|
78 | answer.close() |
---|
79 | return pagecounter |
---|
80 | |
---|