MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / _exec_shutdown

Function _exec_shutdown

app/local_system.py:25–48  ·  view source on GitHub ↗
(restart_after)

Source from the content-addressed store, hash-verified

23
24
25def _exec_shutdown(restart_after):
26 if restart_after:
27 param = '--reboot'
28 else:
29 param = '--poweroff'
30
31 try:
32 # The command arguments are trusted because they aren't based on user
33 # input.
34 result = subprocess.run( # noqa: S603
35 ['/usr/bin/sudo', '/sbin/shutdown', param, 'now'],
36 capture_output=True,
37 text=True,
38 check=True)
39 except subprocess.CalledProcessError as e:
40 raise ShutdownError(e) from e
41 if 'failed' in result.stderr.lower():
42 raise ShutdownError(result.stdout + result.stderr)
43
44 if result.stdout:
45 logger.info(result.stdout)
46 if result.stderr:
47 logger.info(result.stderr)
48 return True

Callers 2

shutdownFunction · 0.85
restartFunction · 0.85

Calls 2

ShutdownErrorClass · 0.85
runMethod · 0.80

Tested by

no test coverage detected