[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Need for a printconf package

On Jun 22, Michael Banck quoted Daniel:
> > Just like etherconf, printconf would "only" handle 90 % of the cases,
> > imposing Debian's prefered spooler and filters because in 90 % of the
> > cases, they don't matter. Thus, printconf would depend on, say, cups and
> > foomatic-*, and use libprinterconf0 to detect parallel, USB and network
> > printers. printconf would also provide a debconf frontend to
> > foomatic-configure (à la foomatic-gui) and mention the weird
> > http://localhost:631/ (CUPS configuration).

This stuff is trivially easy with anything USB or IEEE 1284 parallel.
The pain is really getting network printers right--CUPS will normally
Do The Right Thing automagically with other CUPS servers with Browsing
On and BrowseAddress set to @LOCAL, but Samba and JetDirect etc. take
some manual probing.

Here'd be my idea for a "proof of concept" printconf:

- Depend on foomatic-db-engine, foomatic-db,
  foomatic-db-{hpijs,gimp-print} and the preferred spooler.
  (Also depend on network stuff?)

- Debconf .config question at medium: do you want to automatically
  configure any printers found?  Probably default yes.

- If yes, in postinst run needed code ripped out of foomatic-gui to
  detect said printers and set up the preferred driver for them using
  sensible defaults.  99% of the needed code is already written in
  foomatic-gui; just a matter of doing something like:

# printconf

  # printconf - silly script to set up every printer attached to the
  # system with zero fuss.

  # Copyright (C) 2004 Chris Lawrence <lawrencc@debian.org>
  # GPL v2 or later

  from foomatic import detect, foomatic
  import re
  import os

  # regex for invalid characters in queue names to be filtered
  _invalidre = re.compile(r'([^A-Za-z0-9_])')

  def cleanup_name(model):
      model = model.lower().replace(' ', '_')
      newmod = invalidre.sub('', model)
      return newmod

  # CUPS needs printer.conf established before lpadmin will work properly
  os.system('touch /etc/cups/printer.conf')

  printdb = foomatic.get_printer_db()
  for (device, detectdata, devdesc, detectdesc) in conns:
      # Skip everything we don't have autodetection data for
      if not detectdata: continue

      # Get the IEEE 1284 printer description
      desc = detectdata.get('description')
      if not desc: continue

      model = detectdata.get('model', desc)

      pdbinfo = printdb.autodetect_ids.get(desc)
      # Unknown printer; probably should print a message here asking
      # people to contribute this information to foomatic-db
      if not pdbinfo: continue

      prefdriver = pdbinfo.get('driver')
      # Unsupported printer; barf something here
      if not prefdriver: continue

      foomatic.setup_queue( {'connect' : device, 'description' : desc,
                             'name' : cleanup_name(model),
                             'location' : devdesc,
                             'driver' : prefdriver } )
      # Queue X is now set up with name based on the IEEE model
      # some sort of message here would be nice

  # After loop, reinit CUPS
  os.system('/usr/sbin/invoke-rc.d cupsys reload')    

# End of script

That code should do exactly what we want, modulo bugs of course.  All
that's needed from a practical standpoint is:

- Split foomatic-gui into: foomatic-gui, python-foomatic, and
- The debconf stuff for printconf

Chris Lawrence <lawrencc@debian.org> - http://blog.lordsutch.com/

Reply to: