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$ |
---|
17 | # Revision 1.4 2003/02/10 10:36:33 jalet |
---|
18 | # Small problem wrt external requester |
---|
19 | # |
---|
20 | # Revision 1.3 2003/02/10 00:42:17 jalet |
---|
21 | # External requester should be ok (untested) |
---|
22 | # New syntax for configuration file wrt requesters |
---|
23 | # |
---|
24 | # Revision 1.2 2003/02/09 13:05:43 jalet |
---|
25 | # Internationalization continues... |
---|
26 | # |
---|
27 | # Revision 1.1 2003/02/07 13:15:01 jalet |
---|
28 | # External requester skeleton added. |
---|
29 | # |
---|
30 | # |
---|
31 | # |
---|
32 | |
---|
33 | import os |
---|
34 | from pykota.requester import PyKotaRequesterError |
---|
35 | |
---|
36 | class Requester : |
---|
37 | """A class to send queries to printers via external commands.""" |
---|
38 | def __init__(self, config, printername, arguments) : |
---|
39 | """Sets instance vars depending on the current printer.""" |
---|
40 | self.printername = printername |
---|
41 | self.commandline = arguments[0] |
---|
42 | |
---|
43 | def getPrinterPageCounter(self, printer) : |
---|
44 | """Returns the page counter from the printer via an external command. |
---|
45 | |
---|
46 | The external command must report the life time page number of the printer on stdout. |
---|
47 | """ |
---|
48 | commandline = self.commandline % locals() |
---|
49 | if printer is None : |
---|
50 | raise PyKotaRequesterError, _("Unknown printer address in EXTERNAL(%s) for printer %s") % (commandline, self.printername) |
---|
51 | answer = os.popen(commandline) |
---|
52 | try : |
---|
53 | pagecounter = int(answer.readline().strip()) |
---|
54 | except ValueError : |
---|
55 | raise PyKotaRequesterError, _("Unable to query printer %s via EXTERNAL(%s)") % (printer, commandline) |
---|
56 | answer.close() |
---|
57 | return pagecounter |
---|
58 | |
---|