This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
eqdc.py
executable file
·65 lines (51 loc) · 1.69 KB
/
eqdc.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
#! /bin/env python
"""
Equipment Servicing Diagnostic client.
Used for interacting with the Equipment Servicing Diagnostic system
for the Equipment Servicing task in CIRC 2018.
"""
import argparse
import socket
# HOST = 'task.cstag.ca'
HOST = '192.168.0.1'
PORT = 4547
BUFF_SIZE = 2048
def parse_args():
parser = argparse.ArgumentParser(description='Interact with the CIRC Equipment servicing diagnostic system')
parser.add_argument('command')
parser.add_argument('arguments', nargs='*')
args = parser.parse_args()
api = API()
if args.command:
function = getattr(api, args.command)
if function:
response = function(*args.arguments)
print(response)
else:
print('Invalid command')
class API:
"""
To add support for new commands, create a new method
with the same name you want to have entered from the
command line. CLI arguments after the command name
will be passed in to your method in the order they were
entered on the CLI.
"""
def help(self):
return self._send_mesg('help')
def status(self):
return self._send_mesg('status')
def login(self, username, password):
return self._send_mesg('login {} {}'.format(username, password))
def logout(self):
return self._send_mesg('logout')
def start(self):
return self._send_mesg('start')
def stop(self):
return self._send_mesg('stop')
def _send_mesg(self, msg):
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.sendto(msg.encode(), (HOST, PORT))
response, addr = client.recvfrom(BUFF_SIZE)
return response.decode('utf-8')
parse_args()