[cups.general] Re: LPRng: CUPS emulation HowTo

Hermann Lauer hermann.lauer at iwr.uni-heidelberg.de
Thu Jun 17 04:02:17 PDT 2004


Hello,

(this time with attachement...)

On Thu, Jun 17, 2004 at 10:17:20AM +0200, Helmut Jarausch wrote:
> Hi,
> 
> I am a fan of LPRng and I want to keep it.
> Now, recent releases of Maple (9.0 and 9.5) do require CUPS
> to be installed on your system.
> Since I don't want to switch to CUPS I am curious if there
> is an 'emulator' which software like Maple recognizes and
> which passes all files/inquiries to LPRng.
> 
> If that's not already done and not too difficult I'd like to
> write such a tool in Python (or Perl)
> I'd just need some pointers on what to do for this.

we here are using ifhp as a backend for the CUPS spooler
so thats somekind of the other way you are asking for.
We did that because the socket backend lacks some nice features like
actions on error codes and setting the Display - did 
anybody know something about improved backends ?

But I included the python code just to give you an idea.

Greetings
  Hermann

> 
> Many thanks for any hints,
> 
> Helmut Jarausch
-- 
Netzwerkadministration/Zentrale Dienste, Interdiziplinaeres 
Zentrum fuer wissenschaftliches Rechnen der Universitaet Heidelberg
IWR; INF 368; 69120 Heidelberg; Tel: (06221)54-8236 Fax: -5224
Email: Hermann.Lauer at iwr.uni-heidelberg.de
-------------- next part --------------
#!/usr/bin/python
#
# (C) 2003 Hermann Lauer
# Could be distributed under the GPL
# $Id: ifhp,v 1.11 2003/12/16 10:49:15 hlauer Exp $
#
# Usage: ifhp job-id user title copies options [filename]

import os, sys, string, time, signal

try:
  printer=os.environ['PRINTER']
except KeyError:
  printer='UNKNOWN'

logf=open('/tmp/ifhp_%s.log'%(printer),'w')
logf.write(str(sys.argv)+"\n")
logf.write(str(os.environ)+"\n")
logf.flush()

# called with no args
if len(sys.argv)<6:
	sys.stdout.write('network ifhp "Unknown" "ifhp device printing"\n')
	sys.exit(0)

#send child a signal too, which will eventually terminate the child and close the pipe,
# so we will exit too
def signalhand(signum,frame):
	os.kill(cpid,signum)
	sys.stderr.write("ERROR: Got/Send signal %i\n"%signum)
	sys.stderr.flush()
	logf.write("ERROR: Got/Send signal %i\n"%signum)
	logf.flush()

jobid=sys.argv[1]
jobuser=sys.argv[2]
jobname=sys.argv[3]
jobcopies=sys.argv[4]
joboptions=sys.argv[5]

ifhpopt="-Ttrace"

try:
  ident,model,device=string.split(os.environ['DEVICE_URI'],':',2)
except KeyError:
  model=None
  device=None
if model: ifhpopt=ifhpopt+",model=%s"%(model)
if device: ifhpopt=ifhpopt+",dev=%s"%(device)
if os.environ.has_key('TMPDIR') and os.environ['TMPDIR']: 
	ifhpopt=ifhpopt+",tempfile=%s"%(os.environ['TMPDIR'])

cmd=["/usr/libexec/filters/ifhp",ifhpopt,"-s","/tmp/ifhp_%s.status"%(printer)]

if jobuser: cmd=cmd+["-n",jobuser]
if jobname: cmd=cmd+["-J",jobname]
cmd=cmd+["-t",time.strftime("%H:%M:%S",time.localtime(time.time()))]

#do pipe reading
c2pread, c2pwrite = os.pipe()

signal.signal(signal.SIGTERM, signalhand) #catch signal and kill child first

cpid = os.fork()
if cpid == 0:
    # Child
    os.close(c2pread)		# we only write
    logf.close()
    if len(sys.argv)>6: 	#open file and connect to stdin
	fi=open(sys.argv[6],"r")
        os.dup2(fi.fileno(), 0)
    os.dup2(c2pwrite, 2)	#connect stderr to pipe
    os.execvp(cmd[0], cmd)

#parent
# catch if anything goes wrong
try:
  os.close(c2pwrite)		# we read only
  f=os.fdopen(c2pread, 'r', 0)	# 0 means no buffering

  meld={"main:":None,
	"Do_sync:":"INFO",
	"Send_job:":"INFO",
	"Check_pagecount:":None,
	"Check_device_status:":"INFO",
	"Do_pagecount:":None,
	"Do_accounting:":None,
	"Process_job:":"INFO",
	"Do_waitend:":"INFO",
	"Pr_status:":"ERROR",
	"Link_open:":"ERROR"
	}


  while 1:
	res=f.readline()
	if not res: break
	stl=string.split(res," ",4)
	logf.write(string.join(stl,"_"))
	try:
	  level=meld[stl[3]]
	  if level:
	    logf.write("%s: %s"%(level,stl[4]))
	    sys.stderr.write("%s: %s"%(level,stl[4]))
	    sys.stderr.flush()
	except IndexError:
	    pass
	except KeyError:
	  logf.write(str(stl)+"\n")
	  sys.stderr.write(str(stl)+"\n")
	logf.flush()
except:
  logf.write("EXCEPTION: %s\n"%str(sys.exc_info()))

logf.write("RESULT: %s, %s\n"%(str(f.close()),str(os.waitpid(cpid, os.WNOHANG))))
logf.close()


More information about the cups mailing list