-
Notifications
You must be signed in to change notification settings - Fork 5
/
ivshmsg_client.py
executable file
·66 lines (48 loc) · 1.9 KB
/
ivshmsg_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
#!/usr/bin/python3
# This work is licensed under the terms of the GNU GPL, version 2 or
# (at your option) any later version. See the LICENSE file in the
# top-level directory.
# Rocky Craig <rocky.craig@hpe.com>
# This is modelled on the ivshmem-client program that comes with QEMU.
import argparse
import grp
import os
import sys
from ivshmsg_twisted.twisted_client import FactoryIVSHMSGClient
###########################################################################
def parse_cmdline(cmdline_args):
'''cmdline_args does NOT lead with the program name. Single-letter
arguments reflect the stock QEMU "ivshmem-client".'''
parser = argparse.ArgumentParser(
description='IVSHMSG client files',
epilog='Options reflect those in the QEMU "ivshmem-client".'
)
parser.add_argument('-?', action='help') # -h and --help are built in
parser.add_argument('--socketpath', '-S', metavar='/path/to/socket',
help='Absolute path to UNIX domain socket created by the server',
default='/tmp/ivshmsg_socket'
)
parser.add_argument('--verbose', '-v',
help='Specify multiple times to increase verbosity',
default=0,
action='count'
)
args = parser.parse_args(cmdline_args)
# Idiot checking.
assert os.path.exists(args.socketpath), \
'No socket %s (have you started ivshmsg_server?)' % args.socketpath
return args
###########################################################################
# MAIN
def forever(cmdline_args=None):
if cmdline_args is None:
cmdline_args = sys.argv[1:] # When being explicit, strip prog name
try:
args = parse_cmdline(cmdline_args)
except Exception as e:
raise SystemExit(str(e))
client = FactoryIVSHMSGClient(args)
client.run()
###########################################################################
if __name__ == '__main__':
forever()