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.

Comments

86 responses to “pycups”

  1. Michael avatar
    Michael

    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

  2. tim avatar

    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.

  3. Michael avatar
    Michael

    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’

  4. Michael avatar
    Michael

    Could it be due to the fact that I have cups 1.31 and not 1.4 ?

  5. Michael avatar
    Michael

    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 ?

  6. tim avatar

    Both problems also fixed in the git repository now.

  7. Michael avatar
    Michael

    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.

  8. Rogier avatar
    Rogier

    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

  9. tim avatar

    Rogier: you need a newer version of cups or else wait for pycups-1.9.56 which will work around compiling against older versions.

  10. macaronij avatar
    macaronij

    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)…

  11. tim avatar

    Yes, good idea. Or maybe I should make it a bit more like pysmbc and have the full documentation online.

  12. mrbox avatar

    Great lib! After some problems everything works like a charm 🙂

  13. Gowtham avatar
    Gowtham

    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.

  14. tim avatar

    It just needs to behave the same as the libcups function would.

  15. Gowtham avatar
    Gowtham

    One (rather ignorant) question, How do I send you a pull request(like github) for you to check the changes I have made?

  16. tim avatar

    Just let me know the URL to your git repository and I can take a look.

  17. tim avatar

    Thanks. One comment:

    +  char str[80];
    [...]
          fgets (str, 79, tf);
    

    That would be better as:

          fgets (str, sizeof (str), tf);
    

    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.)

  18. Gowtham avatar
    Gowtham

    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

  19. tim avatar

    Thanks. Some warnings when building though:

    upsconnection.c: In function ‘Connection_adminExportSamba’:
    cupsconnection.c:3808:13: warning: ignoring return value of ‘fgets’, declared with
    attribute warn_unused_result [-Wunused-result]
    

    Should really check this.

    cupsconnection.c:3817:8: warning: attempt to free a non-heap object ‘str’ [enabled by default]
    

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.