-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttschlep
executable file
·75 lines (64 loc) · 2.41 KB
/
ttschlep
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
#!/usr/bin/env python3
import sys
import argparse
import ttschlepper.constants as const
import ttschlepper.comms as comms
import ttschlepper.translation as xlate
def addr_and_port(aStr):
"""\
Reads a host and optional port from the command line.
"""
if ":" in aStr:
h, p = aStr.rsplit(":", 1)
p = int(p, 10)
else:
h = aStr
p = 0
return (h, p)
parser = argparse.ArgumentParser(description="Get or send Lua scripts from Tabletop Simulator")
parser.add_argument('-s', '--server',
metavar="HOST[:PORT]",
type=addr_and_port, default='localhost:'+str(const.TTS_SERVER_PORT),
help='Server hostname and port to connect to (default:%(default)s)')
parser.add_argument('-l', '--listen',
metavar="HOST[:PORT]",
type=addr_and_port, default='localhost:'+str(const.TTS_CLIENT_PORT),
help='Client hostname and port to listen on (default:%(default)s)')
subparsers = parser.add_subparsers(dest='command', help='Action')
subparsers.required = True
p_get = subparsers.add_parser('get', help='get scripts from TTS')
p_get.add_argument('outfile',
metavar="OUTFILE",
type=argparse.FileType('w'), nargs='?', default=sys.stdout,
help="File to save to (default:stdout)")
p_put = subparsers.add_parser('put', help='put scripts to TTS')
p_put.add_argument('infile',
metavar="INFILE",
type=argparse.FileType('r'), nargs='?', default=sys.stdin,
help="File to read from (default:stdin)")
p_get = subparsers.add_parser('listen', help='listen for changes from TTS')
p_get.add_argument('outfile',
metavar="OUTFILE",
type=argparse.FileType('w'), nargs='?', default=sys.stdout,
help="File to save to (default:stdout)")
args = parser.parse_args()
if args.command == 'get':
json = comms.send_msg(comms.SEND_GET_SCRIPTS, args.server, args.listen)
xlate.json2lua(json, args.outfile)
elif args.command == 'put':
json = xlate.lua2json(args.infile)
comms.send_msg(comms.SEND_SAVE_PLAY, args.server, args.listen, json)
elif args.command == 'listen':
raise NotImplemented
# Editor modelines - http://www.wireshark.org/tools/modelines.html
#
# Local variables:
# c-basic-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# coding: utf-8
# mode: python
# End:
#
# vi:set shiftwidth=4 tabstop=4 expandtab fileencoding=utf-8 filetype=python:
# :indentSize=4:tabSize=4:noTabs=true:coding=utf-8:type=python: