Getting available printer trays with PyCups

1k views Asked by At

I am trying to retrieve all the trays available for a printer, but I can't find a way to retrieve a list of the available trays.

This is how I am getting the printers:

>>> import cups
>>> conn = cups.Connection ()
>>> printers = conn.getPrinters ()
>>> for printer in printers:
...     print printer, printers[printer]["device-uri"]
Brother_MFC_1910W_series
Photosmart_6520_series

It works just fine, but there's no information about trays in printers. Any help or reference is much appreciated thanks.

For the record, I'm working on OS X.

2

There are 2 answers

0
Sid On BEST ANSWER

Well after several attempts here's what I've done in order to get the trays.

For each Printer I've found, I look into /etc/cups/ppd/ for the printer_name.ppd file, in which I can find every details I need trays included.

It's also useful as I can get the trays in each language supported in the PPDs file.

0
illright On

Following up on the accepted answer:

Since the PPD files require superuser privileges for reading, a simple way to access them with PyCUPS is as follows:

>>> import cups
>>> conn = cups.Connection()
>>> ppd = conn.getPPD('Brother_MFC_1910W_series')  # Your desired printer's name
>>> print(ppd)  # returns a filename of a temporary file with the PPD
'/tmp/576b35f2620f5'
>>> ppd_file = open(ppd)
>>> print(ppd_file.read())