[cups.development] [ANNOUNCE] ipplib : python IPP and CUPS API

Jerome Alet alet at librelogiciel.com
Fri May 19 09:58:57 PDT 2006


Hi there,

I'm pleased to announce a new project of mine, named ipplib, which 
offers IPP requests parsing and/or building, and (basic) support for 
the CUPS' API. 

This project is written in 100% Python, and is available under
the terms of the GNU GPL.

It's very young, although the parsing code is two years old and I 
believe well tested, so it's currently only downloadable from 
subversion for now :

  $ cd /tmp
  $ svn co svn://svn.librelogiciel.com/ipplib/trunk ipplib
  $ cd ipplib
  $ python setup.py install
  
  (for the last line to work, you need the python-dev package
  installed).
  
Examples of use in Python programs :

--- CUT ---
# Parsing.py    EXAMPLE
from ipplib import ipplib

# Read IPP datas from a CUPS control file
myfile = open("/var/spool/cups/c00155")
ippdatas = myfile.read()
myfile.close()

# Parse these datas
request = ipplib.IPPRequest(ippdatas)
request.parse()
print request
--- CUT ---


--- CUT ---
# Building.py   EXAMPLE
from ipplib import ipplib

request = ipplib.IPPRequest(operation_id=ipplib.CUPS_GET_DEFAULT)
request.operation["attributes-charset"] = ("charset", "utf-8")
request.operation["attributes-natural-language"] = ("naturalLanguage", "en-us")
ippdatas = request.dump()

newrequest = ipplib.IPPRequest(ippdatas)
newrequest.parse()
print newrequest.operation["attributes-natural-language"]
--- CUT ---


--- CUT ---
# CUPS' API
from ipplib import ipplib

cups = ipplib.CUPS()

# High level API : retrieve info about job 3 :
answer = cups.getJobAttributes(3)
print answer.job["document-format"]

# Lower level API :
request = cups.newRequest(ipplib.IPP_GET_PRINTER_ATTRIBUTES)
request.operation["printer-uri"] = ("uri", 
                                    cups.identifierToURI("printers", "HP2100"))
for attribute in ("printer-uri-supported",                                     
                  "printer-type",
                  "member-uris") :
    request.operation["requested-attributes"] = ("nameWithoutLanguage", attribute)
    
answer = request.doRequest()    
print answer
--- CUT ---

Of course several parameters can be used to customize things a bit 
if the default values (e.g. http://localhost:631 for server) are not 
what you want. 

The long term goal is to implement most of the CUPS' API, but currently
only getDefault() and getJobAttributes(jobid) are fully implemented...

Any comment is more than welcome.
Any help is more than welcome.

bye

Jerome Alet





More information about the cups-devel mailing list