@ -8,7 +8,7 @@ import os
import PIL
from PIL import ImageGrab
from threading import Thread
import orchestrator Processor
import Processor
import importlib
import pdb
import imp
@ -26,46 +26,15 @@ def SaveScreenshot(inFilePath):
# save image file
#lScreenshot.save('screenshot.png')
#Глобальные переменные
global mActivityLogDict
#inGlobalDict
# "JSONConfigurationDict":<JSON>
class RobotDaemonServer ( Thread ) :
def __init__ ( self , name , inGlobalDict ) :
Thread . __init__ ( self )
self . name = name
global mJSONConfigurationDict
mJSONConfigurationDict = inGlobalDict [ " JSONConfigurationDict " ]
#Перенос переменной в orchestratorProcessor
orchestratorProcessor . mGlobalDict = inGlobalDict [ " GlobalDict " ]
#Init other functions
#TODO do module init once when run
#lRenderFunctionsRobotList=mJSONConfigurationDict["ControlPanelDict"]["RobotList"]
#for lItem in lRenderFunctionsRobotList:
#lModuleImportName = lItem.get("RenderFunctionModuleSubfolderName","")
#f = None
#filename = None
#description = None
#if lModuleImportName!="":
# lModuleImportName = f'{lItem["RenderFunctionModuleSubfolderName"]}.{lItem["RenderFunctionModuleName"]}'
# f, filename, description = imp.find_module(lModuleImportName)
#else:
# lModuleImportName = lItem["RenderFunctionModuleName"]
# f, filename, description = imp.find_module(lModuleImportName)
#Подключить модуль для вызова
#importlib.import_module(lModuleImportName)
#pdb.set_trace()
#import imp
#f, filename, description = imp.find_module(lModuleImportName)
#example_package = imp.load_module(lModuleImportName, f, filename, description)
#print('Package:', example_package)
#f.close()
#print(globals())
#print(lModuleImportName)
def run ( self ) :
inServerAddress = " " ;
inPort = m JSONConfiguration Dict[ " Server " ] [ " ListenPort " ] ;
inPort = mGlobalDict [ " Server " ] [ " ListenPort " ] ;
print ( ' starting server..., port: ' + str ( inPort ) + " inAddress: " + inServerAddress )
# Server settings
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
@ -128,7 +97,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self . send_header ( ' Content-type ' , ' application/json ' )
self . end_headers ( )
# Send message back to client
message = json . dumps ( m JSONConfiguration Dict)
message = json . dumps ( m Global Dict)
# Write content as utf-8 data
self . wfile . write ( bytes ( message , " utf8 " ) )
if self . path == ' /Monitor/ControlPanelDictGet ' :
@ -139,7 +108,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self . end_headers ( )
#Create result JSON
lResultJSON = { " RenderRobotList " : [ ] }
lRenderFunctionsRobotList = m JSONConfiguration Dict[ " ControlPanelDict " ] [ " RobotList " ]
lRenderFunctionsRobotList = m Global Dict[ " ControlPanelDict " ] [ " RobotList " ]
for lItem in lRenderFunctionsRobotList :
#Подключить модуль для вызова
#print(globals())
@ -152,11 +121,10 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
#Найти функцию
lFunction = getattr ( lModule , lItem [ " RenderFunctionName " ] )
#Выполнить вызов и записать результат
lItemResultDict = lFunction ( m JSONConfiguration Dict)
lItemResultDict = lFunction ( m Global Dict)
#RunFunction
lResultJSON [ " RenderRobotList " ] . append ( lItemResultDict )
# Send message back to client
#print(mJSONConfigurationDict)
message = json . dumps ( lResultJSON )
# Write content as utf-8 data
self . wfile . write ( bytes ( message , " utf8 " ) )
@ -164,8 +132,8 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
if self . path . lower ( ) . startswith ( ' /filemanager/ ' ) :
lFileURL = self . path [ 13 : ]
# check if file in FileURL - File Path Mapping Dict
if lFileURL . lower ( ) in m JSONConfiguration Dict[ " FileManager " ] [ " FileURLFilePathDict " ] :
self . SendResponseContentTypeFile ( ' application/octet-stream ' , m JSONConfiguration Dict[ " FileManager " ] [ " FileURLFilePathDict " ] [ lFileURL ] )
if lFileURL . lower ( ) in m Global Dict[ " FileManager " ] [ " FileURLFilePathDict " ] :
self . SendResponseContentTypeFile ( ' application/octet-stream ' , m Global Dict[ " FileManager " ] [ " FileURLFilePathDict " ] [ lFileURL ] )
# POST
def do_POST ( self ) :
#Централизованная функция получения запросов/отправки
@ -183,7 +151,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self . send_header ( ' Content-type ' , ' application/json ' )
self . end_headers ( )
# Send message back to client
message = json . dumps ( orchestrator Processor. ActivityListOrDict ( lInputObject ) )
message = json . dumps ( Processor. ActivityListOrDict ( lInputObject ) )
# Write content as utf-8 data
self . wfile . write ( bytes ( message , " utf8 " ) )
return