root / pykota / trunk / pykota / accounters / stupid.py @ 1240

Revision 1240, 3.0 kB (checked in by uid67467, 20 years ago)

Should be ok now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2# -*- coding: ISO-8859-15 -*-
3#
4# PyKota - Print Quotas for CUPS and LPRng
5#
6# (c) 2003 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20#
21# $Id$
22#
23# $Log$
24# Revision 1.10  2003/12/27 16:49:25  uid67467
25# Should be ok now.
26#
27# Revision 1.8  2003/11/23 19:01:37  jalet
28# Job price added to history
29#
30# Revision 1.7  2003/11/21 14:28:46  jalet
31# More complete job history.
32#
33# Revision 1.6  2003/11/12 23:29:24  jalet
34# More work on new backend. This commit may be unstable.
35#
36# Revision 1.5  2003/10/07 09:07:29  jalet
37# Character encoding added to please latest version of Python
38#
39# Revision 1.4  2003/06/25 14:10:01  jalet
40# Hey, it may work (edpykota --reset excepted) !
41#
42# Revision 1.3  2003/05/27 23:00:21  jalet
43# Big rewrite of external accounting methods.
44# Should work well now.
45#
46# Revision 1.2  2003/04/30 13:40:47  jalet
47# Small fix
48#
49# Revision 1.1  2003/04/30 13:36:40  jalet
50# Stupid accounting method was added.
51#
52#
53#
54
55import sys
56import tempfile
57from pykota.accounter import AccounterBase, PyKotaAccounterError
58
59class Accounter(AccounterBase) :
60    def computeJobSize(self) :   
61        """Computes the job size and return its value.
62       
63           THIS METHOD IS COMPLETELY UNRELIABLE BUT SERVES AS AN EXAMPLE.
64        """
65        # first we log a message because using this accounting method is not recommended.
66        self.filter.logger.log_message(_("Using the 'stupid' accounting method is unreliable."), "warn")
67       
68        temporary = None   
69        if self.filter.inputfile is None :   
70            infile = sys.stdin
71            # we will have to duplicate our standard input
72            temporary = tempfile.TemporaryFile()
73        else :   
74            infile = open(self.filter.inputfile, "rb")
75           
76        pagecount = 0
77        for line in infile.xreadlines() :
78            pagecount += line.count("showpage")
79            if temporary is not None :   
80                temporary.write(line)   
81               
82        if temporary is not None :   
83            # this is a copy of our previous standard input
84            # flush, then rewind
85            temporary.flush()
86            temporary.seek(0, 0)
87            # our temporary file will be used later if the
88            # job is allowed.
89            self.filter.inputfile = temporary
90        else :
91            infile.close()
92        return pagecount   
Note: See TracBrowser for help on using the browser.