Reading control files in /var/spool/cups/c*

Mattioli Pier Maria mattioli.pr at maxmara.it
Thu Jun 11 02:08:02 PDT 2009


Hi,
I need to know how to read information into the file c* located into /var/spool/cups/.

I use python and at the moment I wrote this "test" code to read some job's information directly reading these file couse lpq and lpstat don'r report the job status and they are too slow (my cups server manage 10000 jobs per day on 200 printers).

"""
jobs = sys.argv[1:]

cmd = "lpstat -l -P all"
retcode, buf = commands.getstatusoutput(cmd)
buf = [' '.join(b.split( )) for b in buf.split('\n') if b.strip()]
job_list = []
for x in range(0, len(buf), 2):
	job_id = buf[x].split('-')[1].split(' ')[0]
	job_list.append(job_id)

for jobid in jobs:
	cont = open('/var/spool/cups/c%s' % jobid, 'r').read()

	if not jobid in job_list\
	and 'J' in cont.split('\x00\x11time-at-completed')[1].split('!')[0]\
	and 'J' not in cont.split('\x00\x12time-at-processing')[1].split('\x00\x11time-at-completed')[0]:
		jobstatus = 'cacelled'

	elif not jobid in job_list:
		jobstatus = 'completed'

	elif 'J' in cont.split('\x00\x12time-at-processing')[1].split('\x00\x11time-at-completed')[0]:
		jobstatus = 'printing'

	elif '\x07no-hold\x03' in cont:
		jobstatus = 'waiting'

	else:
		jobstatus = 'stopped'
"""

As You can see I don't know how status information are written in these files. This code seems to work but doesn't show jobs in the status I called "printing". Is there any reference to the content of these control files?
Can anyone tellme where is the parser for these files into the CUPS sources?

Thankyou

Pier






More information about the cups mailing list