|
|
import psutil
|
|
|
import datetime
|
|
|
def RenderRobotR01(inGlobalConfiguration):
|
|
|
#Subheader Variants
|
|
|
lSubheaderRunTrueText="Состояние: <span style=\"color:green\">Работает</span>"
|
|
|
lSubheaderRunFalseText="Состояние: <span style=\"color:red\">Не работает</span>"
|
|
|
#Result template
|
|
|
lResultDict={
|
|
|
"HeaderLeftText":"Автозагрузка заявок на расход",
|
|
|
"HeaderRightText":"R01",
|
|
|
"SubheaderText":lSubheaderRunFalseText,
|
|
|
"BodyKeyValueList":[
|
|
|
#Дата запуска: 10:00:09 01.09.2019
|
|
|
{"Key":"Дата запуска","Value":"Не запущен"},
|
|
|
{"Key":"Текущий шаг","Value":"Не запущен"},
|
|
|
{"Key":"Время выполнения шага","Value":"--с."},
|
|
|
{"Key":"Отчет робота","Value":"<a href=\"filemanager/r01/report.xlsx\">Скачать</a>"}
|
|
|
],
|
|
|
"FooterText":"Дата изменения: 9:38:00 09.10.2019",
|
|
|
"FooterButtonX2List":[
|
|
|
{"Text":"Ручной запуск", "Color":"green", "Link":""},
|
|
|
{"Text":"Безопасная остановка", "Color":"orange", "Link":""}
|
|
|
],
|
|
|
"FooterButtonX1List":[
|
|
|
{"Text":"Принудительная остановка", "Color":"red", "Link":""}
|
|
|
]
|
|
|
}
|
|
|
#Check if process running
|
|
|
if CheckIfProcessRunning("Robot_R01"):
|
|
|
lResultDict["SubheaderText"]=lSubheaderRunTrueText
|
|
|
#Fill robot info from Storage - R01
|
|
|
if "Robot_R01" in inGlobalConfiguration.get("Storage",{}):
|
|
|
lItemDict=inGlobalConfiguration["Storage"]["Robot_R01"]
|
|
|
#lResultDict["HeaderLeftText"]=lItemDict["Name"]
|
|
|
#lResultDict["HeaderRightText"]=lItemDict["Code"]
|
|
|
lResultDict["BodyKeyValueList"][0]["Value"]=lItemDict.get("RunDateTimeString","Не запущен")
|
|
|
lResultDict["BodyKeyValueList"][1]["Value"]=lItemDict.get("StepCurrentName","Не запущен")
|
|
|
lResultDict["BodyKeyValueList"][2]["Value"]=lItemDict.get("StepCurrentDuration","--с.")
|
|
|
else:
|
|
|
#Process not running
|
|
|
lResultDict["FooterText"]=f'Дата изменения: {datetime.datetime.now().strftime("%H:%M:%S %d.%m.%Y")}'
|
|
|
else:
|
|
|
#Process not running
|
|
|
lResultDict["FooterText"]=f'Дата изменения: {datetime.datetime.now().strftime("%H:%M:%S %d.%m.%Y")}'
|
|
|
return lResultDict
|
|
|
def CheckIfProcessRunning(processName):
|
|
|
'''
|
|
|
Check if there is any running process that contains the given name processName.
|
|
|
'''
|
|
|
#Iterate over the all the running process
|
|
|
for proc in psutil.process_iter():
|
|
|
try:
|
|
|
# Check if process name contains the given name string.
|
|
|
if processName.lower() in proc.name().lower():
|
|
|
return True
|
|
|
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
|
|
pass
|
|
|
return False; |