diff --git a/README.md b/README.md index 3f21c56..4edaca6 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,8 @@ Obviously, this source is read-only: you cannot upload PDFs to it. "timeout": 3, "persist_cache": true, "use_banner": "remy-banner.png" + "launchers": ["xochitl", "remux", "tarnish", "draft"], + "enable_webui_export": false } ``` @@ -161,6 +163,15 @@ The cache is kept across runs, and files are re-downloaded if modified date or s This might leave behind some files and might miss some updates. By setting `persist_cache` to `true` the cache is cleared every time. +The `enable_webui_export` determines if Remy should include the option of using the WebUI of the reMarkable to generate exports of documents. +This is only available if the launcher is `xochitl` and `use_banner` is false. + +The `launchers` option is a list of launchers that you want supported. +Remy will detect which one is currently active using `systemctl`. +This is useful when rebooting the launcher to ensure that the changes are picked up on the tablet. +By default, Remy looks for `xochitl`, `remux`, `tarnish`, and `draft`. + + #### Rsync source ```json @@ -175,7 +186,9 @@ By setting `persist_cache` to `true` the cache is cleared every time. "use_banner": "remy-banner.png", "cache_mode": "on_demand", "rsync_path": "/path/to/local/rsync", - "rsync_options": [ "--rsync-path=/opt/bin/rsync" ] + "rsync_options": [ "--rsync-path=/opt/bin/rsync" ], + "launchers": ["xochitl", "remux", "tarnish", "draft"], + "enable_webui_export": false } ``` diff --git a/remy/remarkable/config.py b/remy/remarkable/config.py index d032857..137bb1c 100644 --- a/remy/remarkable/config.py +++ b/remy/remarkable/config.py @@ -56,6 +56,8 @@ class RemyConfigException(Exception): } +LAUNCHERS = ["xochitl", "remux", "tarnish", "draft"] + SOURCE_DEFAULTS = { "name": "reMarkable", "hidden": False, @@ -64,6 +66,7 @@ class RemyConfigException(Exception): "username": "root", "host_key_policy": "ask", "timeout": 3, + "launchers": LAUNCHERS, "use_banner": False, "enable_webui_export": False } diff --git a/remy/remarkable/filesource.py b/remy/remarkable/filesource.py index 505df9b..94cbde4 100644 --- a/remy/remarkable/filesource.py +++ b/remy/remarkable/filesource.py @@ -10,6 +10,7 @@ from threading import RLock from remy.utils import log +from remy.remarkable.config import LAUNCHERS @@ -175,11 +176,13 @@ class LiveFileSourceSSH(FileSource): '/usr/share/remarkable/templates' ) + _launcher = None + _allUids = None _dirty = False - 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): + 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): self.ssh = ssh self.name = name self.persist_cache = persist_cache @@ -194,21 +197,34 @@ def __init__(self, ssh, id='', name="SSH", cache_dir=None, username=None, remote shutil.rmtree(cache_dir, ignore_errors=True) self._makeLocalPaths() - _,out,_ = self.ssh.exec_command("echo $HOME") - out.channel.recv_exit_status() + log.debug("Supported launchers: " + ', '.join(launchers)) + for launcher in launchers: + _,out,_ = self.ssh.exec_command(f"systemctl is-active {launcher}") + if out.channel.recv_exit_status() == 0: + self._launcher = launcher + log.info("Detected launcher: %s", launcher) + break + if self._launcher is None: + log.warning("No launcher detected") + + if remote_documents: self.remote_roots[0] = remote_documents if remote_templates: self.remote_roots[1] = remote_templates if use_banner: - self._dirty = True # force restart of xochitl even when stopping failed - _,out,_ = ssh.exec_command("/bin/systemctl stop xochitl") - if out.channel.recv_exit_status() == 0: + self._dirty = True # force restart of launcher even when stopping failed + if self._launcher: + _,out,_ = ssh.exec_command(f"/bin/systemctl stop {self._launcher}") + launcher_stopped = out.channel.recv_exit_status() == 0 + else: + launcher_stopped = True + if launcher_stopped: _,out,_ = ssh.exec_command(utils_path + "/remarkable-splash '%s'" % use_banner) out.channel.recv_exit_status() else: - log.warning("I could not stop xochitl") + log.warning(f"I could not stop {self._launcher}") self.sftp = ssh.open_sftp() self.scp = self.sftp @@ -324,18 +340,18 @@ def cleanup(self): if not self.persist_cache: log.debug("Clearing cache") shutil.rmtree(self.cache_dir, ignore_errors=True) - self.refreshXochitl() + self.refreshLauncher() - def refreshXochitl(self, force=False): - if self._dirty or force: + def refreshLauncher(self, force=False): + if self._launcher and (self._dirty or force): try: - _,out,_ = self.ssh.exec_command("/bin/systemctl restart xochitl") + _,out,_ = self.ssh.exec_command(f"/bin/systemctl restart {self._launcher}") if out.channel.recv_exit_status() == 0: self._dirty = False except paramiko.SSHException as e: - log.warning("Could not restart xochitl." - "This is most probably due to the tablet going to sleep." - "A manual reboot of the tablet is recommended.") + log.warning(f"Could not restart {self._launcher}." + "This is most probably due to the tablet going to sleep." + "A manual reboot of the tablet is recommended.") log.debug("SSH Error: %s", e) def listItems(self): @@ -420,10 +436,10 @@ class LiveFileSourceRsync(LiveFileSourceSSH): def __init__(self, ssh, data_dir, name="Rsync", username="root", host="10.11.99.1", key=None, rsync_path=None, rsync_options=None, remote_documents=None, remote_templates=None, - use_banner=False, cache_mode="on_demand", known_hosts=None, host_key_policy="ask", **kw): + use_banner=False, cache_mode="on_demand", known_hosts=None, host_key_policy="ask", launchers=LAUNCHERS, **kw): LiveFileSourceSSH.__init__(self, ssh, name=name, cache_dir=data_dir, remote_documents=remote_documents, remote_templates=remote_templates, - use_banner=use_banner, connect=False) + use_banner=use_banner, connect=False, launchers=launchers) log.info("DATA STORED IN:\n\t%s\n\t%s", self.local_roots[0], self.local_roots[1]) @@ -553,6 +569,6 @@ def prefetchDocument(self, uid, progress=None, force=False): def cleanup(self): log.debug("CLEANUP: %s", self._dirty) - self.refreshXochitl() + self.refreshLauncher()