root / tea4cups / trunk / cupsoftee @ 567

Revision 567, 3.2 kB (checked in by jerome, 19 years ago)

Initial README file

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3
4# CupsOfTee : Tee for CUPS
5#
6# (c) 2005 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#
24
25import sys
26import os
27import popen2
28import cStringIO
29import shlex
30import select
31import signal
32import time
33
34if __name__ == "__main__" :   
35    # This is a CUPS backend, we should act and die like a CUPS backend
36    retcode = 0
37    if len(sys.argv) == 1 :
38        # we will execute each existing backend in device enumeration mode
39        # and generate their PyKota accounting counterpart
40        (directory, myname) = os.path.split(sys.argv[0])
41        for backend in [os.path.join(directory, b) for b in os.listdir(directory) if os.path.isfile(os.path.join(directory, b)) and (b != myname)] :
42            answer = os.popen(backend, "r")
43            try :
44                devices = [line.strip() for line in answer.readlines()]
45            except :   
46                devices = []
47            status = answer.close()
48            if status is None :
49                for d in devices :
50                    # each line is of the form : 'xxxx xxxx "xxxx xxx" "xxxx xxx"'
51                    # so we have to decompose it carefully
52                    fdevice = cStringIO.StringIO("%s" % d)
53                    tokenizer = shlex.shlex(fdevice)
54                    tokenizer.wordchars = tokenizer.wordchars + r".:,?!~/\_$*-+={}[]()#"
55                    arguments = []
56                    while 1 :
57                        token = tokenizer.get_token()
58                        if token :
59                            arguments.append(token)
60                        else :
61                            break
62                    fdevice.close()
63                    try :
64                        (devicetype, device, name, fullname) = arguments
65                    except ValueError :   
66                        pass    # ignore this 'bizarre' device
67                    else :   
68                        if name.startswith('"') and name.endswith('"') :
69                            name = name[1:-1]
70                        if fullname.startswith('"') and fullname.endswith('"') :
71                            fullname = fullname[1:-1]
72                        print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname)
73        retcode = 0               
74    elif len(sys.argv) not in (6, 7) :   
75        sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0])
76        retcode = 1
77    else :   
78        sys.stderr.write("ERROR: Not Yet !\n")
79        retcode = 1
80    sys.exit(retcode)   
Note: See TracBrowser for help on using the browser.