老生常谈的东西
这是我这段代码的第21次更新了,依然不能实现全部的设计需求
然而都这个点儿了,先睡吧
欠下的债,早晚都要还的
try:
import sys
import time
import os
import platform
import threading
except:
pass
class StatusMonitor:
def __init__(self):
self.adb_task = None
self._dict = {}
try:
base_dir = os.path.dirname(os.getcwd())
configfile_path = os.path.join(base_dir, r'\untility\configfile.txt')
CONFIGFILE = open(configfile_path, 'r')
adbstatus_path = os.path.join(base_dir, r'\logs\adb_status.txt')
self.ADBFILE = open(adbstatus_path, 'a+')
except:
print ("File not exist")
return False
for line in CONFIGFILE:
(key,value) = line.strip().split(':',maxsplit=1)
self._dict[key] = value
global adb_status_monitor
self.adb_status_monitor = 1
def device_state_monitor_start(self):
while True:
if self.adb_status_monitor == 1:
Time_mark = time.strftime("%Y-%m-%d %H:%M:%S")
self.ADBFILE.write(str(Time_mark + ' '))
adb_status = True
if adb_status == True:
self.ADBFILE.write('ADB works normally')
self.ADBFILE.write('\n')
print ('ADB works normally')
monkey_result = True
if monkey_result == True:
self.ADBFILE.write('Monkey works normally')
self.ADBFILE.write('\n')
print ('Monkey works normally')
else:
self.ADBFILE.write('Monkey process is terminated')
self.ADBFILE.write('\n')
print ('Monkey works abnormally')
else:
self.ADBFILE.write('ADB is disconnected,and Monkey process can not be found')
self.ADBFILE.write('\n')
print ('ADB is disconnected')
time.sleep(8)
else:
break
def device_state_monitor_stop(self):
global adb_status_monitor
self.adb_status_monitor = 0
self.ADBFILE.close()
def regNewProcess(self):
self.adb_task = threading.Thread(target=self.device_state_monitor_start)
self.adb_task.start()
print('The thread adb task start')
"""def check_parameters(self):
#Check the config file for blank value
configfile = self._dict
print (configfile)
for key in configfile:
if configfile[key] =='':
print ([key], "Error: Value is blank")
return False
else:
#print ([key,configfile[key]],'Pass')
pass
test_hour = self.get_parameters('TEST_HOUR')
cycle_time = self.get_parameters('CYCLE_TIME')
change_prof_hour = self.get_parameters('CHANGE_PROFILE_HOUR')
test_type = self.get_parameters('TEST_TYPE')
execute_method = self.get_parameters('EXECUTE_METHOD')
#Check the Test_hour/Cycle_time/change_prof_hour
if int(test_hour) < int(cycle_time):
# 'TEST_HOUR' should longer than 'CYCLE_TIME'
print ("Error: test_hour < cycle time is incorrect")
return False
elif int(cycle_time) < int(change_prof_hour):
# 'CYCLE_TIME' should longer than 'CHANGE_PROFILE_TIME'
print ("Error: cycle_time < change_prof_hour is incorrect")
return False
elif (test_type) != 'black'and (test_type) != 'white':
# Only 'black' or 'white' is available in 'TEST_TYPE'
print ("Error: test_type should be 'black' or 'white'.")
return False
elif (execute_method) != '1' and (execute_method) != '2':
# Only '1' or '2' is available in 'EXECUTE_METHOD'
print ("Error: execute_method should be '1' or '2'")
return False
else:
print ("Check parameters completed.No error occurs")
return True"""
def get_parameters(self,item):
value = self._dict.get(item,None)
if value == None:
print (item,' KEY error, please check the key_name')
return value
if __name__=='__main__':
i = StatusMonitor()
k = i.regNewProcess()
mm = i.get_parameters('TEST_TYPE')
print(k,mm)