diff options
author | David Robillard <d@drobilla.net> | 2012-05-09 16:06:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-09 16:06:59 +0000 |
commit | 6932da9169a38a5a8eafc63357b9ede00cb46117 (patch) | |
tree | f2a9d02d7c82c859db334dfcb3b6060cfc8bac07 /scripts | |
parent | ed80c779a6085ce62b9f61a28263607983db93a1 (diff) | |
download | ingen-6932da9169a38a5a8eafc63357b9ede00cb46117.tar.gz ingen-6932da9169a38a5a8eafc63357b9ede00cb46117.tar.bz2 ingen-6932da9169a38a5a8eafc63357b9ede00cb46117.zip |
Support TCP sockets.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4328 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/ingenish | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/scripts/ingenish b/scripts/ingenish index 9e49c271..a142a392 100755 --- a/scripts/ingenish +++ b/scripts/ingenish @@ -19,16 +19,24 @@ import shlex import socket import sys import time - +import re try: import readline except: pass class Client: - def __init__(self, path='/tmp/ingen.sock'): - self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self.sock.connect(path) + def __init__(self, uri='unix:///tmp/ingen.sock'): + print 'Connecting to server %s' % uri + if uri.startswith('unix://'): + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock.connect(uri[len('unix://'):]) + elif uri.startswith('tcp://'): + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + parsed = re.split('[:/]', uri[len('tcp://'):]) + addr = (parsed[0], int(parsed[1])) + print addr + self.sock.connect(addr) def __del__(self): self.sock.close() @@ -99,13 +107,17 @@ class Client: ''' % (path)) def print_usage(): - print('''Usage: ingenish COMMAND [ARGUMENT]... - ingenish + print('''Usage: ingenish [OPTION]... [COMMAND [ARGUMENT]...] A command line interface to an Ingen server. A command can be given directly on the command line, or when run with no arguments an interactive shell is launched. +Options: + -s ADDRESS The address of the Ingen server. Default is the local server + at unix:///tmp/ingen.sock but remote servers can be used with + an address like tcp:///my-ingen-server-host:16180 + Commands: put PATH TURTLE_FRAGMENT set PATH TURTLE_FRAGMENT @@ -130,8 +142,6 @@ Example: ingenish set /tone/output 'ingen:value 0.7' ''') -ingen = Client() - def run(cmd): if cmd[0] == 'help': print_usage() @@ -150,7 +160,19 @@ def run(cmd): else: return False -if len(sys.argv) == 1: +a = 1 +server = 'unix:///tmp/ingen.sock' +if len(sys.argv) > 1: + if sys.argv[a] == '-s': + server = sys.argv[a + 1] + a = a + 2 + elif sys.argv[a][0] == '-': + print_usage() + sys.exit(1) + +ingen = Client(server) + +if len(sys.argv) - a == 0: while True: try: run(shlex.split(raw_input('> '))) @@ -159,8 +181,7 @@ if len(sys.argv) == 1: break except: print('error: %s' % sys.exc_info()[0]) -elif run(sys.argv[1:]): - sys.exit(0) else: - print_usage() - sys.exit(1) + if not run(sys.argv[1:]): + print_usage() + sys.exit(1) |