Last active
November 7, 2022 17:26
-
-
Save gentoo90/08325ff68a27e09bc7e712412ebb5d93 to your computer and use it in GitHub Desktop.
Maestral plugin for caja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Maestral (Dropbox open source client) integration for Caja (MATE file manager) | |
1) Put it into ~/.local/share/caja-python/extensions | |
2) Install python-caja: | |
$ sudo apt-get install python-caja | |
To see caja output in terminal: | |
$ caja -q && caja | |
''' | |
from os import path | |
from urllib import parse | |
import logging | |
from maestral import daemon | |
from maestral.constants import FileStatus | |
import gi | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import GLib, Caja, GObject | |
DAEMON_CHECK_INTERVAL = 2 | |
logging.basicConfig( | |
filename=path.expanduser('~/.cache/maestral/caja-maestral.log'), level=logging.INFO) | |
def _get_item_path(item): | |
uri_raw = item.get_uri() | |
if len(uri_raw) < 7: | |
return '' | |
return path.normpath(parse.unquote(uri_raw[7:])) | |
class MaestralProvider(GObject.GObject, Caja.InfoProvider): | |
def __init__(self): | |
try: | |
self.maestral = None | |
GLib.timeout_add_seconds( | |
DAEMON_CHECK_INTERVAL, self._try_init_maestral) | |
logging.debug('plugin startedg') | |
except Exception as ex: | |
logging.exception(ex) | |
def update_file_info(self, item): | |
try: | |
if item.get_uri_scheme() != 'file': | |
return Caja.OperationResult.COMPLETE | |
if self.maestral is None: | |
return Caja.OperationResult.FAILED | |
item_path = _get_item_path(item) | |
if not item_path.startswith(self.maestral.dropbox_path): | |
return Caja.OperationResult.COMPLETE | |
item_status = self.maestral.get_file_status(item_path) | |
logging.debug(f'[{item_status}] {item_path}') | |
if item_status == FileStatus.Synced.value: | |
item.add_emblem('ok') | |
if item_status in [FileStatus.Downloading.value, FileStatus.Uploading.value]: | |
item.add_emblem('synchronizing') | |
if item_status == FileStatus.Unwatched.value: | |
item.add_emblem('unreadable') | |
if item_status == FileStatus.Error.value: | |
item.add_emblem('important') | |
return Caja.OperationResult.COMPLETE | |
except Exception as ex: | |
logging.exception(ex) | |
return Caja.OperationResult.FAILED | |
def _try_init_maestral(self): | |
logging.debug('Connectiong to the maestral daemon...') | |
try: | |
self.maestral = daemon.MaestralProxy() | |
logging.debug('Connection established') | |
return False | |
except daemon.CommunicationError as ex: | |
logging.debug('Connection failed') | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment