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