Changeset 19 for pkipplib

Show
Ignore:
Timestamp:
05/22/06 21:48:26 (18 years ago)
Author:
jerome
Message:

The README now include setup documentation and examples of use.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkipplib/trunk/README

    r15 r19  
    1818Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 
    1919 
     20======================================================================= 
     21 
     22This software is a Python library which can prepare IPP requests with 
     23the help of a somewhat high level API. These requests can then be sent 
     24to an IPP printer or print server (e.g. CUPS). 
     25 
     26This library can also parse IPP answers received, and create high 
     27level Python objects from them. 
     28 
     29Both of these actions can be done through an IPPRequest class 
     30and its instance methods. 
     31 
     32Finally, a CUPS class can be leveraged to easily deal with CUPS  
     33print servers. 
     34 
     35All of this library being written in the Python language, there's 
     36no need to link the code with the CUPS' API, which makes it 
     37independant of the CUPS version being installed. 
     38 
     39======================================================================= 
     40 
     41Installation : 
     42-------------- 
     43 
     44        1 - Grab the latest version of this library from : 
     45         
     46            http://www.pykota.com/software/pkipplib/ 
     47             
     48        2 - Extract the tarball :     
     49         
     50            $ tar -zxf pkipplib-x.yy.tar.gz 
     51             
     52        3 - Install the Python module :     
     53         
     54            $ cd pkipplib-x.yy 
     55            $ python setup.py install 
     56 
     57NB : for the installation script to work, you need to install 
     58the python-dev package on your system first. 
     59 
     60======================================================================= 
     61 
     62Examples : 
     63---------- 
     64 
     65--- CUT --- 
     66# Parsing.py    EXAMPLE 
     67from pkipplib import pkipplib 
     68 
     69# Read IPP datas from a CUPS job control file 
     70myfile = open("/var/spool/cups/c00155") 
     71ippdatas = myfile.read() 
     72myfile.close() 
     73 
     74# Parse these datas 
     75request = pkipplib.IPPRequest(ippdatas) 
     76request.parse() 
     77 
     78# Print the whole result as a string 
     79print request 
     80 
     81# Access one of the job's attributes directly  
     82print request.job["job-name"] 
     83--- CUT --- 
     84 
     85 
     86--- CUT --- 
     87# Building.py   EXAMPLE 
     88from pkipplib import pkipplib 
     89 
     90# Create a CUPS_GET_DEFAULT request 
     91request = pkipplib.IPPRequest(operation_id=pkipplib.CUPS_GET_DEFAULT) 
     92request.operation["attributes-charset"] = ("charset", "utf-8") 
     93request.operation["attributes-natural-language"] = ("naturalLanguage", "en-us") 
     94 
     95# Get the request as binary datas 
     96ippdatas = request.dump() 
     97 
     98# Parse these datas back 
     99newrequest = pkipplib.IPPRequest(ippdatas) 
     100newrequest.parse() 
     101 
     102# Of course, the result of parsing matches what we created before. 
     103print newrequest.operation["attributes-natural-language"] 
     104--- CUT --- 
     105 
     106 
     107--- CUT --- 
     108# CUPS' API 
     109from pkipplib import pkipplib 
     110 
     111# By default, connects to http://localhost:631 
     112cups = pkipplib.CUPS() 
     113 
     114# High level API : retrieve info about job 3 : 
     115answer = cups.getJobAttributes(3) 
     116print answer.job["document-format"] 
     117# That's all folks ! 
     118 
     119# Lower level API : 
     120request = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES) 
     121request.operation["printer-uri"] = ("uri",  
     122                                    cups.identifierToURI("printers", "HP2100")) 
     123for attribute in ("printer-uri-supported",                                      
     124                  "printer-type", 
     125                  "member-uris") : 
     126    # IMPORTANT : here, despite the unusual syntax, we append to               
     127    # the list of requested attributes : 
     128    request.operation["requested-attributes"] = ("nameWithoutLanguage", attribute) 
     129     
     130# Sends this request to the CUPS server     
     131answer = request.doRequest()     
     132 
     133# Print the answer as a string of text 
     134print answer 
     135--- CUT --- 
     136 
     137======================================================================= 
     138 
     139Please email bug reports, enhancements or comments to : alet@librelogiciel.com