From: Eric S. Raymond Date: Sat, 30 Nov 2013 20:00:00 +0000 (-0500) Subject: Clean up and document immediate mode. X-Git-Tag: 2.3~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3170384c16c815cf3a2ac2e170fe91c9ee77a9bf;p=irker.git Clean up and document immediate mode. --- diff --git a/NEWS b/NEWS index 4a80c8f..bcf564c 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ irker history +Repository head: + -i option enables immediate sending of one line in foreground. + 2.2 @ 2013-11-29 Fixed Unicode processing - got busted in 2.0 when irclib was removed. Show Python traceback on higher debug levels. diff --git a/irk b/irk deleted file mode 100755 index 6307d65..0000000 --- a/irk +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# Illustrates how to test irkerd. -# -# First argument must be a channel URL. If it does not begin with "irc", -# the base URL for freenode is prepended. -# -# -k option kills irkerd if irk hard to spawn one. -# -# Second argument must be a payload string. Standard C-style escapes -# such as \n and \t are decoded. -# -import json -import socket -import sys -import fileinput -import subprocess -import time -import os -import signal -import getopt - -def send(target, message): - data = {"to": target, "privmsg" : message} - #print(json.dumps(data)) - try: - s = socket.create_connection(("localhost", 6659)) - s.sendall(json.dumps(data)) - except socket.error, e: - sys.stderr.write("irkerd: write to server failed: %r\n" % e) - -if __name__ == "__main__": - (options, arguments) = getopt.getopt(sys.argv[1:], "k", ) - killafter = False - for (opt, val) in options: - if opt == '-k': - killafter = True - - # Spawn an irkerd instance if none is running. - try: - # irkerd might already be running - s = socket.create_connection(("localhost", 6659)) - irkerd = None - except: - # If it isn't, spawn an instance - print "Spawning an irker instance..." - irkerd = subprocess.Popen("irkerd", shell=True, preexec_fn=os.setsid) - time.sleep(0.5) - - target = arguments[0] - if not "irc:" in target: - target = "irc://chat.freenode.net/{0}".format(target) - message = " ".join(arguments[1:]) - message = message.decode('string_escape') - if message == '-': - for line in fileinput.input('-'): - send(target, line.rstrip('\n')) - else: - send(target, message) - if killafter: - if irkerd: - time.sleep(0.5) - # Magic required because shell=True, terminate() won't work. - os.killpg(irkerd.pid, signal.SIGTERM) - print "...terminated." diff --git a/irkerd b/irkerd index 1484af7..86f10c6 100755 --- a/irkerd +++ b/irkerd @@ -828,13 +828,14 @@ class IrkerUDPHandler(SocketServer.BaseRequestHandler): def usage(): sys.stdout.write(""" Usage: - irkerd [-d debuglevel] [-l logfile] [-n nick] [-p password] [-V] [-h] + irkerd [-d debuglevel] [-l logfile] [-n nick] [-p password] [-i channel message] [-V] [-h] Options -d set debug level -l set logfile -n set nick-style -p set nickserv password + -i immediate mode -V return irkerd version -h print this help dialog """) @@ -875,8 +876,7 @@ if __name__ == '__main__': def bailout(): raise SystemExit, 1 irker.irc.add_event_handler("quit", lambda _c, _e: bailout()) - (to, privmsg) = val.split(",") - irker.handle('{"to":"%s","privmsg":"%s"}' % (to, privmsg), quit_after=True) + irker.handle('{"to":"%s","privmsg":"%s"}' % (immediate, arguments[0]), quit_after=True) irker.irc.spin() else: irker.thread_launch() diff --git a/irkerd.xml b/irkerd.xml index 0638a6e..2a6c1bb 100644 --- a/irkerd.xml +++ b/irkerd.xml @@ -22,8 +22,10 @@ -l logfile -n nick -p password + -i ITC-URL -V - -h + -h + message text @@ -108,6 +110,12 @@ password to be used. If given, this password is shipped to authenticate the nick on receipt of a welcome message. +-i +Immediate mode, to be run in foreground. Takes two +following values interpreted as a channel URL and a message +string. Sends the message, then quits. + + -V Write the program version to stdout and terminate.