Changeset 30 for pkipplib/trunk/bin
- Timestamp:
- 06/24/06 15:28:19 (18 years ago)
- Files:
-
- 1 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