| 20 | ======================================================================= |
| 21 | |
| 22 | This software is a Python library which can prepare IPP requests with |
| 23 | the help of a somewhat high level API. These requests can then be sent |
| 24 | to an IPP printer or print server (e.g. CUPS). |
| 25 | |
| 26 | This library can also parse IPP answers received, and create high |
| 27 | level Python objects from them. |
| 28 | |
| 29 | Both of these actions can be done through an IPPRequest class |
| 30 | and its instance methods. |
| 31 | |
| 32 | Finally, a CUPS class can be leveraged to easily deal with CUPS |
| 33 | print servers. |
| 34 | |
| 35 | All of this library being written in the Python language, there's |
| 36 | no need to link the code with the CUPS' API, which makes it |
| 37 | independant of the CUPS version being installed. |
| 38 | |
| 39 | ======================================================================= |
| 40 | |
| 41 | Installation : |
| 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 | |
| 57 | NB : for the installation script to work, you need to install |
| 58 | the python-dev package on your system first. |
| 59 | |
| 60 | ======================================================================= |
| 61 | |
| 62 | Examples : |
| 63 | ---------- |
| 64 | |
| 65 | --- CUT --- |
| 66 | # Parsing.py EXAMPLE |
| 67 | from pkipplib import pkipplib |
| 68 | |
| 69 | # Read IPP datas from a CUPS job control file |
| 70 | myfile = open("/var/spool/cups/c00155") |
| 71 | ippdatas = myfile.read() |
| 72 | myfile.close() |
| 73 | |
| 74 | # Parse these datas |
| 75 | request = pkipplib.IPPRequest(ippdatas) |
| 76 | request.parse() |
| 77 | |
| 78 | # Print the whole result as a string |
| 79 | print request |
| 80 | |
| 81 | # Access one of the job's attributes directly |
| 82 | print request.job["job-name"] |
| 83 | --- CUT --- |
| 84 | |
| 85 | |
| 86 | --- CUT --- |
| 87 | # Building.py EXAMPLE |
| 88 | from pkipplib import pkipplib |
| 89 | |
| 90 | # Create a CUPS_GET_DEFAULT request |
| 91 | request = pkipplib.IPPRequest(operation_id=pkipplib.CUPS_GET_DEFAULT) |
| 92 | request.operation["attributes-charset"] = ("charset", "utf-8") |
| 93 | request.operation["attributes-natural-language"] = ("naturalLanguage", "en-us") |
| 94 | |
| 95 | # Get the request as binary datas |
| 96 | ippdatas = request.dump() |
| 97 | |
| 98 | # Parse these datas back |
| 99 | newrequest = pkipplib.IPPRequest(ippdatas) |
| 100 | newrequest.parse() |
| 101 | |
| 102 | # Of course, the result of parsing matches what we created before. |
| 103 | print newrequest.operation["attributes-natural-language"] |
| 104 | --- CUT --- |
| 105 | |
| 106 | |
| 107 | --- CUT --- |
| 108 | # CUPS' API |
| 109 | from pkipplib import pkipplib |
| 110 | |
| 111 | # By default, connects to http://localhost:631 |
| 112 | cups = pkipplib.CUPS() |
| 113 | |
| 114 | # High level API : retrieve info about job 3 : |
| 115 | answer = cups.getJobAttributes(3) |
| 116 | print answer.job["document-format"] |
| 117 | # That's all folks ! |
| 118 | |
| 119 | # Lower level API : |
| 120 | request = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES) |
| 121 | request.operation["printer-uri"] = ("uri", |
| 122 | cups.identifierToURI("printers", "HP2100")) |
| 123 | for 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 |
| 131 | answer = request.doRequest() |
| 132 | |
| 133 | # Print the answer as a string of text |
| 134 | print answer |
| 135 | --- CUT --- |
| 136 | |
| 137 | ======================================================================= |
| 138 | |
| 139 | Please email bug reports, enhancements or comments to : alet@librelogiciel.com |