Metadata-Version: 2.0
Name: pycups-notify
Version: 0.0.2
Summary: Notification system for the pycups library.
Home-page: https://github.com/anxuae/pycups-notify
Author: Antoine Rousseaux
Author-email: UNKNOWN
License: MIT license
Download-URL: https://github.com/anxuae/pycups-notify/archive/0.0.2.tar.gz
Description-Content-Type: text/x-rst
Keywords: printer,CUPS
Platform: unix
Platform: linux
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Other Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Natural Language :: English
Classifier: Topic :: Printing
Requires-Dist: pycups (>=1.9.73)

.. image:: https://raw.githubusercontent.com/anxuae/pycups-notify/master/docs/pycups-notify.png
   :align: center
   :alt: pycups-notify


The ``pycups-notify`` library is an extension to the `pycups <https://github.com/OpenPrinting/pycups>`_
one. It enables subscription to CUPS RSS notifications.

This library implements the `Event notify <http://www.marco.panizza.name/dispenseTM/slides/exerc/eventnotify/eventnotify.html>`_
pattern to match with the `design description <https://www.cups.org/doc/spec-design.html>`_
of the CUPS server.


Install
-------

::

     $> pip install pycups-notify


Usage
-----

.. code-block:: python

    import time
    import cups
    from cups_notify import Subscriber

    def on_event(evt):
        print(evt)

    # Create a CUPS connection
    conn = cups.Connection()

    # Create a new subscriber
    sub = Subscriber(conn)

    # Subscribe the callback to all CUPS events
    sub.subscribe(on_event)

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        sub.stop()

It is possible to define a list of events on which the callback is binded:

.. code-block:: python

    import cups
    from cups_notify import Subscriber, event

    def my_callback(evt):
        print(evt.title, evt.description)

    # Create a new subscriber
    sub = Subscriber(cups.Connection())

    # Subscribe the callback
    sub.subscribe(my_callback, [event.CUPS_EVT_JOB_CREATED,
                                event.CUPS_EVT_JOB_COMPLETED,
                                event.CUPS_EVT_JOB_STOPPED])

If the CUPS server is not running on the same computer as the subscriber application
one, the local IP address (same network than the CUPS server) have to be provided to
the subscriber class:

.. code-block:: python

    # Create a CUPS connection
    cups.setServer('198.20.34.1')
    conn = cups.Connection()

    # Create a new subscriber
    sub = Subscriber(conn, '198.20.34.26')


Run
---

A simple listener can be started by typing the following command line::

     $> pycups-notify


