@@ -39,6 +39,15 @@ def handle_press(*command):
3939 print ("[dry-run] " , " " .join (command ))
4040 sys .exit ()
4141
42+ if os .environ .get ("ATX_RASPI_DRY_RUN" , "" ) == "" :
43+ def handle_press (* command ):
44+ os .system (* command )
45+ sys .exit ()
46+ else :
47+ def handle_press (* command ):
48+ print ("[dry-run] " , " " .join (command ))
49+ sys .exit ()
50+
4251def diag (* msgs ):
4352 linelen = max ([len (msg ) for msg in msgs ]) + 2
4453 wrapper = "=" * linelen
@@ -92,12 +101,12 @@ def announce():
92101 if pulse_duration >= REBOOTPULSEMAXIMUM :
93102 print ()
94103 diag ("SHUTDOWN request on chip {0} from GPIO{1}, halting Rpi ..." .format (CHIP , SHUTDOWN ))
95- os . system ("poweroff" )
104+ handle_press ("poweroff" )
96105 sys .exit ()
97106 elif pulse_duration >= REBOOTPULSEMINIMUM :
98107 print ()
99108 diag ("REBOOT request on chip {0} from GPIO{1}, recycling Rpi ..." .format (CHIP , SHUTDOWN ))
100- os . system ("reboot" )
109+ handle_press ("reboot" )
101110 sys .exit ()
102111 else :
103112 pulse_start = None
@@ -125,13 +134,13 @@ def announce():
125134 if (time .time () - pulse_start >= REBOOTPULSEMAXIMUM ):
126135 print ()
127136 diag ("SHUTDOWN request from GPIO{0}, halting Rpi ..." .format (SHUTDOWN ))
128- os . system ("poweroff" )
137+ handle_press ("poweroff" )
129138 sys .exit ()
130139 shutdown_signal = GPIO .input (SHUTDOWN )
131140 if time .time () - pulse_start >= REBOOTPULSEMINIMUM :
132141 print ()
133142 diag ("REBOOT request from GPIO{0}, recycling Rpi ..." .format (SHUTDOWN ))
134- os . system ("reboot" )
143+ handle_press ("reboot" )
135144 sys .exit ()
136145 if GPIO .input (SHUTDOWN ): # before looping we must make sure the shutdown signal went low
137146 GPIO .wait_for_edge (SHUTDOWN , GPIO .FALLING )
0 commit comments