pycups
This page is about the Python bindings for the CUPS API, known as pycups. It was written for use with system-config-printer, but can be put to other uses as well.
I work on this module as part of my job at Red Hat.
Download
Download tarball releases from:
http://cyberelk.net/tim/data/pycups/
or from the Python Package Index:
http://pypi.python.org/pypi/pycups
Source Code
Fetch the source like this:
git clone git://git.fedorahosted.org/git/pycups.git
or browse it using gitweb.
New releases are announced at freshmeat.
Documentation
Documentation is produced using epydoc and hosted at the pycups PyPI page.
Bug Reporting
Report bugs using the trac interface.
Discussion
Discussion of pycups is welcome on the system-config-printer mailing list.
[...] just heard that pycups is now included in Debian unstable as python-cups. Thanks to Otavio Salvador for packaging and [...]
Hey Tim,
trying to use pycups on RHEL5 but can’t even get it to build. I get the following;
[root@gbwtecsuv1008 pycups-1.9.24]# python setup.py install
running install
running build
running build_ext
building ‘cups’ extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c cupsmodule.c -o build/temp.linux-i686-2.4/cupsmodule.o
cupsmodule.c: In function ‘cups_require’:
cupsmodule.c:242: error: ‘VERSION’ undeclared (first use in this function)
cupsmodule.c:242: error: (Each undeclared identifier is reported only once
cupsmodule.c:242: error: for each function it appears in.)
cupsmodule.c:272: error: expected ‘)’ before ‘VERSION’
error: command ‘gcc’ failed with exit status 1
Any hints?
Also, in the setup the package is referred to as “cups” rather than “pycups” which will result in an RPM being produced called cups-1.0 which isn’t what you want (I assume).
TIA
Cheers
Dan
Dan: run ‘make’ to build pycups — the VERSION macro comes from the environment set up by the Makefile.
For packaging, I use ‘cups’ for the name because I want to import the extension with ‘import cups’.
[...] about to start writing some proper API documentation for pycups, and I’ve been looking around for short-cuts. Seems like epydoc is just what I’m after, [...]
Now at OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/ports/print/py-cups/
Now in mandriva too :
http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/python-cups/
Is there any example code for pycups / python-cups?
Yes, it is used extensively by system-config-printer, in particular the cupshelpers.py file.
There is also documentation for it included in the pycups source tarball: try ‘make doc’.
[...] goodbye to back button woes couldn’t be easier… Just install pycups (from the same developer), pygtk, and the nifty little system-config-printer app found here. There is a little more doc on [...]
I went to the trac site to create a bug report, but couldn’t figure out how to create an account there. I eventually found my way here in case others want to submit a bug.
Hi,
After making the application if I run the example I get: undefined symbol: libiconv. I have libiconv 2.4.0 installed
Any idea?
pycups doesn’t use the symbol ‘libiconv’ directly, however it does use ‘iconv’, ‘iconv_open’, and ‘iconv_close’. These are POSIX.1-2001 functions, so should be provided by your C library (for instance, GNU glibc provides them).
Your source does not build on Mac OS X. Here is a patch.
Btw, there are C libraries other than glibc…
Makefile.diff
14c14
env LDFLAGS=-liconv CFLAGS=-DVERSION=\\\”$(VERSION)\\\” python setup.py build
cupsppd.c.diff
25a26
> #include
54a56,65
> char *
> strndup(char *src, size_t n)
> {
> char *dst = malloc(n);
>
> if (!dst)
> exit(1);
> return strncpy(dst, src, n);
> }
>
480,481c491
file);
if (!fgets(line, linelen, self->file))
I think your patch has been broken during transit. Please submit patches in unified diff format (i.e. diff -u), preferably from ‘git format-patch’, using the trac interface or normal email.
However, for this particular case it looks like it needs an autoconf check, which means that it needs to start using autoconf.
I would prefer to email the patch but I can’t seem to find your email.
However, the modifications I made to the Makefile regarding libiconv seem to have been futile. Python throws the following error when I try cupstree.py
(right after running make install):
Traceback (most recent call last):
File “pycups-1.9.30/cupstree.py”, line 2, in
import cups
ImportError: dlopen(/usr/local/lib/python2.6/site-packages/cups.so, 2): Symbol not found: _libiconv
Referenced from: /usr/local/lib/python2.6/site-packages/cups.so
Expected in: dynamic lookup
I noticed that I was able to import cups if I launched python while standing in the source directory where the freshly build cups.so can be found. So I manually copied cups.so to /usr/local/lib/python2.6/site-packages and now I am able to import cups regardless of where it’s started from. Indeed, running cmp on the cups.so that is created by make install and the cups.so that is created by make shows the files are not identical:
> cmp /usr/local/lib/python2.6/site-packages/cups.so /Users/kajic/stuff/kek/pycups-1.9.30/cups.so
/usr/local/lib/python2.6/site-packages/cups.so /Users/kajic/stuff/kek/pycups-1.9.30/cups.so differ: char 17, line 1
How can this be?
I realize I am probably missing out on something but why isn’t it possible to add jobs using pycups? I would very much like to be able to do this and I’ve looked through the pycups documentation but I can’t find an addJob or equivalent method. Right now I am using os.execv and “lp” to add jobs but I would very much like to avoid that. Perhaps there is some other library I could use to add jobs?
Robert: use cups.Connection.printFile()/printFiles() to do that.
cups.require(“1.9.39″)
Thanks again! I was using 1.9.30
Here are some notes on what I had to do to sucessfully install 1.9.45 (Max OS X 10.5.6):
In cupsppd.c I had to remove the #ifdef __SVR4 on line 510 (and 528) because otherwise gcc gave the following warning:
cupsppd.c:557: warning: implicit declaration of function ‘getline’
and when importing cups in python I got the following error:
>>> import cups
Traceback (most recent call last):
File “”, line 1, in
ImportError: dlopen(/usr/local/lib/python2.6/site-packages/cups.so, 2): Symbol not found: _getline
Referenced from: /usr/local/lib/python2.6/site-packages/cups.so
Expected in: dynamic lookup
Furthermore I had to add LDFLAGS=-liconv to line 12 in the Makefile. Then after a make and make install I had to manually copy cups.so from the source directory to its install location:
sudo cp pycups-1.9.45/cups.so /usr/local/lib/python2.6/site-packages/cups.so
Indeed, as I said in a previous post, pycups-1.9.45/cups.so and pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so seem to differ:
> cmp pycups-1.9.45/cups.so pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so
pycups-1.9.45/cups.so pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so differ: char 17, line 1
I hope this can be of some help to others.
I would very much like to avoid that. Perhaps there is some other library I could use to add jobs?
JohnT: are you talking about on Mac OS X? You can use libcups directly, of course.