forked from Qirky/Troop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-client.py
executable file
·146 lines (94 loc) · 4.39 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p "python3.withPackages (ps: [ps.tkinter])"
"""
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
from src.config import langnames
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")
parser.add_argument('-P', '--port', action='store', help="Port for Troop server (default 57890)")
parser.add_argument('-n', '--name', action='store', help="Display name to use")
parser.add_argument('-m', '--mode', action='store', default='foxdot',
help='Name of live coding language ({}) or a valid executable'.format(', '.join(langnames.keys())))
parser.add_argument('-s', '--syntax', action='store',
help='Name of live coding language syntax to use when selecting "No Interpreter" option.')
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('--hub', help="Connect to a named Troop server running on the Troop Hub Service")
args = parser.parse_args()
# Set up client
from src.client import Client
from src.config import readin
from getpass import getpass
# Language and syntax
options = { 'lang': args.mode }
if args.syntax:
options['syntax'] = args.syntax
# Server address
if args.hub:
from src.hub import HubClient, HubParser
print("Troop Hub Service | Collecting details for '{}'".format(args.hub))
hub = HubParser(args.hub)
address = HubClient(**hub).query(hub.get('name'))
print("Troop Hub Service | Success.")
options['host'], options['port'] = address
elif args.public:
from src.config import PUBLIC_SERVER_ADDRESS
options['host'], options['port'] = PUBLIC_SERVER_ADDRESS
else:
if args.host:
options['host'] = args.host
if args.port:
options['port'] = args.port
# User name
if args.name:
options['name'] = args.name
# Non-gui startup
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")
if 'name' not in options:
options['name'] = readin("Enter a name")
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)