forked from Qirky/Troop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-client.py
109 lines (73 loc) · 3.6 KB
/
run-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
"""
Troop-Client
------------
Real-time collaborative Live Coding.
- Troop is a real-time collaborative tool that enables group live
coding within the same document. To run the client application it
must be able to connect to a running Troop Server instance on
your network. Running `python run-client.py` will start the process
of connecting to the server by asking for a host and port (defaults
are localhost and port 57890).
- Using other Live Coding Languages:
Troop is designed to be used with FoxDot (http://foxdot.org) but
is also configured to work with Tidal Cycles (http://tidalcycles.org).
You can run this file with the `--mode` flag followed by "tidalcycles"
to use the Tidal Cycles language. You can also use any other application
that can accept code commands as strings via the stdin by specifying
the path of the interpreter application, such as ghci in the case of
Tidal Cycles, in place of the "tidalcycles" string when using the
`--mode` flag.
"""
import argparse
parser = argparse.ArgumentParser(
prog="Troop Client",
description="Collaborative interface for Live Coding")
parser.add_argument('-i', '--cli', action='store_true', help="Use the command line to enter connection info")
parser.add_argument('-p', '--public', action='store_true', help="Connect to public Troop server")
parser.add_argument('-H', '--host', action='store', help="IP Address of the machine running the Troop server")#, default="localhost")
parser.add_argument('-P', '--port', action='store', help="Port for Troop server (default 57890)")#, default=57890)
parser.add_argument('-m', '--mode', action='store', default='foxdot',
help='Name of live coding language (TidalCycles, SonicPi, SuperCollider, FoxDot, None, or a valid executable')
parser.add_argument('-a', '--args', action='store', help="Add extra arguments to supply to the interpreter", nargs=argparse.REMAINDER, type=str)
parser.add_argument('-c', '--config', action='store_true', help="Load connection info from 'client.cfg'")
parser.add_argument('-l', '--log', action='store_true')
args = parser.parse_args()
# Set up client
from src.client import Client
from src.config import readin
from getpass import getpass
# Client config options
options = { 'lang': args.mode, 'logging': args.log }
if args.public:
from src.config import PUBLIC_SERVER_ADDRESS
options['host'], options['port'] = PUBLIC_SERVER_ADDRESS
if args.host:
options['host'] = args.host
if args.port:
options['port'] = args.port
if args.cli:
if 'host' not in options:
options['host'] = readin("Troop Server Address", default="localhost")
if 'port' not in options:
options['port'] = readin("Port Number", default="57890")
options['name'] = readin("Enter a name").replace(" ", "_")
options['password'] = getpass()
options['get_info'] = False # Flag to say we don't need the GUI
elif args.config:
import os.path
if os.path.isfile('client.cfg'):
"""
You can set a configuration file if you are connecting to the same
server on repeated occasions. A password should not be stored. The
file (client.cfg) should look like:
host=<host_ip>
port=<port_no>
"""
options.update(Client.read_configuration_file('client.cfg'))
else:
print("Unable to load configuration from 'client.cfg'")
# Store any extra arguments to supply to the interpreter
if args.args:
options['args'] = args.args
myClient = Client(**options)