MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / executeCommand

Function executeCommand

src/octoprint/server/api/__init__.py:181–203  ·  view source on GitHub ↗
(command, logger)

Source from the content-addressed store, hash-verified

179 logger.info("Performing command: %s" % command)
180
181 def executeCommand(command, logger):
182 timeSleeping = 0.5
183 #if shutdown send message to plugin
184 if action == "reboot" or action == "shutdown":
185 eventManager().fire(Events.SHUTTING_DOWN, {'status': action})
186 timeSleeping = 1
187 time.sleep(timeSleeping) #add a small delay to make sure the response is sent
188
189 try:
190 p = sarge.run(command, stderr=sarge.Capture())
191 if p.returncode != 0:
192 returncode = p.returncode
193 stderr_text = p.stderr.text
194 logger.warn("Command failed with return code %i: %s" % (returncode, stderr_text))
195 if action == "reboot" or action == "shutdown":
196 eventManager().fire(Events.SHUTTING_DOWN, {'status': None})
197 else:
198 logger.info("Command executed sucessfully")
199
200 except Exception, e:
201 logger.warn("Command failed: %s" % e)
202 if command == "reboot" or command == "shutdown":
203 eventManager().fire(Events.SHUTTING_DOWN, {'status': None})
204
205 executeThread = threading.Thread(target=executeCommand, args=(command, logger))
206 executeThread.start()

Callers

nothing calls this directly

Calls 3

eventManagerFunction · 0.90
fireMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected