10
10
from threading import RLock
11
11
12
12
from remy .utils import log
13
+ from remy .remarkable .config import LAUNCHERS
13
14
14
15
15
16
@@ -175,11 +176,13 @@ class LiveFileSourceSSH(FileSource):
175
176
'/usr/share/remarkable/templates'
176
177
)
177
178
179
+ _launcher = None
180
+
178
181
_allUids = None
179
182
180
183
_dirty = False
181
184
182
- def __init__ (self , ssh , id = '' , name = "SSH" , cache_dir = None , username = None , remote_documents = None , remote_templates = None , use_banner = False , connect = True , utils_path = '$HOME' , persist_cache = True , ** kw ):
185
+ def __init__ (self , ssh , id = '' , name = "SSH" , cache_dir = None , username = None , remote_documents = None , remote_templates = None , use_banner = False , connect = True , utils_path = '$HOME' , persist_cache = True , launchers = LAUNCHERS , ** kw ):
183
186
self .ssh = ssh
184
187
self .name = name
185
188
self .persist_cache = persist_cache
@@ -194,21 +197,34 @@ def __init__(self, ssh, id='', name="SSH", cache_dir=None, username=None, remote
194
197
shutil .rmtree (cache_dir , ignore_errors = True )
195
198
self ._makeLocalPaths ()
196
199
197
- _ ,out ,_ = self .ssh .exec_command ("echo $HOME" )
198
- out .channel .recv_exit_status ()
200
+ log .debug ("Supported launchers: " + ', ' .join (launchers ))
201
+ for launcher in launchers :
202
+ _ ,out ,_ = self .ssh .exec_command (f"systemctl is-active { launcher } " )
203
+ if out .channel .recv_exit_status () == 0 :
204
+ self ._launcher = launcher
205
+ log .info ("Detected launcher: %s" , launcher )
206
+ break
207
+ if self ._launcher is None :
208
+ log .warning ("No launcher detected" )
209
+
210
+
199
211
if remote_documents :
200
212
self .remote_roots [0 ] = remote_documents
201
213
if remote_templates :
202
214
self .remote_roots [1 ] = remote_templates
203
215
204
216
if use_banner :
205
- self ._dirty = True # force restart of xochitl even when stopping failed
206
- _ ,out ,_ = ssh .exec_command ("/bin/systemctl stop xochitl" )
207
- if out .channel .recv_exit_status () == 0 :
217
+ self ._dirty = True # force restart of launcher even when stopping failed
218
+ if self ._launcher :
219
+ _ ,out ,_ = ssh .exec_command (f"/bin/systemctl stop { self ._launcher } " )
220
+ launcher_stopped = out .channel .recv_exit_status () == 0
221
+ else :
222
+ launcher_stopped = True
223
+ if launcher_stopped :
208
224
_ ,out ,_ = ssh .exec_command (utils_path + "/remarkable-splash '%s'" % use_banner )
209
225
out .channel .recv_exit_status ()
210
226
else :
211
- log .warning ("I could not stop xochitl " )
227
+ log .warning (f "I could not stop { self . _launcher } " )
212
228
213
229
self .sftp = ssh .open_sftp ()
214
230
self .scp = self .sftp
@@ -324,18 +340,18 @@ def cleanup(self):
324
340
if not self .persist_cache :
325
341
log .debug ("Clearing cache" )
326
342
shutil .rmtree (self .cache_dir , ignore_errors = True )
327
- self .refreshXochitl ()
343
+ self .refreshLauncher ()
328
344
329
- def refreshXochitl (self , force = False ):
330
- if self ._dirty or force :
345
+ def refreshLauncher (self , force = False ):
346
+ if self ._launcher and ( self . _dirty or force ) :
331
347
try :
332
- _ ,out ,_ = self .ssh .exec_command ("/bin/systemctl restart xochitl " )
348
+ _ ,out ,_ = self .ssh .exec_command (f "/bin/systemctl restart { self . _launcher } " )
333
349
if out .channel .recv_exit_status () == 0 :
334
350
self ._dirty = False
335
351
except paramiko .SSHException as e :
336
- log .warning ("Could not restart xochitl ."
337
- "This is most probably due to the tablet going to sleep."
338
- "A manual reboot of the tablet is recommended." )
352
+ log .warning (f "Could not restart { self . _launcher } ."
353
+ "This is most probably due to the tablet going to sleep."
354
+ "A manual reboot of the tablet is recommended." )
339
355
log .debug ("SSH Error: %s" , e )
340
356
341
357
def listItems (self ):
@@ -420,10 +436,10 @@ class LiveFileSourceRsync(LiveFileSourceSSH):
420
436
def __init__ (self , ssh , data_dir , name = "Rsync" ,
421
437
username = "root" , host = "10.11.99.1" , key = None ,
422
438
rsync_path = None , rsync_options = None , remote_documents = None , remote_templates = None ,
423
- use_banner = False , cache_mode = "on_demand" , known_hosts = None , host_key_policy = "ask" , ** kw ):
439
+ use_banner = False , cache_mode = "on_demand" , known_hosts = None , host_key_policy = "ask" , launchers = LAUNCHERS , ** kw ):
424
440
LiveFileSourceSSH .__init__ (self , ssh , name = name , cache_dir = data_dir ,
425
441
remote_documents = remote_documents , remote_templates = remote_templates ,
426
- use_banner = use_banner , connect = False )
442
+ use_banner = use_banner , connect = False , launchers = launchers )
427
443
428
444
log .info ("DATA STORED IN:\n \t %s\n \t %s" , self .local_roots [0 ], self .local_roots [1 ])
429
445
@@ -553,6 +569,6 @@ def prefetchDocument(self, uid, progress=None, force=False):
553
569
554
570
def cleanup (self ):
555
571
log .debug ("CLEANUP: %s" , self ._dirty )
556
- self .refreshXochitl ()
572
+ self .refreshLauncher ()
557
573
558
574
0 commit comments