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.
Download
Download tarball releases from the Python Package Index:
http://pypi.python.org/pypi/pycups
or older releases from:
http://cyberelk.net/tim/data/pycups/
Source Code
The git repository is available at GitHub.
Bug Reporting
Report issues using GitHub.
The package doesn’t build properly on fc10
Here is the output from build:
python setup.py build
running build
running build_ext
building ‘cups’ extension
creating build
creating build/temp.linux-i686-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DVERSION=”1.9.54″ -I/usr/local/include/python2.6 -c cupsmodule.c -o build/temp.linux-i686-2.6/cupsmodule.o
cupsmodule.c: In function ‘do_password_callback’:
cupsmodule.c:155: error: ‘cups_password_callback’ undeclared (first use in this function)
cupsmodule.c:155: error: (Each undeclared identifier is reported only once
cupsmodule.c:155: error: for each function it appears in.)
cupsmodule.c: In function ‘cups_setPasswordCB’:
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
error: command ‘gcc’ failed with exit status 1
make: *** [cups.so] Error 1
Fixed upstream (add “tls->” just before “cups_password_callback” at cupsmodule.c:155).
However, be aware that Fedora 10 is no longer receiving security updates — you should upgrade to a newer version of Fedora.
Hm, it fixed the first error.
The others are still there :
namely the whole
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
Could it be due to the fact that I have cups 1.31 and not 1.4 ?
Ok I removed the 2 lines referring to the cups_password_callback_context and was able to compile.
Now there is another problem when trying to run some package using pycups (namely cloudprint).
ImportError: /usr/local/lib/python2.6/site-packages/cups.so: undefined symbol: cupsGetPPD3
It is most likely due to the fact that I have cups 1.31 .
Any way to force the build so it uses 1.31 ?
Both problems also fixed in the git repository now.
Thanks,
Actually I fixed them myself in the code and recompiled 🙂
I also had a problem with getPPD3 and have to comment out the appropriate functions as well.
Anyway it works fine now with the cloudprint.
I am also getting this ImportError when starting the python cloudprint script:
ImportError: /usr/local/lib/python2.6/site-packages/cups.so: undefined symbol: cupsGetPPD3
Can you point me in the direction where to comment out the appropriate functions so this error will not occur?
My OS is Ubuntu 8.04 server with python 2.6 and pycups-1.9.55 installed.
Thanks
Rogier: you need a newer version of cups or else wait for pycups-1.9.56 which will work around compiling against older versions.
very good work, it could be very helpfull to have an intro / tutorial whit the basic
something very easy just to start using the module
#Connect to CUPS whit the default user
printer = cups.Connection()
#Define the default printer name
default_printer = printer.getDefault()
#Print a Test Page in the default printer
printer.printTestPage(default_printer)
#Print a file whit the default options
printer.printFile(default_printer,”PATH/FILE”,”Title”,{})
perhaps some example adding a printer, etc…
i know it s very noob but it can save some time to a lot of people, i dind’t find any tutorial on the web and didn t know if this module could do the stuff i need until i build it and ask help(cups)…
Yes, good idea. Or maybe I should make it a bit more like pysmbc and have the full documentation online.
Great lib! After some problems everything works like a charm 🙂
Hi Tim,
Thanks for releasing this py binding library. Made my development time much shorter and I didn’t have to put in a lot of effort to write using C library.
I could accomplish most of my tasks using pycups library. However, there is one API component which is available in C library but not exposed through pycups library, i.e cupsAdminExportSamba.
I managed to write the PyObject method to extend pycups library for this API call. But, the major constraint is that this call relies on cups-windows drivers to be available on the local machine alongside with libcups. Now, I am not sure how this fits into the pycups library when there is an additional dependency. Perhaps, you have better idea.
It just needs to behave the same as the libcups function would.
One (rather ignorant) question, How do I send you a pull request(like github) for you to check the changes I have made?
Just let me know the URL to your git repository and I can take a look.
Here the commit to my git repository.
https://github.com/narisipalli/pycups/commit/068357df8a6868ad679ed4941282d64f5d2713d0
Thanks. One comment:
That would be better as:
and perhaps a comment explaining what that file is expected to look like and why the last line is relevant in this situation.
(Note that fgets already leaves space for, and stores, a terminating nul character.)
Thanks for looking into it. Took some time to come back to this, blame on holiday time.
Heres my commit with changes as per your suggestions-
https://github.com/narisipalli/pycups/commit/38911235208055324299a4df6699672528ffccc6
Thanks. Some warnings when building though:
Should really check this.
I didn’t spot this when looking through first of all, but str is declared on the stack so we don’t need to free it.
When I import your git repository it has a separate history of its own instead of branching from mine… isn’t it meant to share a common ancestor?