How to use the maestral.sync.daemon.MaestralProxy function in maestral

To help you get started, we’ve selected a few maestral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
"Rebuilding the index may take several minutes, depending on the size of  "
            "your Dropbox. Please do not modify any items in your local Dropbox folder "
            "during this process. Any changes to local files while rebuilding may be "
            "lost.",
            width=width
        )

        click.echo("\n".join(message1) + "\n")
        click.echo("\n".join(message2) + "\n")
        click.confirm("Do you want to continue?", abort=True)

        import time
        from concurrent.futures import ThreadPoolExecutor
        from maestral.sync.daemon import MaestralProxy

        with MaestralProxy(config_name, fallback=True) as m0:
            with ThreadPoolExecutor(max_workers=1) as executor:
                future = executor.submit(m0.rebuild_index)
                with MaestralProxy(config_name, fallback=True) as m1:
                    while future.running():
                        msg = ("\r" + m1.status).ljust(width)
                        click.echo(msg, nl=False)
                        time.sleep(1.0)

        click.echo("\rRebuilding complete.".ljust(width))

    else:
        click.echo("Maestral does not appear to be linked.")
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def level(config_name: str, level_name: str, running: bool):
    """Gets or sets the log level. Changes will take effect after restart."""
    import logging
    if level_name:
        from maestral.sync.daemon import MaestralProxy

        level_num = logging._nameToLevel[level_name]
        with MaestralProxy(config_name, fallback=True) as m:
            m.set_log_level("app", "log_level", level_num)
        click.echo("Log level set to {}.".format(level_name))
    else:
        os.environ["MAESTRAL_CONFIG"] = config_name
        from maestral.config.main import CONF

        level_num = CONF.get("app", "log_level")
        level_name = logging.getLevelName(level_num)
        click.echo("Log level:  {}".format(level_name))
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def set_dir(config_name: str, new_path: str, running: bool):
    """Change the location of your Dropbox folder."""

    if _is_maestral_linked(config_name):
        from maestral.sync.main import Maestral
        from maestral.sync.daemon import MaestralProxy
        with MaestralProxy(config_name, fallback=True) as m:
            if not new_path:
                # don't use the remote instance because we need console interaction
                new_path = Maestral._ask_for_path()
            m.move_dropbox_directory(new_path)

        click.echo("Dropbox folder moved to {}.".format(new_path))
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def status(config_name: str, running: bool):
    """Returns the current status of the Maestral daemon."""
    from maestral.sync.daemon import MaestralProxy

    try:
        with MaestralProxy(config_name) as m:
            n_errors = len(m.sync_errors)
            color = "red" if n_errors > 0 else "green"
            n_errors_str = click.style(str(n_errors), fg=color)
            click.echo("")
            click.echo("Account:       {}".format(m.get_conf("account", "email")))
            click.echo("Usage:         {}".format(m.get_conf("account", "usage")))
            click.echo("Status:        {}".format(m.status))
            click.echo("Sync errors:   {}".format(n_errors_str))
            click.echo("")

    except Pyro5.errors.CommunicationError:
        click.echo("Maestral daemon is not running.")
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def file_status(config_name: str, running: bool, local_path: str):
    """Returns the current sync status of a given file or folder."""
    from maestral.sync.daemon import MaestralProxy

    try:
        with MaestralProxy(config_name) as m:
            stat = m.get_file_status(local_path)
            click.echo(stat)

    except Pyro5.errors.CommunicationError:
        click.echo("unwatched")
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def errors(config_name: str, running: bool):
    """Lists all sync errors."""
    from maestral.sync.daemon import MaestralProxy

    try:
        with MaestralProxy(config_name) as m:
            err_list = m.sync_errors
            if len(err_list) == 0:
                click.echo("No sync errors.")
            else:
                max_path_length = max(len(err["dbx_path"]) for err in err_list)
                column_length = max(max_path_length, len("Relative path")) + 4
                click.echo("")
                click.echo("PATH".ljust(column_length) + "ERROR")
                for err in err_list:
                    c0 = "'{}'".format(err["dbx_path"]).ljust(column_length)
                    c1 = "{}. {}".format(err["title"], err["message"])
                    click.echo(c0 + c1)
                click.echo("")

    except Pyro5.errors.CommunicationError:
        click.echo("Maestral daemon is not running.")
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def ls(dropbox_path: str, running: bool, config_name: str, list_all: bool):
    """Lists contents of a Dropbox directory."""

    if not dropbox_path.startswith("/"):
        dropbox_path = "/" + dropbox_path

    if _is_maestral_linked(config_name):
        from maestral.sync.daemon import MaestralProxy
        with MaestralProxy(config_name, fallback=True) as m:
            entries = m.list_folder(dropbox_path, recursive=False)

            if not entries:
                click.echo("Could not connect to Dropbox")
                return

            excluded_status = (m.excluded_status(e["path_lower"]) for e in entries)

            # display results
            for e, ex in zip(entries, excluded_status):
                if not ex == "included":
                    excluded_str = click.style(" ({})".format(ex), bold=True)
                else:
                    excluded_str = ""
                type_str = "Folder" if e["type"] == "FolderMetadata" else "File"
                if not e["name"].startswith(".") or list_all:
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def excluded_remove(dropbox_path: str, config_name: str, running: bool):
    """Removes a folder from the excluded list and re-syncs."""

    if not dropbox_path.startswith("/"):
        dropbox_path = "/" + dropbox_path

    if dropbox_path == "/":
        click.echo(click.style("The root directory is always included.", fg="red"))
        return

    from maestral.sync.daemon import MaestralProxy

    if _is_maestral_linked(config_name):
        with MaestralProxy(config_name, fallback=True) as m:
            m.include_folder(dropbox_path)
        click.echo("Included directory '{}' in syncing.".format(dropbox_path))
github SamSchott / maestral-dropbox / maestral / sync / daemon.py View on Github external
:param str config_name: The name of the Maestral configuration to use.
    :param int timeout: Number of sec to wait for daemon to shut down before killing it.
    :returns: ``True`` if terminated gracefully, ``False`` if killed and ``None`` if the
        daemon was not running.
    :rtype: bool
    """
    import signal
    import time

    logger.debug("Stopping daemon")

    pid = get_maestral_pid(config_name)
    if pid:
        try:
            # tell maestral daemon to shut down
            with MaestralProxy(config_name) as m:
                m.stop_sync()
                m.shutdown_pyro_daemon()
        except Pyro5.errors.CommunicationError:
            logger.debug("Could not communicate with daemon")
            try:
                os.kill(pid, signal.SIGTERM)  # try to send SIGTERM to process
                logger.debug("Terminating daemon process")
            except ProcessLookupError:
                _delete_pid(config_name)
                logger.debug("Daemon was not running")
                return  # return ``None`` if process did not exist
        finally:
            # wait for maestral to carry out shutdown
            logger.debug("Waiting for shutdown")
            t0 = time.time()
            while time.time() - t0 < timeout:
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def unlink(config_name: str, running: bool):
    """Unlinks your Dropbox account."""

    if _is_maestral_linked(config_name):

        from maestral.sync.daemon import MaestralProxy

        if running:
            stop_daemon_with_cli_feedback(config_name)

        with MaestralProxy(config_name, fallback=True) as m:
            m.unlink()

        click.echo("Unlinked Maestral.")
    else:
        click.echo("Maestral is not linked.")