def createResponseMessage(message): loggingConfig = python_config.read_logging_config() enabled = loggingConfig.get('enabled') api = loggingConfig.get('api') auth = loggingConfig.get('auth') domain = loggingConfig.get('domain') loggingNotEnabledMsg = "logging is not enabled in the config.ini." messageBase = Eby_Message.MessageBase(message) response = None isKeepAliveMessage = messageBase.CheckIfMessageIsKeepAlive() if isKeepAliveMessage: response = messageBase.getFullAcknowledgeKeepAliveMessage() return response #if not, then it's a data message else: messageBase.getMessageType( ) #save the message data to the database, log it, etc. response = messageBase.getFullAcknowledgeKeepAliveMessage() if enabled == "1": hostLog.log(auth, domain, "WXS to Host", "ACKNOWLE", response) else: print(loggingNotEnabledMsg) return response
def handle(self): loggingConfig = python_config.read_logging_config() #enabled = loggingConfig.get('enabled') #api = loggingConfig.get('api') auth = loggingConfig.get('auth') domain = loggingConfig.get('domain') # self.rfile is a file-like object created by the handler; # we can now use e.g. readline() instead of raw recv() calls #self.data = self.rfile.readline().strip() self.data = self.request.recv(1024) print("{} wrote:".format(self.client_address[0])) print(self.data) test = str(self.data, 'utf-8') #this works!!! #hostLog.log(auth, domain, "inbound", "ACK", test) response = self.createResponseMessage(self.data) print('Sending back:') print(response) #bytesToReturn = bytearray(response, 'ascii') #print('bytes to return:') #print(bytesToReturn) # Likewise, self.wfile is a file-like object used to write back # to the client self.wfile.write(response)
def logExceptionStackTrace(exceptionMsg, exceptionDetails): loggingConfig = python_config.read_logging_config() enabled = loggingConfig.get('enabled') auth = loggingConfig.get('auth') domain = loggingConfig.get('domain') if enabled == "1": hostLog.log(auth, domain, "Socket Listener", "Exception", exceptionMsg + " StackTrace: " + exceptionDetails) else: print("Exception", exceptionMsg + " StackTrace: " + exceptionDetails)
def __init__(self, libserver): self.libserver = libserver self.AsciiRequestMessage = libserver.replace("'", "") #libserver.decode('ascii') #libserver.request[:].decode('ascii') self.fields = self.populateFields() self.MsgSequenceNumber = self.getMessageSequenceNumber() self.MessageID = self.fields[1] self.RouteNumber = self.fields[2] if self.fields[2] else "" self.StopNumber = self.fields[3] if self.fields[3] else "" self.ContainerID = self.fields[4] if self.fields[4] else "" self.AssignmentID = self.fields[5] if self.fields[5] else "" self.PickArea = self.fields[6] if self.fields[6] else "" self.PickType = self.fields[7] if self.fields[7] else "" self.Jurisdiction = self.fields[8] if self.fields[8] else "" self.NumberCartons = self.getNumberCartons() self.loggingConfig = python_config.read_logging_config()
import python_config import mysql.connector import datetime from pylogix import PLC import sys import atexit import Eby_DockScanPause as scanPause import Eby_02_DashboardModal as modal config = python_config.read_db_config() host = config.get('host') user = config.get('user') database = config.get('wcsdatabase') password = config.get('password') logging = python_config.read_logging_config() auth = logging.get('auth') domain = logging.get('domain') plcIP = "10.22.56.34" # Data Types STRUCT = 160 BOOL = 193 SINT = 194 INT = 195 DINT = 196 LINT = 197 USINT = 198 UINT = 199 UDINT = 200 LWORD = 201
def saveNewContainer(self): loggingConfig = python_config.read_logging_config() enabled = loggingConfig.get('enabled') auth = loggingConfig.get('auth') domain = loggingConfig.get('domain') existingRecord = self.doesNewContainerAlreadyExist() if existingRecord is not None: if enabled == "1": #the ContainerID hostLog.log(auth, domain, "HOST to WXS", "Dupl", existingRecord[2]) return config = python_config.read_db_config() host = config.get('host') user = config.get('user') database = config.get('database') password = config.get('password') date = None assignmentRecords = self.getMasterRecordByAssignmentId() if assignmentRecords is not None and len(assignmentRecords) > 0: date = assignmentRecords[0] # (rjw 2020-11-14 11:47) -- needed to add in assignment date based on original date of assignment drop in case this ADDCONTA comes after midnight # date = "SELECT date FROM assignment.dat_master WHERE assignment_id=" + "'" + str(self.AssignmentID) + "'" # cursor.execute(date) # date = str(cursor.fetchone()[0]) #print(date) try: connection = mysql.connector.connect( host= host, user= user, database= database, password= password ) cursor = connection.cursor() addNewContainerSQL = ("INSERT INTO dat_master " "(record_id, container_id, assignment_id, route_no, stop_no, pick_code, pick_type, jurisdiction, carton_qty, c_comp, a_comp, o_comp, r_comp, assign_name, status, date, created_at, updated_at) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)") currentTimeStamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] newContainer = ( self.MessageID, self.ContainerID, self.AssignmentID, self.RouteNumber, self.StopNumber, self.PickArea, self.PickType, self.Jurisdiction, self.NumberCartons, 0, 0, 0, 0, 'SOCKET', 'Pending', date, currentTimeStamp, currentTimeStamp ) cursor.execute(addNewContainerSQL, newContainer) connection.commit() rowcount = cursor.rowcount print("Rows inserted: " + str(rowcount)) cursor.close() connection.close() return True except Exception as e: print(e) #connection.rollback() exc_type, exc_value, exc_traceback = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_traceback) exceptionMsg = exc_value exceptionDetails = ''.join('!! ' + line for line in lines) GlobalFunctions.logExceptionStackTrace(exceptionMsg, exceptionDetails) hostLog.dbLog("Eby_NewContainer", "Upd Err", self.AsciiRequestMessage) return False finally: cursor.close() connection.close()