1
- #!/usr/bin/python3 -u
1
+ #!/usr/bin/python3
2
+
2
3
'Program to run plugins to inhibit system sleep/suspend.'
3
4
# Mark Blakeney, Jul 2020.
4
5
22
23
23
24
TIMEMULTS = {'s' : 1 , 'm' : 60 , 'h' : 3600 }
24
25
26
+ def log (msg ):
27
+ print (msg , flush = True )
28
+
25
29
def conv_to_secs (val ):
26
30
'Convert given time string to float seconds'
27
31
# Default input time value (without qualifier) is minutes
@@ -91,7 +95,7 @@ def __init__(self, index, prog, progname, period, period_on,
91
95
self .icmd = shlex .split (f'{ inhibitor_prog } { what } --who="{ progname } " '
92
96
f'--why="{ self .name } " { prog } -s { period_on } -i "{ cmd } "' )
93
97
94
- print (f'{ self .name } [{ path } ] configured @ { period_str } /{ period_on_str } ' )
98
+ log (f'{ self .name } [{ path } ] configured @ { period_str } /{ period_on_str } ' )
95
99
96
100
async def run (self ):
97
101
'Worker function which runs as a asyncio task for each plugin'
@@ -102,16 +106,16 @@ async def run(self):
102
106
while return_code == SUSP_CODE :
103
107
if self .is_inhibiting is not True :
104
108
self .is_inhibiting = True
105
- print (f'{ self .name } is inhibiting '
106
- f'suspend (return={ return_code } )' )
109
+ log (f'{ self .name } is inhibiting '
110
+ f'suspend (return={ return_code } )' )
107
111
108
112
proc = await asyncio .create_subprocess_exec (* self .icmd )
109
113
return_code = await proc .wait ()
110
114
111
115
if self .is_inhibiting is not False :
112
116
self .is_inhibiting = False
113
- print (f'{ self .name } is not inhibiting '
114
- f'suspend (return={ return_code } )' )
117
+ log (f'{ self .name } is not inhibiting '
118
+ f'suspend (return={ return_code } )' )
115
119
116
120
await asyncio .sleep (self .period )
117
121
@@ -133,7 +137,7 @@ def init():
133
137
base_dir = Path (__file__ ).resolve ().parent
134
138
135
139
if args .package_dir :
136
- print (base_dir )
140
+ log (base_dir )
137
141
sys .exit ()
138
142
139
143
# This instance may be a child invocation merely to run and check
@@ -165,7 +169,7 @@ def init():
165
169
continue
166
170
167
171
vers = res .stdout .split ('\n ' )[0 ].strip ()
168
- print (f'{ progname } using { iprog } , { vers } ' )
172
+ log (f'{ progname } using { iprog } , { vers } ' )
169
173
inhibitor_prog = iprog
170
174
171
175
if not inhibitor_prog :
0 commit comments