- Timestamp:
- 06/24/06 15:28:19 (18 years ago)
- Location:
- pkipplib/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pkipplib/trunk/bin/cupssubscribe
r29 r30 21 21 # $Id$ 22 22 23 """cupssubscribe is a command line tool which can be used to create 24 or delete IPP subscriptions.""" 25 23 26 import sys 24 27 import locale … … 37 40 except : 38 41 gettext.NullTranslations().install() 39 parser = optparse.OptionParser(usage="cupssubscribe [options] ")42 parser = optparse.OptionParser(usage="cupssubscribe [options] [subscriptions ids]") 40 43 parser.add_option("-v", "--version", 41 44 action="store_true", … … 50 53 dest="debug", 51 54 help=_("activate debug mode.")) 55 parser.add_option("-X", "--delete", 56 action="store_true", 57 dest="delete", 58 help=_("deletes subscriptions.")) 52 59 parser.add_option("-p", "--printer", 53 60 dest="printer", … … 94 101 print "cupssubscribe v%(__version__)s" % globals() 95 102 else : 96 if not options.events :103 if not options.events and not options.delete : 97 104 sys.stderr.write(_("You MUST pass a list of events to subscribe to.\n")) 98 elif not options.cups : 99 sys.stderr.write(_("You MUST pass an URL to the CUPS server.\n")) 100 elif not options.recipient : 105 elif not options.recipient and not options.delete : 101 106 sys.stderr.write(_("You MUST pass a recipient for the subscription.\n")) 107 elif options.delete and not arguments : 108 sys.stderr.write(_("You MUST pass a subscriptions ids at the end of your command line.\n")) 102 109 else : 103 110 cups = pkipplib.CUPS(options.cups, … … 114 121 else : 115 122 url = baseurl 116 answer = cups.createSubscription(url, 117 [e.strip() for e in options.events.split(",")], 118 userdata=options.userdata, 119 recipient=options.recipient, 120 pullmethod=options.pullmethod, 121 charset=options.charset, 122 naturallanguage=options.language, 123 leaseduration=options.duration, 124 timeinterval=options.interval, 125 jobid=options.job) 126 try : 127 subscriptionid = answer.subscription["notify-subscription-id"][0][1] 128 except KeyError : 129 sys.stderr.write("%s\n" % answer.operation["status-message"][0][1]) 130 else : 131 print "Subscription %i registered." % subscriptionid 123 if not options.delete : 124 answer = cups.createSubscription(url, 125 [e.strip() for e in options.events.split(",")], 126 userdata=options.userdata, 127 recipient=options.recipient, 128 pullmethod=options.pullmethod, 129 charset=options.charset, 130 naturallanguage=options.language, 131 leaseduration=options.duration, 132 timeinterval=options.interval, 133 jobid=options.job) 134 try : 135 subscriptionid = answer.subscription["notify-subscription-id"][0][1] 136 except KeyError : 137 sys.stderr.write("%s\n" % answer.operation["status-message"][0][1]) 138 else : 139 print "Subscription %i registered." % subscriptionid 140 else : 141 for subid in [int(arg) for arg in arguments] : 142 answer = cups.cancelSubscription(url, subid, options.job) 143 try : 144 error = answer.operation["status-message"][0][1] 145 except KeyError : 146 print "Subscription %i cancelled." % subid 147 else : 148 sys.stderr.write("%s\n" % error) 132 149 -
pkipplib/trunk/pkipplib/pkipplib.py
r28 r30 716 716 timeinterval=None, 717 717 jobid=None) : 718 """Creates a printer or server subscription.""" 719 req = self.newRequest(IPP_CREATE_PRINTER_SUBSCRIPTION) 720 req.operation["printer-uri"] = ("uri", uri) 718 """Creates a job, printer or server subscription.""" 719 if jobid is not None : 720 opid = IPP_CREATE_JOB_SUBSCRIPTION 721 uritype = "job-uri" 722 else : 723 opid = IPP_CREATE_PRINTER_SUBSCRIPTION 724 uritype = "printer-uri" 725 req = self.newRequest(opid) 726 req.operation[uritype] = ("uri", uri) 721 727 for event in events : 722 728 req.subscription["notify-events"] = ("keyword", event) … … 739 745 return self.doRequest(req) 740 746 747 def cancelSubscription(self, uri, subscriptionid, jobid=None) : 748 """Cancels a subscription.""" 749 req = self.newRequest(IPP_CANCEL_SUBSCRIPTION) 750 if jobid is not None : 751 uritype = "job-uri" 752 else : 753 uritype = "printer-uri" 754 req.operation[uritype] = ("uri", uri) 755 req.event_notification["notify-subscription-id"] = ("integer", subscriptionid) 756 return self.doRequest(req) 741 757 742 758 if __name__ == "__main__" :