Skip to content

Commit ebb8beb

Browse files
authored
Feature/custom launcher (#57)
Support custom launchers, fixes #50
1 parent b13632c commit ebb8beb

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Obviously, this source is read-only: you cannot upload PDFs to it.
143143
"timeout": 3,
144144
"persist_cache": true,
145145
"use_banner": "remy-banner.png"
146+
"launchers": ["xochitl", "remux", "tarnish", "draft"],
147+
"enable_webui_export": false
146148
}
147149
```
148150

@@ -161,6 +163,15 @@ The cache is kept across runs, and files are re-downloaded if modified date or s
161163
This might leave behind some files and might miss some updates.
162164
By setting `persist_cache` to `true` the cache is cleared every time.
163165

166+
The `enable_webui_export` determines if Remy should include the option of using the WebUI of the reMarkable to generate exports of documents.
167+
This is only available if the launcher is `xochitl` and `use_banner` is false.
168+
169+
The `launchers` option is a list of launchers that you want supported.
170+
Remy will detect which one is currently active using `systemctl`.
171+
This is useful when rebooting the launcher to ensure that the changes are picked up on the tablet.
172+
By default, Remy looks for `xochitl`, `remux`, `tarnish`, and `draft`.
173+
174+
164175
#### Rsync source
165176

166177
```json
@@ -175,7 +186,9 @@ By setting `persist_cache` to `true` the cache is cleared every time.
175186
"use_banner": "remy-banner.png",
176187
"cache_mode": "on_demand",
177188
"rsync_path": "/path/to/local/rsync",
178-
"rsync_options": [ "--rsync-path=/opt/bin/rsync" ]
189+
"rsync_options": [ "--rsync-path=/opt/bin/rsync" ],
190+
"launchers": ["xochitl", "remux", "tarnish", "draft"],
191+
"enable_webui_export": false
179192
}
180193
```
181194

remy/remarkable/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class RemyConfigException(Exception):
5656
}
5757

5858

59+
LAUNCHERS = ["xochitl", "remux", "tarnish", "draft"]
60+
5961
SOURCE_DEFAULTS = {
6062
"name": "reMarkable",
6163
"hidden": False,
@@ -64,6 +66,7 @@ class RemyConfigException(Exception):
6466
"username": "root",
6567
"host_key_policy": "ask",
6668
"timeout": 3,
69+
"launchers": LAUNCHERS,
6770
"use_banner": False,
6871
"enable_webui_export": False
6972
}

remy/remarkable/filesource.py

+33-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from threading import RLock
1111

1212
from remy.utils import log
13+
from remy.remarkable.config import LAUNCHERS
1314

1415

1516

@@ -175,11 +176,13 @@ class LiveFileSourceSSH(FileSource):
175176
'/usr/share/remarkable/templates'
176177
)
177178

179+
_launcher = None
180+
178181
_allUids = None
179182

180183
_dirty = False
181184

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):
183186
self.ssh = ssh
184187
self.name = name
185188
self.persist_cache = persist_cache
@@ -194,21 +197,34 @@ def __init__(self, ssh, id='', name="SSH", cache_dir=None, username=None, remote
194197
shutil.rmtree(cache_dir, ignore_errors=True)
195198
self._makeLocalPaths()
196199

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+
199211
if remote_documents:
200212
self.remote_roots[0] = remote_documents
201213
if remote_templates:
202214
self.remote_roots[1] = remote_templates
203215

204216
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:
208224
_,out,_ = ssh.exec_command(utils_path + "/remarkable-splash '%s'" % use_banner)
209225
out.channel.recv_exit_status()
210226
else:
211-
log.warning("I could not stop xochitl")
227+
log.warning(f"I could not stop {self._launcher}")
212228

213229
self.sftp = ssh.open_sftp()
214230
self.scp = self.sftp
@@ -324,18 +340,18 @@ def cleanup(self):
324340
if not self.persist_cache:
325341
log.debug("Clearing cache")
326342
shutil.rmtree(self.cache_dir, ignore_errors=True)
327-
self.refreshXochitl()
343+
self.refreshLauncher()
328344

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):
331347
try:
332-
_,out,_ = self.ssh.exec_command("/bin/systemctl restart xochitl")
348+
_,out,_ = self.ssh.exec_command(f"/bin/systemctl restart {self._launcher}")
333349
if out.channel.recv_exit_status() == 0:
334350
self._dirty = False
335351
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.")
339355
log.debug("SSH Error: %s", e)
340356

341357
def listItems(self):
@@ -420,10 +436,10 @@ class LiveFileSourceRsync(LiveFileSourceSSH):
420436
def __init__(self, ssh, data_dir, name="Rsync",
421437
username="root", host="10.11.99.1", key=None,
422438
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):
424440
LiveFileSourceSSH.__init__(self, ssh, name=name, cache_dir=data_dir,
425441
remote_documents=remote_documents, remote_templates=remote_templates,
426-
use_banner=use_banner, connect=False)
442+
use_banner=use_banner, connect=False, launchers=launchers)
427443

428444
log.info("DATA STORED IN:\n\t%s\n\t%s", self.local_roots[0], self.local_roots[1])
429445

@@ -553,6 +569,6 @@ def prefetchDocument(self, uid, progress=None, force=False):
553569

554570
def cleanup(self):
555571
log.debug("CLEANUP: %s", self._dirty)
556-
self.refreshXochitl()
572+
self.refreshLauncher()
557573

558574

0 commit comments

Comments
 (0)