Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom launcher #57

Merged
merged 4 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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
Expand All @@ -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
}
```

Expand Down
3 changes: 3 additions & 0 deletions remy/remarkable/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class RemyConfigException(Exception):
}


LAUNCHERS = ["xochitl", "remux", "tarnish", "draft"]

SOURCE_DEFAULTS = {
"name": "reMarkable",
"hidden": False,
Expand All @@ -64,6 +66,7 @@ class RemyConfigException(Exception):
"username": "root",
"host_key_policy": "ask",
"timeout": 3,
"launchers": LAUNCHERS,
"use_banner": False,
"enable_webui_export": False
}
Expand Down
50 changes: 33 additions & 17 deletions remy/remarkable/filesource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from threading import RLock

from remy.utils import log
from remy.remarkable.config import LAUNCHERS



Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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()