forked from ipa320/setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sunrise
executable file
·74 lines (68 loc) · 1.89 KB
/
sunrise
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
#!/usr/bin/env python
import telnetlib
import string
import sys
import socket
class sunrise:
def __init__(self):
notconnected = True
while(notconnected):
try:
self.tn = telnetlib.Telnet(host="192.168.42.146", timeout=2)
notconnected = False
except socket.timeout:
print "timeout, trying again ..."
except socket.error:
print "socket error, trying again ..."
def recover_sunrise(self):
print "Recovering Sunrise"
print self.tn.read_until("->")
print self.tn.read_eager()
self.tn.write("<scho\n")
print self.tn.read_until("->")
print self.tn.read_eager()
print "done recovering sunrise"
def check_init(self):
#tn.set_debuglevel(10)
self.tn.read_until("->")
self.tn.read_eager()
self.tn.write("<scho\n")
teststr = self.tn.read_until("->")
teststr += self.tn.read_eager()
#print teststr
if(string.find(teststr, "unknown symbol name") != -1):
print "not initialized"
return False
else:
print "already intialized"
return True
def init(self):
if(self.check_init() == False):
print "Initializing Sunrise"
self.tn.write("<l\n")
print "Initializing sunrise, this may take 1-2 minutes"
print self.tn.read_until("State RUNNING reached !")
print self.tn.read_eager()
print "done initializing"
else:
print "already initialized"
def reboot(self):
print "Rebooting Sunrise"
print self.tn.read_until("->")
print self.tn.read_eager()
self.tn.write("reboot\n")
teststr = self.tn.read_until("->")
teststr += self.tn.read_eager()
print teststr
print self.tn.read_eager()
if __name__ == "__main__":
s = sunrise()
if(len(sys.argv) == 2):
if(sys.argv[1] == "checkInit"):
s.check_init()
elif(sys.argv[1] == "Init"):
s.init()
else:
print sys.argv
else:
print "usage: sunrise [checkInit , Init , Reboot]"