~ronalde/schoolcups/trunk

« back to all changes in this revision

Viewing changes to trunk/holdjob

  • Committer: Ronald van Engelen
  • Date: 2008-12-21 11:52:14 UTC
  • Revision ID: ubuntu-users@lacocina.nl-20081221115214-827dmp1z7f7enait
initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# holdjob - printcontrol cups backend
 
4
# Copyright (C) 2007  Wim van Schijndel <wvschijndel@hooghuislyceum.nl>
 
5
#
 
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
import sys
 
21
import os.path, os
 
22
import cups
 
23
 
 
24
# reading configuration file
 
25
config={}
 
26
filepointer = open ("/opt/asq/asq.conf" ,"r")
 
27
for line in filepointer:
 
28
        if line.replace(" ","")[0]!="#":
 
29
                line = line.split()
 
30
                cnf = []
 
31
                for arg in line:
 
32
                        if len(arg)>0:
 
33
                                cnf.append(arg)
 
34
                if len(cnf)>0:
 
35
                        try:
 
36
                                config[cnf[0]] = cnf[1]
 
37
                        except:
 
38
                                config[cnf[0]] = ""
 
39
 
 
40
# setting cups constants
 
41
CUPS_BACKEND_OK = 0 # Job completed successfully
 
42
CUPS_BACKEND_FAILED = 1 # Job failed, use error-policy
 
43
CUPS_BACKEND_AUTH_REQUIRED = 2 # Job failed, authentication required
 
44
CUPS_BACKEND_HOLD = 3 # Job failed, hold job
 
45
CUPS_BACKEND_STOP = 4 #  Job failed, stop queue
 
46
CUPS_BACKEND_CANCEL = 5 # Job failed, cancel job
 
47
 
 
48
# setting callback function for cups authentication
 
49
def callback ():
 
50
        return config["cups_admin_pass"]
 
51
 
 
52
# main program
 
53
def main():
 
54
        # only 1 argument so display backend info to cups
 
55
        if len(sys.argv)==1:
 
56
                sys.stdout.write("direct %s:// \"Unknown\" \"HoldJob\"\n" % os.path.basename(sys.argv[0]))
 
57
                sys.stdout.flush()
 
58
                sys.exit(CUPS_BACKEND_OK)
 
59
        # to many or to little arguments so display usage
 
60
        #elif len(sys.argv) not in (5,6):
 
61
        #       sys.stdout.write("Usage: %s job-id user title copies options [file]\n" % os.path.basename(sys.argv[0]))
 
62
        #       sys.stdout.flush()
 
63
        #       sys.exit(CUPS_BACKEND_CANCEL)
 
64
        # getting job from cups so process
 
65
        else:
 
66
                cupsjobinfo={}
 
67
                cupsjobinfo["job_id"]=int(sys.argv[1])
 
68
                # setting cups admin user and password
 
69
                cups.setUser(config["cups_admin_user"])
 
70
                cups.setPasswordCB (callback)
 
71
                # make connection with cups and get active jobs
 
72
                cc = cups.Connection()
 
73
                cupsjobs = cc.getJobs()
 
74
                cc.setJobHoldUntil(cupsjobinfo["job_id"],'hold')
 
75
        sys.exit(CUPS_BACKEND_OK)
 
76
 
 
77
main()