root / pkipplib / trunk / notifiers / samplenotifier @ 35

Revision 35, 1.4 kB (checked in by jerome, 18 years ago)

Documents samplenotifier.

  • Property svn:executable set to *
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3#
4
5"""This command can be placed in /usr/lib/cups/notifier and
6used as the notifications' recipient when creating IPP subscriptions.
7
8It will automatically ensures that each time a printer is added or
9removed from CUPS it is also added or removed from PyKota's database.
10
11IMPORTANT : because of a bug in CUPS 1.2.1, this command only works
12the first time a notification is sent."""
13
14import sys
15import os
16import fcntl
17
18from pkipplib import pkipplib
19
20if __name__ == "__main__" :
21    #
22    # First thing we do is put stdin in non-blocking mode.
23    fd = sys.stdin.fileno()
24    fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, 
25                    fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
26
27    # then we read the notification CUPS sent us to our stdin
28    notification = pkipplib.IPPRequest(sys.stdin.read())
29   
30    # now we parse it
31    notification.parse()
32   
33    # then we act one way or another, depending on the event received.
34    event = notification.event_notification["notify-subscribed-event"][0][1]
35    if event in ("printer-added", "printer-deleted") :
36        printername = notification.event_notification["printer-name"][0][1]
37        if event.endswith("-added") :
38            action = "add"
39        else :   
40            action = "delete"
41        os.system('/usr/bin/pkprinters --%s "%s"' % (action, printername))
Note: See TracBrowser for help on using the browser.