-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarantz5.py
73 lines (60 loc) · 2.31 KB
/
Marantz5.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
import subprocess
import shlex
from subprocess import Popen
from subprocess import Popen,PIPE
import time
import string
import socket
class IP():
def __init__(self, script, ip, port, timer):
print "Marantz5"
#self.script = "./MarantzIP/"
self.script = script
self.ip = ip
self.port = port
self.timer = timer # threading.Timer(10, self.disconnect)
#
# Start
# It might be possible to use the following rather than netcat - for later!
#
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
while 1:
data = s.recv(1024)
if data == "":
break
print "Received:", repr(data)
print "Connection closed."
s.close()
#
# End
#
def write(self, command):
self.parms_str = "%s \"%s\" %s %s %s" % (str(self.script), str(command), str(self.ip), str(self.port), str(self.timer))
#print "Command str is: ", self.parms_str
print "Command is: ", command, " self.parms_str is: ", self.parms_str
#print "Command is: ", command
#self.parms_lst = [str(self.script), str(command), str(self.ip), str(self.port), str(self.timer)]
#print "Command lst is: ", self.parms_lst
#output = subprocess.check_output(self.parms_lst)
#print "Test: ", output.decode("utf-8")
proc = Popen(self.parms_str, shell=True, stdin=PIPE, stderr=PIPE, stdout=PIPE)
res = proc.communicate()[0]
#res, err = proc.communicate()
#print "STDOUT: ", repr(res), " STDERR: ", repr(err)
#print "Communicate returns: ", repr(res)
#string.replace(res, "\n", "\r")
lst = string.split(res, "\r") #Result ["Start\nano_string1", "ano_string2, ... , "End\n" ]
#print "Output list1: ", lst
lst.remove("")
#print "Final Output list: ", lst
print "Returned: ", lst
time.sleep(self.timer)
#print "Output strt: ", proc.communicate(), "\nOutput end"
#return res
return lst
def write_command(self, command):
return self.write(command)