Merge lp:~matthew-earl/endroid/endroid into lp:endroid

Proposed by Matthew Earl
Status: Merged
Approved by: Martin Morrison
Approved revision: 40
Merged at revision: 40
Proposed branch: lp:~matthew-earl/endroid/endroid
Merge into: lp:endroid
Diff against target: 159 lines (+94/-6)
6 files modified
bin/endroid_cat (+4/-0)
bin/endroid_echo (+4/-0)
bin/endroid_remote (+77/-6)
bin/endroid_tee (+4/-0)
debian/endroid.install (+3/-0)
doc/wiki/Reference (+2/-0)
To merge this branch: bzr merge lp:~matthew-earl/endroid/endroid
Reviewer Review Type Date Requested Status
ChrisD Approve
Review via email: mp+180347@code.launchpad.net

Commit message

Add tee/cat equivalents of endroid_echo

Description of the change

Add tee/cat equivalents of endroid_echo

To post a comment you must log in.
Revision history for this message
ChrisD (gingerchris) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/endroid_cat'
2--- bin/endroid_cat 1970-01-01 00:00:00 +0000
3+++ bin/endroid_cat 2013-08-15 13:51:45 +0000
4@@ -0,0 +1,4 @@
5+#!/usr/bin/env bash
6+
7+endroid_remote cat $@
8+
9
10=== added file 'bin/endroid_echo'
11--- bin/endroid_echo 1970-01-01 00:00:00 +0000
12+++ bin/endroid_echo 2013-08-15 13:51:45 +0000
13@@ -0,0 +1,4 @@
14+#!/usr/bin/env bash
15+
16+endroid_remote echo $@
17+
18
19=== renamed file 'bin/endroid_echo' => 'bin/endroid_remote'
20--- bin/endroid_echo 2013-08-09 11:45:04 +0000
21+++ bin/endroid_remote 2013-08-15 13:51:45 +0000
22@@ -1,4 +1,4 @@
23-#!/usr/bin/python
24+#!/usr/bin/env python
25
26 import os
27 import sys
28@@ -11,9 +11,80 @@
29 class UserError(Exception):
30 pass
31
32+class UsageError(UserError):
33+ def __init__(self):
34+ usage_lines = ["Usage:"]
35+
36+ for cls in mode_classes.values():
37+ usage_lines.append(" {bin} {cmd} {usage}".format(
38+ bin=sys.argv[0], cmd=cls.cmd, usage=cls.usage))
39+ usage_lines.append(" " + cls.help)
40+
41+ super(UsageError, self).__init__('\n'.join(usage_lines))
42+
43+class Mode(object):
44+ pass
45+
46+class Tee(Mode):
47+ cmd = 'tee'
48+ usage = ''
49+ help = ('Read lines from stdin, print them to stdout and send them to '
50+ 'EnDroid.')
51+
52+ def __init__(self, args):
53+ if len(args) > 0:
54+ raise UsageError()
55+
56+ def get_message(self):
57+ msg = ""
58+
59+ line = sys.stdin.readline()
60+ while line:
61+ sys.stdout.write(line)
62+ sys.stdout.flush()
63+ msg += line
64+
65+ line = sys.stdin.readline()
66+
67+ return msg
68+
69+class Echo(Mode):
70+ cmd = 'echo'
71+ usage = ' <message>'
72+ help = 'Send <message> to EnDroid.'
73+
74+ def __init__(self, args):
75+ if len(args) > 1:
76+ raise UsageError()
77+ self.msg = ' '.join(args)
78+
79+ def get_message(self):
80+ return self.msg
81+
82+class Cat(Mode):
83+ cmd = 'cat'
84+ usage = ''
85+ help = 'Read lines from stdin and send them to EnDroid.'
86+
87+ def __init__(self, args):
88+ if len(args) > 0:
89+ raise UsageError()
90+
91+ def get_message(self):
92+ return sys.stdin.read()
93+
94+mode_classes = dict((cls.cmd, cls) for cls in (Tee, Echo, Cat))
95+
96 try:
97 if len(sys.argv) < 2:
98- raise UserError("Usage: %s <Message>" % sys.argv[0])
99+ raise UsageError()
100+
101+ try:
102+ mode_class = mode_classes[sys.argv[1]]
103+ except KeyError:
104+ raise UsageError()
105+
106+ mode = mode_class(sys.argv[2:])
107
108 if JID_ENV_VAR not in os.environ:
109 raise UserError("Target user env var (%s) not set" % JID_ENV_VAR)
110@@ -23,10 +94,10 @@
111
112 if URL_ENV_VAR not in os.environ:
113 raise UserError("Endroid URL env var (%s) not set" % URL_ENV_VAR)
114-
115- params = {'user': os.environ[JID_ENV_VAR],
116- 'key': os.environ[KEY_ENV_VAR],
117- 'message': ' '.join(sys.argv[1:])}
118+
119+ params = {'user': os.environ[JID_ENV_VAR],
120+ 'key': os.environ[KEY_ENV_VAR],
121+ 'message': mode.get_message()}
122
123 f = urllib.urlopen(os.environ[URL_ENV_VAR], urllib.urlencode(params))
124 for line in f.readlines():
125
126=== added file 'bin/endroid_tee'
127--- bin/endroid_tee 1970-01-01 00:00:00 +0000
128+++ bin/endroid_tee 2013-08-15 13:51:45 +0000
129@@ -0,0 +1,4 @@
130+#!/usr/bin/env bash
131+
132+endroid_remote tee $@
133+
134
135=== modified file 'debian/endroid.install'
136--- debian/endroid.install 2013-08-14 10:00:18 +0000
137+++ debian/endroid.install 2013-08-15 13:51:45 +0000
138@@ -2,6 +2,9 @@
139 etc/endroid.conf usr/share/doc/endroid/examples/
140 etc/init/endroid.conf etc/init/
141 bin/endroid usr/bin/
142+bin/endroid_remote usr/bin/
143 bin/endroid_echo usr/bin/
144+bin/endroid_cat usr/bin/
145+bin/endroid_tee usr/bin/
146 lib/wokkel-0.7.1-py2.7.egg usr/lib/endroid/dependencies
147 var/endroid.db var/lib/endroid/db
148
149=== modified file 'doc/wiki/Reference'
150--- doc/wiki/Reference 2013-08-14 09:56:14 +0000
151+++ doc/wiki/Reference 2013-08-15 13:51:45 +0000
152@@ -531,6 +531,8 @@
153 "message_here" to the user with JID {{{ENDROID_REMOTE_USER}}} provided that they have enabled the remote plugin (by typing {{{allow remote}}} to !EnDroid and receiving their key in response) and that
154 {{{ENDROID_REMOTE_KEY}}} matches the user's remote plugin key. The default value for {{{ENDROID_REMOTE_URL}}} would be {{{http://127.0.0.1:8880/remote/}}} .
155
156+In addition {{{endroid_cat}}} and {{{endroid_tee}}} scripts are provided which redirect {{{stdin}}} to EnDroid. {{{endroid_tee}}} also prints input to stdout, whilst {{{endroid_cat}}} consumes all input.
157+
158
159 == Patternmatcher ==
160

Subscribers

People subscribed via source and target branches