From 34a3a67b9e2ab4aa59611567dc96b9932e9df889 Mon Sep 17 00:00:00 2001 From: md8n Date: Thu, 2 Mar 2023 23:10:01 +0900 Subject: [PATCH] Logging improvements for the Python code --- .gitignore | 3 + Actions/actions.py | 138 +++++++++++++-------------- Background/LogStreamer.py | 8 +- Background/UIProcessor.py | 70 +++++++------- Background/WebMCPProcessor.py | 2 +- Background/webcamVideoStream.py | 14 +-- Connection/nonVisibleWidgets.py | 14 +-- Connection/serialPortThread.py | 31 +++--- DataStructures/logger.py | 6 +- ReleaseManager/releaseManager.py | 42 ++++---- WebPageProcessor/webPageProcessor.py | 18 ++-- config/config.py | 40 ++++---- 12 files changed, 191 insertions(+), 195 deletions(-) diff --git a/.gitignore b/.gitignore index 76d34f10..7628b7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ alog.txt __pycache__/ *.py[cod] *$py.class + +# node +static/node_modules/ diff --git a/Actions/actions.py b/Actions/actions.py index f094f16d..90bfd3dc 100644 --- a/Actions/actions.py +++ b/Actions/actions.py @@ -306,7 +306,7 @@ def shutdown(self): self.data.ui_queue1.put("WebMCP", "shutdown", "") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def turnOff(self): @@ -364,7 +364,7 @@ def defineHome(self, posX="", posY=""): self.data.ui_queue1.put("Action", "homePositionMessage", position) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def home(self): @@ -394,7 +394,7 @@ def home(self): self.data.gcode_queue.put("G00 Z0 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def resetChainLengths(self): @@ -412,7 +412,7 @@ def resetChainLengths(self): self.data.gcode_queue.put("G21 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def defineZ0(self): @@ -424,7 +424,7 @@ def defineZ0(self): self.data.gcode_queue.put("G10 Z0 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def stopZ(self): @@ -439,7 +439,7 @@ def stopZ(self): self.data.gcode_queue.queue.clear() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def setMinZ(self): @@ -451,7 +451,7 @@ def setMinZ(self): self.data.gcode_queue.put("B18") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def setMaxZ(self): @@ -463,7 +463,7 @@ def setMaxZ(self): self.data.gcode_queue.put("B17") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def clearZ(self): @@ -475,7 +475,7 @@ def clearZ(self): self.data.gcode_queue.put("B19") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def getZlimits(self): @@ -487,7 +487,7 @@ def getZlimits(self): self.data.gcode_queue.put("B20") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def startRun(self): @@ -518,7 +518,7 @@ def startRun(self): return False except Exception as e: # something goes wrong, stop uploading. - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") self.data.uploadFlag = 0 self.data.gcodeIndex = 0 return False @@ -529,7 +529,7 @@ def stopRun(self): :return: ''' try: - self.data.console_queue.put("stopping run") + self.data.console_queue.put(f"{__name__}: stopping run") # this is necessary because of the way PID data is being processed. Otherwise could potentially get stuck # in PID test self.data.inPIDPositionTest = False @@ -541,7 +541,7 @@ def stopRun(self): with self.data.gcode_queue.mutex: self.data.gcode_queue.queue.clear() # TODO: app.onUploadFlagChange(self.stopRun, 0) edit: not sure this is needed anymore - self.data.console_queue.put("Gcode stopped") + self.data.console_queue.put(f"{__name__}: Gcode stopped") self.sendGCodePositionUpdate(self.data.gcodeIndex) # notify UI client to clear any alarm that's active because a stop has been process. self.data.ui_queue1.put("Action", "clearAlarm", "") @@ -551,7 +551,7 @@ def stopRun(self): self.data.gpioActions.causeAction("PauseLED", "off") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def moveToDefault(self): @@ -577,7 +577,7 @@ def moveToDefault(self): return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def testMotors(self): @@ -589,7 +589,7 @@ def testMotors(self): self.data.gcode_queue.put("B04 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def wipeEEPROM(self, extent): @@ -622,7 +622,7 @@ def wipeEEPROM(self, extent): #self.timer.start() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def pauseRun(self): @@ -633,7 +633,7 @@ def pauseRun(self): try: if self.data.uploadFlag == 1: self.data.uploadFlag = 2 - self.data.console_queue.put("Run Paused") + self.data.console_queue.put(f"{__name__}: Run Paused") self.data.ui_queue1.put("Action", "setAsResume", "") # The idea was to be able to make sure the machine returns to # the correct z-height after a pause in the event the user raised/lowered the bit. @@ -646,7 +646,7 @@ def pauseRun(self): self.data.gpioActions.causeAction("PauseLED", "on") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def resumeRun(self): @@ -713,7 +713,7 @@ def resumeRun(self): self.data.gpioActions.causeAction("PauseLED", "off") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def returnToCenter(self): @@ -734,7 +734,7 @@ def returnToCenter(self): self.data.gcode_queue.put("G00 X0.0 Y0.0 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def clearGCode(self): @@ -746,7 +746,7 @@ def clearGCode(self): self.data.gcodeFile.clearGcodeFile() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def moveGcodeZ(self, moves): @@ -770,7 +770,7 @@ def moveGcodeZ(self, moves): else: return False except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def moveGcodeIndex(self, dist, index=False): @@ -804,12 +804,12 @@ def moveGcodeIndex(self, dist, index=False): retval = self.sendGCodePositionUpdate(recalculate=True) return retval except Exception as e: - self.data.console_queue.put(str(e)) - self.data.console_queue.put("Unable to update position for new gcode line") + self.data.console_queue.put(f"{__name__}: {e}") + self.data.console_queue.put(f"{__name__}: Unable to update position for new gcode line") return False return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def move(self, direction, distToMove): @@ -852,7 +852,7 @@ def move(self, direction, distToMove): self.data.config.setValue("Computed Settings", "distToMove", distToMove) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def moveZ(self, direction, distToMoveZ): @@ -893,7 +893,7 @@ def moveZ(self, direction, distToMoveZ): self.data.gcode_queue.put("G20 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False @@ -916,7 +916,7 @@ def touchZ(self): self.data.measureRequest = self.defineZ0() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def updateSetting(self, setting, value, fromGcode = False): @@ -928,7 +928,7 @@ def updateSetting(self, setting, value, fromGcode = False): :return: ''' try: - self.data.console_queue.put("at update setting from gcode("+str(fromGcode)+"): "+setting+" with value: "+str(value)) + self.data.console_queue.put(f"{__name__}: '{setting}': '{value}' - (from gcode? {fromGcode})") # if front page button has been pressed or serialPortThread is going to send gcode with a G21 or G20.. if setting == "toInches" or setting == "toMM": # this shouldn't be reached any more after I reordered the processActions function @@ -1030,7 +1030,7 @@ def updateSetting(self, setting, value, fromGcode = False): self.data.ui_queue1.put("Action", "distToMoveUpdateZ", "") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def rotateSprocket(self, sprocket, time): @@ -1048,7 +1048,7 @@ def rotateSprocket(self, sprocket, time): self.data.gcode_queue.put("B11 "+sprocket+" S-100 T"+str(abs(time))) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False @@ -1086,7 +1086,7 @@ def setSprockets(self, sprocket, degrees): self.data.gcode_queue.put("G90 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def setSprocketAutomatic(self): @@ -1099,7 +1099,7 @@ def setSprocketAutomatic(self): self.data.gcode_queue.put("B10 L") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def getLeftChainLength(self, dist): @@ -1154,7 +1154,7 @@ def setSprocketsZero(self): self.data.gcode_queue.put("B06 L0 R0 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def setSprocketsDefault(self): @@ -1168,7 +1168,7 @@ def setSprocketsDefault(self): self.data.gcode_queue.put("B08 ") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def updatePorts(self): @@ -1176,7 +1176,7 @@ def updatePorts(self): Updates the list of ports found on the computer. :return: ''' - self.data.console_queue.put("at Update Ports") + self.data.console_queue.put(f"{__name__}: at Update Ports") portsList = [] try: if sys.platform.startswith("linux") or sys.platform.startswith("cygwin"): @@ -1199,7 +1199,7 @@ def updatePorts(self): self.data.ui_queue1.put("Action", "updatePorts", "") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def acceptTriangularKinematicsResults(self): @@ -1212,7 +1212,7 @@ def acceptTriangularKinematicsResults(self): self.data.triangularCalibration.acceptTriangularKinematicsResults() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False @@ -1237,7 +1237,7 @@ def calibrate(self, result): cut34YoffsetEst, ) except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def holeyCalibrate(self, result): @@ -1262,7 +1262,7 @@ def holeyCalibrate(self, result): calibrationError, ) except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False @@ -1279,7 +1279,7 @@ def sendGCode(self, gcode): self.data.gcode_queue.put(line) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def macro(self, number): @@ -1300,11 +1300,9 @@ def macro(self, number): print("here2") self.data.gpioActions.setGPIOAction(3, "Stop") return True - except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False - ''' try: if number == 1: @@ -1314,7 +1312,7 @@ def macro(self, number): self.data.gcode_queue.put(macro) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def testImage(self): @@ -1327,7 +1325,7 @@ def testImage(self): self.data.opticalCalibration.testImage() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def adjustCenter(self, dist): @@ -1343,7 +1341,7 @@ def adjustCenter(self, dist): return False return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def processSettingRequest(self, section, setting): @@ -1381,7 +1379,7 @@ def processSettingRequest(self, section, setting): data = {"curveX": xCurve, "curveY": yCurve} self.data.ui_queue1.put("Action", "updateOpticalCalibrationCurve", data) except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") elif setting == "calibrationError": # send calibration error matrix try: @@ -1391,7 +1389,7 @@ def processSettingRequest(self, section, setting): data = {"errorX": errorX, "errorY": errorY} self.data.ui_queue1.put("Action", "updateOpticalCalibrationError", data) except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") elif setting == "pauseButtonSetting": # send current pause button state try: @@ -1400,7 +1398,7 @@ def processSettingRequest(self, section, setting): else: return setting, "Resume" except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") else: # send whatever is being request if setting == "units": @@ -1595,7 +1593,7 @@ def moveTo(self, posX, posY): return True return False except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def processGCode(self): @@ -1810,7 +1808,7 @@ def adjustChain(self, chain): try: for x in range(6): self.data.ui_queue1.put("Action", "updateTimer", chain+":"+str(5-x)) - self.data.console_queue.put("Action:updateTimer_" + chain + ":" + str(5 - x)) + self.data.console_queue.put(f"{__name__}: Action:updateTimer_{chain}:{5 - x}") time.sleep(1) if chain == "left": self.data.gcode_queue.put("B02 L1 R0 ") @@ -1822,7 +1820,7 @@ def adjustChain(self, chain): self.data.gcode_queue.put("B10 R") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def issueStopCommand(self, distance): @@ -1832,7 +1830,7 @@ def issueStopCommand(self, distance): self.data.gcode_queue.queue.clear() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def toggleCamera(self): @@ -1850,7 +1848,7 @@ def toggleCamera(self): self.data.camera.stop() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def cameraStatus(self): @@ -1869,7 +1867,7 @@ def cameraStatus(self): self.data.ui_queue1.put("Action", "updateCamera", "on") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def queryCamera(self): @@ -1882,7 +1880,7 @@ def queryCamera(self): self.data.camera.getSettings() return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def velocityPIDTest(self, parameters): @@ -1904,7 +1902,7 @@ def velocityPIDTest(self, parameters): self.data.gcode_queue.put(gcodeString) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def positionPIDTest(self, parameters): @@ -1928,12 +1926,11 @@ def positionPIDTest(self, parameters): self.data.gcode_queue.put(gcodeString) return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def velocityPIDTestRun(self, command, msg): ''' - :param command: :param msg: :return: @@ -1958,7 +1955,7 @@ def velocityPIDTestRun(self, command, msg): self.data.PIDVelocityTestData = [] print("PID velocity test started") except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def positionPIDTestRun(self, command, msg): @@ -1982,7 +1979,7 @@ def positionPIDTestRun(self, command, msg): self.data.PIDPositionTestData = [] print("PID position test started") except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def updateGCode(self, gcode): @@ -2004,7 +2001,7 @@ def updateGCode(self, gcode): self.data.ui_queue1.put("Action", "gcodeUpdate", "") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def downloadDiagnostics(self): @@ -2021,7 +2018,7 @@ def downloadDiagnostics(self): zipObj.close() return filename except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def clearLogs(self): @@ -2029,7 +2026,7 @@ def clearLogs(self): retval = self.data.logger.deleteLogFiles() return retval except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False ''' def checkForLatestPyRelease(self): @@ -2050,7 +2047,6 @@ def checkForLatestPyRelease(self): if float(tag_name) > latest: latest = float(tag_name) latestRelease = release - except: print("error parsing tagname") print(latest) @@ -2066,7 +2062,6 @@ def checkForLatestPyRelease(self): self.data.pyInstallUpdateAvailable = True self.data.pyInstallUpdateBrowserUrl = asset.browser_download_url self.data.pyInstallUpdateVersion = latest - def processAbsolutePath(self, path): index = path.find("main.py") self.data.pyInstallInstalledPath = path[0:index-1] @@ -2117,7 +2112,6 @@ def updatePyInstaller(self): subprocess.Popen(command) return True return False - def make_executable(self, path): print("1") mode = os.stat(path).st_mode @@ -2164,7 +2158,7 @@ def backupWebControl(self): #zipObj.close() return filename except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False @@ -2178,7 +2172,7 @@ def restoreWebControl(self, fileName): self.data.gcode_queue.put("$$") return retval except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False def setFakeServo(self, value): @@ -2189,5 +2183,5 @@ def setFakeServo(self, value): self.data.gcode_queue.put("B99 OFF") return True except Exception as e: - self.data.console_queue.put(str(e)) + self.data.console_queue.put(f"{__name__}: {e}") return False diff --git a/Background/LogStreamer.py b/Background/LogStreamer.py index 5830123f..094ea555 100644 --- a/Background/LogStreamer.py +++ b/Background/LogStreamer.py @@ -11,6 +11,7 @@ ''' class LogStreamer: app = None + namespace = "/MaslowCNCLogs" def start(self, _app): self.app = _app @@ -29,18 +30,17 @@ def start(self, _app): message = self.app.data.alog_streamer_queue.get() if message != "": socketio.emit("message", {"log": "alog", "data": message, "state": loggerState, - "dataFormat": "text"}, namespace="/MaslowCNCLogs", ) + "dataFormat": "text"}, namespace=self.namespace, ) timeSinceLastLoggerState = time.time() # process a line from the log queue if not self.app.data.log_streamer_queue.empty(): message = self.app.data.log_streamer_queue.get() if message != "": socketio.emit("message", {"log": "log", "data": message, "state": loggerState, - "dataFormat": "text"}, namespace="/MaslowCNCLogs", ) + "dataFormat": "text"}, namespace=self.namespace, ) timeSinceLastLoggerState = time.time() currentTime = time.time() if currentTime - timeSinceLastLoggerState > 5: socketio.emit("message", {"log": "state", "state": loggerState, "dataFormat":"text"}, - namespace="/MaslowCNCLogs", ) + namespace=self.namespace, ) timeSinceLastLoggerState = currentTime - diff --git a/Background/UIProcessor.py b/Background/UIProcessor.py index b6468c02..e0488147 100644 --- a/Background/UIProcessor.py +++ b/Background/UIProcessor.py @@ -17,18 +17,20 @@ ''' class UIProcessor: - app = None - lastCameraTime = 0 - lastHealthCheck = 0 - previousUploadFlag = None - previousCurrentTool = None - previousPositioningMode = None + def __init__(self): + self.app = None + self.lastCameraTime = 0 + self.lastHealthCheck = 0 + self.previousUploadFlag = None + self.previousCurrentTool = None + self.previousPositioningMode = None + self.namespace = "/MaslowCNC" def start(self, _app): - self.app = _app - self.app.data.console_queue.put("starting UI") + self.app.data.console_queue.put(f"{__name__}: starting") with self.app.app_context(): + self.app.data.console_queue.put(f"{__name__}: entering processing loop") while True: time.sleep(0.001) # send health message @@ -104,7 +106,7 @@ def start(self, _app): data = json.dumps({"setting": "pauseButtonSetting", "value": "Resume"}) socketio.emit("message", {"command": "requestedSetting", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) elif message[0:12] == "Tool Change:": # Tool change message detected. # not sure what manualzaxisadjust is.. ### @@ -364,7 +366,7 @@ def activateModal(self, title, message, modalType, resume="false", progress="fal {"title": title, "message": message, "resume": resume, "progress": progress, "modalSize": "small", "modalType": modalType}) socketio.emit("message", {"command": "activateModal", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", + namespace=self.namespace, ) def sendAlarm(self, message): @@ -375,7 +377,7 @@ def sendAlarm(self, message): ''' data = json.dumps({"message": message}) socketio.emit("message", {"command": "alarm", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", + namespace=self.namespace, ) def sendControllerMessage(self, message): @@ -386,7 +388,7 @@ def sendControllerMessage(self, message): :return: ''' socketio.emit("message", {"command": "controllerMessage", "data": json.dumps(message), "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) def sendWebMCPMessage(self, message): ''' @@ -405,7 +407,7 @@ def sendPositionMessage(self, position): :return: ''' socketio.emit("message", {"command": "positionMessage", "data": json.dumps(position), "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) def sendErrorValueMessage(self, position): ''' @@ -414,7 +416,7 @@ def sendErrorValueMessage(self, position): :return: ''' socketio.emit("message", {"command": "errorValueMessage", "data": json.dumps(position), "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) def sendCameraMessage(self, message, _data=""): ''' @@ -426,7 +428,7 @@ def sendCameraMessage(self, message, _data=""): ''' data = json.dumps({"command": message, "data": _data}) socketio.emit( - "message", {"command": "cameraMessage", "data": data, "dataFormat": "json"}, namespace="/MaslowCNC" + "message", {"command": "cameraMessage", "data": data, "dataFormat": "json"}, namespace=self.namespace ) def updatePIDData(self, message, _data=""): @@ -438,7 +440,7 @@ def updatePIDData(self, message, _data=""): ''' data = json.dumps({"command": message, "data": _data}) socketio.emit( - "message", {"command": "updatePIDData", "data": data, "dataFormat": "json"}, namespace="/MaslowCNC" + "message", {"command": "updatePIDData", "data": data, "dataFormat": "json"}, namespace=self.namespace ) def sendGcodeUpdate(self): @@ -452,19 +454,19 @@ def sendGcodeUpdate(self): # turn on spinner on UI clients socketio.emit("message", {"command": "showFPSpinner", "data": len(self.app.data.compressedGCode3D), "dataFormat": "int"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) # pause to let the spinner get turned on. time.sleep(0.25) # send the data. Once processed by the UI client, the client will turn off the spinner. socketio.emit("message", {"command": "gcodeUpdateCompressed", "data": self.app.data.compressedGCode3D, "dataFormat": "base64"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) self.app.data.console_queue.put("Sent Gcode compressed") else: #send "" if there is no compressed data (i.e., because there's no gcode to compress) socketio.emit("message", {"command": "gcodeUpdateCompressed", "data": "", "dataFormat": "base64"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) def sendBoardUpdate(self): ''' @@ -477,7 +479,7 @@ def sendBoardUpdate(self): self.app.data.console_queue.put("Sending Board Data") socketio.emit("message", {"command": "boardDataUpdate", "data": boardData, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) self.app.data.console_queue.put("Sent Board Data") cutData = self.app.data.boardManager.getCurrentBoard().getCompressedCutData() @@ -485,11 +487,11 @@ def sendBoardUpdate(self): self.app.data.console_queue.put("Sending Board Cut Data compressed") socketio.emit("message", {"command": "showFPSpinner", "data": 1, "dataFormat": "int"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) time.sleep(0.25) socketio.emit("message", {"command": "boardCutDataUpdateCompressed", "data": cutData, "dataFormat": "base64"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) self.app.data.console_queue.put("Sent Board Cut Data compressed") def unitsUpdate(self): @@ -502,7 +504,7 @@ def unitsUpdate(self): ) data = json.dumps({"setting": "units", "value": units}) socketio.emit("message", {"command": "requestedSetting", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) def distToMoveUpdate(self): ''' @@ -514,7 +516,7 @@ def distToMoveUpdate(self): ) data = json.dumps({"setting": "distToMove", "value": distToMove}) socketio.emit("message", {"command": "requestedSetting", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) def unitsUpdateZ(self): ''' @@ -526,7 +528,7 @@ def unitsUpdateZ(self): ) data = json.dumps({"setting": "unitsZ", "value": unitsZ}) socketio.emit("message", {"command": "requestedSetting", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) def distToMoveUpdateZ(self): ''' @@ -538,7 +540,7 @@ def distToMoveUpdateZ(self): ) data = json.dumps({"setting": "distToMoveZ", "value": distToMoveZ}) socketio.emit("message", {"command": "requestedSetting", "data": data, "dataFormat": "json"}, - namespace="/MaslowCNC", ) + namespace=self.namespace, ) def processMessage(self, _message): ''' @@ -549,6 +551,7 @@ def processMessage(self, _message): ''' # parse the message to get to its components msg = json.loads(_message) + self.app.data.console_queue.put(f"{__name__}: processMessage command:{msg['command']}, message:{msg['message']}") if msg["command"] == "WebMCP": self.sendWebMCPMessage(msg["message"]) if msg["command"] == "SendAlarm": @@ -577,7 +580,7 @@ def processMessage(self, _message): elif msg["message"] == "clearAlarm": msg["data"] = json.dumps({"data": ""}) socketio.emit("message", {"command": msg["message"], "data": msg["data"], "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) # I'm pretty sure this can be cleaned up into just a continuation of elif's else: if msg["message"] == "setAsPause": @@ -595,12 +598,12 @@ def processMessage(self, _message): msg["message"] = "getZLimits" msg["data"] = json.dumps({"maxZlimit": max, "minZlimit": min}) socketio.emit("message", {"command": msg["message"], "data": msg["data"], "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) # I think I was working on clearing on an issue with the formatting of messages so I added this. I think the # only function that calls it is the serialPortThread when webcontrol connects to the arduino. elif msg["command"] == "TextMessage": socketio.emit("message", {"command": "controllerMessage", "data": msg["data"], "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) # Alerts activate the modal. If alerts are sent on top of each other, it can mess up the UI client display. elif msg["command"] == "Alert": self.activateModal(msg["message"], msg["data"], "alert") @@ -618,7 +621,7 @@ def sendCalibrationImage(self, message, _data): data = json.dumps({"command": message, "data": _data}) socketio.emit( - "message", {"command": "updateCalibrationImage", "data": data, "dataFormat": "json"}, namespace="/MaslowCNC" + "message", {"command": "updateCalibrationImage", "data": data, "dataFormat": "json"}, namespace=self.namespace ) def performHealthCheck(self): @@ -630,6 +633,7 @@ def performHealthCheck(self): ''' currentTime = time.time() if currentTime - self.lastHealthCheck > 5: + self.app.data.console_queue.put(f"{__name__}: performing health check") self.lastHealthCheck = currentTime load = max(psutil.cpu_percent(interval=None, percpu=True)) weAreBufferingLines = bool(int(self.app.data.config.getValue("Maslow Settings", "bufferOn"))) @@ -642,8 +646,7 @@ def performHealthCheck(self): "bufferSize": bufferSize, } socketio.emit("message", {"command": "healthMessage", "data": json.dumps(healthData), "dataFormat": "json"}, - namespace="/MaslowCNC") - self.performStatusCheck(True) + namespace=self.namespace) def performStatusCheck(self, healthCheckCalled=False): ''' @@ -673,7 +676,7 @@ def performStatusCheck(self, healthCheckCalled=False): } socketio.emit("message", {"command": "statusMessage", "data": json.dumps(statusData), "dataFormat": "json"}, - namespace="/MaslowCNC") + namespace=self.namespace) def isChainLengthZero(self, msg): #Message: Unable to find valid machine position for chain lengths 0.00, 0.00 Left Chain Length @@ -683,4 +686,3 @@ def isChainLengthZero(self, msg): if msg.find(", 0.00") != -1: return True return False - diff --git a/Background/WebMCPProcessor.py b/Background/WebMCPProcessor.py index 280ea23b..aa7cb1c8 100644 --- a/Background/WebMCPProcessor.py +++ b/Background/WebMCPProcessor.py @@ -34,7 +34,7 @@ def connect(self, _app): class ConsoleProcessor(MakesmithInitFuncs): def start(self): - print("Starting Console Queue Processor") + print(f"{__name__}: Starting Console Queue Processor") while True: time.sleep(0.001) while ( diff --git a/Background/webcamVideoStream.py b/Background/webcamVideoStream.py index 8b601dc1..92fc7858 100644 --- a/Background/webcamVideoStream.py +++ b/Background/webcamVideoStream.py @@ -31,7 +31,7 @@ def __init__(self, src=0): # be stopped #self.stopped = True #self.suspended = False - print("Camera initialized") + print(f"{__name__}: Camera initialized") def getSettings(self, src=0): cameraOff = False @@ -68,7 +68,7 @@ def getSettings(self, src=0): def start(self, src = 0): # start the thread to read frames from the video stream - print("Starting camera thread") + print(f"{__name__}: Starting camera thread") if self.stream is None: self.stream = cv2.VideoCapture(src) (self.grabbed, self.frame) = self.stream.read() @@ -81,11 +81,11 @@ def start(self, src = 0): self.th = threading.Thread(target=self.update) self.th.daemon = True self.th.start() - print("Camera thread started") + print(f"{__name__}: Camera thread started") #self.data.ui_queue.put("Action:updateCamera_on") self.data.ui_queue1.put("Action", "updateCamera", "on") else: - print("Camera already started") + print(f"{__name__}: Camera already started") return self def update(self): @@ -117,7 +117,7 @@ def update(self): def read(self): # return the frame most recently read - #print("Reading camera frame") + #print(f"{__name__}: Reading camera frame") if self.suspended: (self.grabbed, self.frame) = self.stream.read() self.suspended = False @@ -131,7 +131,7 @@ def read(self): def stop(self): # indicate that the thread should be stopped - print("Stopping camera") + print(f"{__name__}: Stopping camera") self.stopped = True def status(self): @@ -152,7 +152,7 @@ def changeSetting(self, key, value): self.setVideoSize() if key == 'cameraSleep' and value != self.cameraSleep: if value<1: - print("changing sleep interval") + print(f"{__name__}: changing sleep interval") self.cameraSleep = value if self.stream is not None: self.stopped = True diff --git a/Connection/nonVisibleWidgets.py b/Connection/nonVisibleWidgets.py index 21f02d6a..53f88dcc 100644 --- a/Connection/nonVisibleWidgets.py +++ b/Connection/nonVisibleWidgets.py @@ -95,13 +95,13 @@ def setUpData(self, data): if data.pyInstallPlatform == "linux": _platform = distro.linux_distribution()[0].lower() - print("##") - print(_platform) - print("##") + print(f"{__name__}: ##") + print(f"{__name__}: {_platform}") + print(f"{__name__}: ##") if _platform.find("raspbian") != -1: data.pyInstallPlatform = "rpi" - print("----") - print(data.pyInstallPlatform) + print(f"{__name__}: ----") + print(f"{__name__}: {data.pyInstallPlatform}") if getattr(sys, "frozen", False): if hasattr(sys, "_MEIPASS"): @@ -112,8 +112,8 @@ def setUpData(self, data): else: data.pyInstallType = "singledirectory" - print(data.pyInstallType) - print("----") + print(f"{__name__}: {data.pyInstallType}") + print(f"{__name__}: ----") self.serialPort.setUpData(data) self.gcodeFile.setUpData(data) diff --git a/Connection/serialPortThread.py b/Connection/serialPortThread.py index b1fed10d..093e422f 100644 --- a/Connection/serialPortThread.py +++ b/Connection/serialPortThread.py @@ -47,7 +47,7 @@ def _write(self, message, isQuickCommand=False): message = message + "\n" if len(message) > 1: - self.data.console_queue.put("Sending: " + str(message).rstrip('\n')) + self.data.console_queue.put(f"{__name__}: Sending: " + str(message).rstrip('\n')) self.bufferSpace = self.bufferSpace - len( message @@ -100,12 +100,12 @@ def _write(self, message, isQuickCommand=False): #print("Set positioning mode: " + str(positioningMode)) self.data.logger.writeToLog("Sent: " + str(message.decode())) except: - self.data.console_queue.put("write issue") + self.data.console_queue.put(f"{__name__}: write issue") self.data.logger.writeToLog("Send FAILED: " + str(message.decode())) self.lastWriteTime = time.time() else: - self.data.console_queue.put("Skipping: " + str(message).rstrip('\n')) + self.data.console_queue.put(f"{__name__}: Skipping: " + str(message).rstrip('\n')) def _getFirmwareVersion(self): ''' @@ -169,7 +169,7 @@ def sendNextLine(self): else: self.data.uploadFlag = 0 self.data.gcodeIndex = 0 - self.data.console_queue.put("Gcode Ended") + self.data.console_queue.put(f"{__name__}: Gcode Ended") def managePause(self, line): if line.find("M0 ") != -1 or line.find("M00") != -1 or line.find("M1 ") != -1 or line.find("M01") != -1: @@ -186,8 +186,8 @@ def manageToolChange(self, line): # if this is a the same tool as the controller is currently tracking, it will continue on. # first, determine the tool being called for... toolNumber = int(self.extractGcodeValue(line, 'T', 0)) - print(toolNumber) - print(self.data.currentTool) + self.data.console_queue.put(f"{__name__}: {toolNumber}") + self.data.console_queue.put(f"{__name__}: {self.data.currentTool}") # so, in the first case... if toolNumber != self.data.currentTool: # set uploadFlag to -1 to turn off sending more lines (after this one) @@ -219,9 +219,9 @@ def closeConnection(self): if self.serialInstance is not None: self.serialInstance.close() self.data.serialPort.serialPortRequest = "Closed" - print("connection closed at serialPortThread") + self.data.console_queue.put(f"{__name__}: connection closed at serialPortThread") else: - print("serial Instance is none??") + self.data.console_queue.put(f"{__name__}: serial Instance is none??") return @@ -235,16 +235,14 @@ def getmessage(self): # check for serial version being > 3 if float(serial.VERSION[0]) < 3: self.data.ui_queue1.put("Alert", "Incompability Detected", - "Pyserial version 3.x is needed, but version " - + serial.VERSION - + " is installed" + f"Pyserial version 3.x is needed, but version {serial.VERSION} is installed" ) self.weAreBufferingLines = bool(int(self.data.config.getValue("Maslow Settings", "bufferOn")) ) try: self.data.comport = self.data.config.getValue("Maslow Settings", "COMport") - connectMessage = "Trying to connect to controller on " +self.data.comport + connectMessage = f"{__name__}: Trying to connect to controller on COM port {self.data.comport}" self.data.console_queue.put(connectMessage) self.serialInstance = serial.Serial( self.data.comport, 57600, timeout=0.25 @@ -253,7 +251,7 @@ def getmessage(self): #self.data.console_queue.put(self.data.comport + " is unavailable or in use") pass else: - self.data.console_queue.put("\r\nConnected on port " + self.data.comport + "\r\n") + self.data.console_queue.put(f"\r\n{__name__}: Connected on port {self.data.comport}\r\n") self.data.ui_queue1.put("Action", "connectionStatus", {'status': 'connected', 'port': self.data.comport, 'fakeServoStatus': self.data.fakeServoStatus}) self.data.ui_queue1.put("TextMessage", "", "Connected on port " + self.data.comport) @@ -281,7 +279,7 @@ def getmessage(self): # check to see if the serail port needs to be closed (for firmware upgrade) if self.data.serialPort.serialPortRequest == "requestToClose": - print("processing request to close") + self.data.console_queue.put(f"{__name__}: processing request to close") self.closeConnection() # do not change status just yet... return @@ -354,7 +352,7 @@ def getmessage(self): if self.bufferSpace > len(line): self.sendNextLine() except IndexError: - self.data.console_queue.put("index error when reading gcode") + self.data.console_queue.put(f"{__name__}: index error when reading gcode") # we don't want the whole serial thread to close if the gcode can't be sent because of an # index error (file deleted...etc) else: @@ -365,7 +363,7 @@ def getmessage(self): # Check for serial connection loss # ------------------------------------------------------------------------------------- if time.time() - self.lastMessageTime > 5: - self.data.console_queue.put("Connection Timed Out") + self.data.console_queue.put(f"{__name__}: Connection Timed Out") if self.data.uploadFlag > 0: self.data.ui_queue1.put("Alert", "Connection Lost", "Message: USB connection lost. This has likely caused the machine to loose it's calibration, which can cause erratic behavior. It is recommended to stop the program, remove the sled, and perform the chain calibration process. Press Continue to override and proceed with the cut.") @@ -410,4 +408,3 @@ def findEndOfNumber(self, textString, index): else: return i return i - diff --git a/DataStructures/logger.py b/DataStructures/logger.py index 36d2b20c..96c80530 100644 --- a/DataStructures/logger.py +++ b/DataStructures/logger.py @@ -30,13 +30,13 @@ class Logger(MakesmithInitFuncs): loggingTimeout = -1 def __init__(self): - print("Initializing Logger") + print(f"{__name__}: Initializing") self.home = str(Path.home()) # clear the old log file if not os.path.isdir(self.home + "/.WebControl"): - print("creating " + self.home + "/.WebControl directory") + print(f"{__name__}: creating {self.home} /.WebControl directory") os.mkdir(self.home + "/.WebControl") - print(self.home+"/.WebControl/"+"log.txt") + print(f"{__name__}: {self.home}/.WebControl/log.txt") with open(self.home+"/.WebControl/"+"log.txt", "a") as logFile: logFile.truncate() diff --git a/ReleaseManager/releaseManager.py b/ReleaseManager/releaseManager.py index 5844a75e..2094eccc 100644 --- a/ReleaseManager/releaseManager.py +++ b/ReleaseManager/releaseManager.py @@ -35,7 +35,7 @@ def getLatestRelease(self): def checkForLatestPyRelease(self): if True: # self.data.platform=="PYINSTALLER": - print("Checking latest pyrelease.") + print(f"{__name__}: Checking latest pyrelease.") try: enableExperimental = self.data.config.getValue( "WebControl Settings", "experimentalReleases" @@ -63,20 +63,20 @@ def checkForLatestPyRelease(self): latestVersionGithub = tag_float self.latestRelease = release - print(f"Latest pyrelease: {latestVersionGithub}") + print(f"{__name__}: Latest pyrelease: {latestVersionGithub}") if ( self.latestRelease is not None and latestVersionGithub > self.data.pyInstallCurrentVersion ): - print(f"Latest release tag: {self.latestRelease.tag_name}") + print(f"{__name__}: Latest release tag: {self.latestRelease.tag_name}") assets = self.latestRelease.get_assets() for asset in assets: if ( asset.name.find(self.data.pyInstallType) != -1 and asset.name.find(self.data.pyInstallPlatform) != -1 ): - print(asset.name) - print(asset.url) + print(f"{__name__}: {asset.name}") + print(f"{__name__}: {asset.url}") self.data.ui_queue1.put("Action", "pyinstallUpdate", "on") self.data.pyInstallUpdateAvailable = True self.data.pyInstallUpdateBrowserUrl = ( @@ -84,7 +84,7 @@ def checkForLatestPyRelease(self): ) self.data.pyInstallUpdateVersion = self.latestRelease except Exception as e: - print(f"Error checking pyrelease: {e}") + print(f"{__name__}: Error checking pyrelease: {e}") def isExperimental(self, tag): """ @@ -103,21 +103,21 @@ def isExperimental(self, tag): def processAbsolutePath(self, path): index = path.find("main.py") self.data.pyInstallInstalledPath = path[0 : index - 1] - print(self.data.pyInstallInstalledPath) + print(f"{__name__}: {self.data.pyInstallInstalledPath}") def updatePyInstaller(self, bypassCheck=False): home = self.data.config.getHome() if self.data.pyInstallUpdateAvailable == True or bypassCheck: if not os.path.exists(home + "/.WebControl/downloads"): - print("creating downloads directory") + print(f"{__name__}: creating downloads directory") os.mkdir(home + "/.WebControl/downloads") fileList = glob.glob(home + "/.WebControl/downloads/*.gz") for filePath in fileList: try: os.remove(filePath) except: - print("error cleaning download directory: ", filePath) - print("---") + print(f"{__name__}: error cleaning download directory: {filePath}") + print(f"{__name__}: ---") req = requests.get(self.data.pyInstallUpdateBrowserUrl) if ( self.data.pyInstallPlatform == "win32" @@ -127,7 +127,7 @@ def updatePyInstaller(self, bypassCheck=False): else: filename = home + "/.WebControl/downloads" open(filename, "wb").write(req.content) - print(filename) + print(f"{__name__}: {filename}") if self.data.platform == "PYINSTALLER": lhome = os.path.join(self.data.platformHome) @@ -161,20 +161,20 @@ def updatePyInstaller(self, bypassCheck=False): arguments = [filename, self.data.pyInstallInstalledPath, tool_path] command = [program_name] command.extend(arguments) - print("popening") - print(command) + print(f"{__name__}: popening") + print(f"{__name__}: {command}") subprocess.Popen(command) return True return False def make_executable(self, path): - print("1") + print(f"{__name__}: 1") mode = os.stat(path).st_mode - print("2") + print(f"{__name__}: 2") mode |= (mode & 0o444) >> 2 # copy R bits to X - print("3") + print(f"{__name__}: 3") os.chmod(path, mode) - print("4") + print(f"{__name__}: 4") def update(self, version): """ @@ -190,10 +190,10 @@ def update(self, version): asset.name.find(self.data.pyInstallType) != -1 and asset.name.find(self.data.pyInstallPlatform) != -1 ): - print(asset.name) - print(asset.url) + print(f"{__name__}: {asset.name}") + print(f"{__name__}: {asset.url}") self.data.pyInstallUpdateBrowserUrl = asset.browser_download_url - print(self.data.pyInstallUpdateBrowserUrl) + print(f"{__name__}: {self.data.pyInstallUpdateBrowserUrl}") return self.updatePyInstaller(True) - print("hmmm.. issue") + print(f"{__name__}: hmmm.. issue") return False diff --git a/WebPageProcessor/webPageProcessor.py b/WebPageProcessor/webPageProcessor.py index 200cb86d..43a50802 100644 --- a/WebPageProcessor/webPageProcessor.py +++ b/WebPageProcessor/webPageProcessor.py @@ -11,6 +11,7 @@ class WebPageProcessor: data = None + namespace = "/MaslowCNC" def __init__(self, data): self.data = data @@ -142,7 +143,6 @@ def createWebPage(self, pageID, isMobile, args): return page, "GPIO Settings", False, "medium", "content", "footerSubmit" elif pageID == "openGCode": lastSelectedFile = self.data.config.getValue("Maslow Settings", "openFile") - print(lastSelectedFile) lastSelectedDirectory = self.data.config.getValue("Computed Settings", "lastSelectedDirectory") home = self.data.config.getHome() homedir = home+"/.WebControl/gcode" @@ -271,7 +271,7 @@ def createWebPage(self, pageID, isMobile, args): ) return page, "Actions", False, "large", "content", False elif pageID == "zAxis": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) distToMoveZ = self.data.config.getValue("Computed Settings", "distToMoveZ") unitsZ = self.data.config.getValue("Computed Settings", "unitsZ") touchPlate = self.data.config.getValue("Advanced Settings", "touchPlate") @@ -289,7 +289,7 @@ def createWebPage(self, pageID, isMobile, args): ) return page, "Z-Axis", False, "medium", "content", False elif pageID == "setZaxis": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) minZlimit = 0 #self.data.config.getValue("Advanced Settings", "minZlimit") maxZlimit = 0 #self.data.config.getValue("Advanced Settings", "maxZlimit") distToMoveZ = self.data.config.getValue("Computed Settings", "distToMoveZ") @@ -315,7 +315,7 @@ def createWebPage(self, pageID, isMobile, args): else: fourMotor = True chainExtendLength = self.data.config.getValue("Advanced Settings", "chainExtendLength") - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) if isMobile: page = render_template("setSprockets_mobile.html", chainExtendLength=chainExtendLength, fourMotor=fourMotor) else: @@ -327,7 +327,7 @@ def createWebPage(self, pageID, isMobile, args): else: fourMotor = True chainExtendLength = self.data.config.getValue("Advanced Settings", "chainExtendLength") - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) if isMobile: page = render_template("resetChains_mobile.html", chainExtendLength=chainExtendLength, fourMotor=fourMotor) else: @@ -335,7 +335,7 @@ def createWebPage(self, pageID, isMobile, args): return page, "Reset Chains", False, "medium", "content", False elif pageID == "triangularCalibration": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) motorYoffset = self.data.config.getValue("Maslow Settings", "motorOffsetY") rotationRadius = self.data.config.getValue("Advanced Settings", "rotationRadius") chainSagCorrection = self.data.config.getValue( @@ -350,7 +350,7 @@ def createWebPage(self, pageID, isMobile, args): ) return page, "Triangular Calibration", True, "medium", "content", False elif pageID == "opticalCalibration": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) opticalCenterX = self.data.config.getValue("Optical Calibration Settings", "opticalCenterX") opticalCenterY = self.data.config.getValue("Optical Calibration Settings", "opticalCenterY") scaleX = self.data.config.getValue("Optical Calibration Settings", "scaleX") @@ -370,7 +370,7 @@ def createWebPage(self, pageID, isMobile, args): page = render_template("opticalCalibration.html", pageID="opticalCalibration", opticalCenterX=opticalCenterX, opticalCenterY=opticalCenterY, scaleX=scaleX, scaleY=scaleY, gaussianBlurValue=gaussianBlurValue, cannyLowValue=cannyLowValue, cannyHighValue=cannyHighValue, autoScanDirection=autoScanDirection, markerX=markerX, markerY=markerY, tlX=tlX, tlY=tlY, brX=brX, brY=brY, calibrationExtents=calibrationExtents, isMobile=isMobile, positionTolerance=positionTolerance) return page, "Optical Calibration", True, "large", "content", False elif pageID == "holeyCalibration": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) motorYoffset = self.data.config.getValue("Maslow Settings", "motorOffsetY") distanceBetweenMotors = self.data.config.getValue("Maslow Settings", "motorSpacingX") leftChainTolerance = self.data.config.getValue("Advanced Settings", "leftChainTolerance") @@ -385,7 +385,7 @@ def createWebPage(self, pageID, isMobile, args): ) return page, "Holey Calibration", True, "medium", "content", False elif pageID == "quickConfigure": - socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace="/MaslowCNC") + socketio.emit("closeModals", {"data": {"title": "Actions"}}, namespace=self.namespace) motorOffsetY = self.data.config.getValue("Maslow Settings", "motorOffsetY") rotationRadius = self.data.config.getValue("Advanced Settings", "rotationRadius") kinematicsType = self.data.config.getValue("Advanced Settings", "kinematicsType") diff --git a/config/config.py b/config/config.py index 87fa7d96..d6a3e6d6 100644 --- a/config/config.py +++ b/config/config.py @@ -34,28 +34,28 @@ def __init__(self): self.home = str(Path.home()) if hasattr(sys, '_MEIPASS'): self.home1 = os.path.join(sys._MEIPASS) - print(self.home1) + print(f"{__name__}: {self.home1}") ''' This portion creates directories that are missing and creates a new webcontrol.json file if this is the first run (copies defaultwebcontrol.json) ''' - print("Initializing Configuration") + print(f"{__name__}: Initializing") if not os.path.isdir(self.home+"/.WebControl"): - print("creating "+self.home+"/.WebControl directory") + print(f"{__name__}: creating {self.home}/.WebControl directory") os.mkdir(self.home+"/.WebControl") if not os.path.exists(self.home+"/.WebControl/webcontrol.json"): - print("copying defaultwebcontrol.json to "+self.home+"/.WebControl/") + print(f"{__name__}: copying defaultwebcontrol.json to {self.home}/.WebControl/") copyfile(self.home1+"/defaultwebcontrol.json",self.home+"/.WebControl/webcontrol.json") self.firstRun = True if not os.path.isdir(self.home+"/.WebControl/gcode"): - print("creating "+self.home+"/.WebControl/gcode directory") + print(f"{__name__}: creating {self.home}/.WebControl/gcode directory") os.mkdir(self.home+"/.WebControl/gcode") if not os.path.isdir(self.home+"/.WebControl/imports"): - print("creating "+self.home+"/.WebControl/imports directory") + print(f"{__name__}: creating {self.home}/.WebControl/imports directory") os.mkdir(self.home+"/.WebControl/imports") if not os.path.isdir(self.home+"/.WebControl/boards"): - print("creating "+self.home+"/.WebControl/boards directory") + print(f"{__name__}: creating {self.home}/.WebControl/boards directory") os.mkdir(self.home+"/.WebControl/boards") with open(self.home+"/.WebControl/webcontrol.json", "r") as infile: self.settings = json.load(infile) @@ -83,11 +83,11 @@ def __init__(self): break if found == False: if sectionFound: - print("section found") + print(f"{__name__}: section found") else: - print("section not found") + print(f"{__name__}: section not found") self.settings[section]=[] - print(section+"->"+self.defaults[section][x]["key"]+" was not found..") + print(f"{__name__}: {section}->{self.defaults[section][x]['key']} was not found..") t = {} if "default" in self.defaults[section][x]: t["default"]=self.defaults[section][x]["default"] @@ -109,7 +109,7 @@ def __init__(self): t["options"]=self.defaults[section][x]["options"] self.settings[section].append(t) - print("added "+section+"->"+self.settings[section][len(self.settings[section])-1]["key"]) + print(f"{__name__}: added {section}->{self.settings[section][len(self.settings[section])-1]['key']}") updated = True ''' @@ -118,7 +118,7 @@ def __init__(self): ''' if updated: with open(self.home+"/.WebControl/webcontrol.json", "w") as outfile: - # print ("writing file") + # print(f"{__name__}: writing file") json.dump( self.settings, outfile, sort_keys=True, indent=4, ensure_ascii=False ) @@ -133,7 +133,7 @@ def __init__(self): for item in dir: if item.startswith("webcontrol"): if item.endswith("gz") or item.endswith("zip") or item.endswith("dmg"): - print("Removing file:"+item) + print(f"{__name__}: Removing file: {item}") os.remove(os.path.join(dirName, item)) def checkForTouchedPort(self): @@ -144,17 +144,17 @@ def checkForTouchedPort(self): ''' home = self.home path = home+"/.WebControl/webcontrol-*.port" - print(path) + print(f"{__name__}: {path}") try: for filename in glob.glob(path): - print(filename) + print(f"{__name__}: {filename}") port = filename.split("-") port = port[1].split(".port") - print(port[0]) + print(f"{__name__}: {port[0]}") self.data.config.setValue("WebControl Settings", "webPort", port[0]) os.remove(filename) except Exception as e: - print(e) + print(f"{__name__}: {e}") return False return True @@ -727,7 +727,7 @@ def parseFirmwareVersions(self): home = "." if hasattr(sys, '_MEIPASS'): home = os.path.join(sys._MEIPASS) - print(self.home) + print(f"{__name__}: {self.home}") path = home+"/firmware/madgrizzle/*.hex" for filename in glob.glob(path): version = filename.split("-") @@ -789,7 +789,7 @@ def firmwareKeyValue(self, value): try: return fmt.format(value) except: - print('firmwareKeyString Exception: value = ' + str(value)) + print(f"{__name__}: firmwareKeyString Exception: value = {str(value)}") return str(value) def reloadWebControlJSON(self): @@ -802,5 +802,5 @@ def reloadWebControlJSON(self): self.settings = json.load(infile) return True except: - print("error reloading WebControlJSON") + print(f"{__name__}: error reloading WebControlJSON") return False