-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSer.py
More file actions
58 lines (53 loc) · 1.32 KB
/
Copy pathtestSer.py
File metadata and controls
58 lines (53 loc) · 1.32 KB
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
import platform
import socket
import serial
import time
import getDiskUsage
import getnifs
import getPlatform
def loop():
buttonPressed = ser.read()
if (buttonPressed == '1'):
doOS();
elif (buttonPressed == '2'):
doIP();
elif (buttonPressed == '3'):
doDU();
def doOS():
print 'OS'
lsbinfo = getPlatform.get_lsb_information()
os = platform.uname()
info = '~'+lsbinfo['DESCRIPTION']+'~'+os[2]
print info
ser.write(info)
def doIP():
print 'IP'
network = ''
nifs = getnifs.get_network_interfaces()
for ni in nifs:
if ni.name == 'lo':
continue
else:
nif = ni.name[:1]+ni.name[-1:]
network += '~'+nif+'#'+str(ni.addresses.get(socket.AF_INET))
print network
ser.write(network)
def doDU():
print 'Disk'
diskU = ''
for part in getDiskUsage.disk_partitions():
pt1 = getDiskUsage.disk_usage(part.mountpoint)
# print pt1.x
# print pt1.y
# print pt1.z
balance = int(round((100.0 - pt1.z)/4))
# print balance
#stat = (pt1.x).ljust(6)+'{:4d}'.format(pt1.y)+'G '+'{:3.0f}'.format(pt1.z)+'%'
stat = '~'+(pt1.x).ljust(6)+'{:4d}'.format(pt1.y)+'G'+'#'+str(balance)
diskU += stat
print diskU
ser.write(diskU)
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) #port is 11 (for COM12, and baud rate is 9600 /dev/ttyUSB0
time.sleep(2) #wait for the Serial to initialize
while True:
loop()