How to use the maestral.sync.main.Maestral 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
def start(config_name: str, running: bool, foreground: bool, verbose: bool):
    """Starts the Maestral as a daemon."""

    # do nothing if already running
    if running:
        click.echo("Maestral daemon is already running.")
        return

    from maestral.sync.main import Maestral

    # run setup if not yet linked
    if Maestral.pending_link() or Maestral.pending_dropbox_folder():
        # run setup
        m = Maestral(run=False)
        m.create_dropbox_directory()
        m.set_excluded_folders()

        m.sync.last_cursor = ""
        m.sync.last_sync = 0

    if foreground:
        # start daemon in foreground
        from maestral.sync.daemon import start_maestral_daemon
        start_maestral_daemon(config_name)
    else:
        # start daemon in subprocess
        start_daemon_subprocess_with_cli_feedback(config_name, log_to_console=verbose)
github SamSchott / maestral-dropbox / maestral / gui / setup_dialog.py View on Github external
<p align="left">
            Your Dropbox folder has been moved or deleted from its original location.
            Maestral will not work properly until you move it back. It used to be located
            at: </p><p align="left">{0}</p>
            <p align="left">
            To move it back, click "Quit" below, move the Dropbox folder back to its
            original location, and launch Maestral again.
            </p>
            <p align="left">
            To re-download your Dropbox, please select a location for your Dropbox
            folder below. Maestral will create a new folder named "{1}" in the
            selected location.</p>
            <p align="left">
            To unlink your Dropbox account from Maestral, click "Unlink" below.</p>
            
            """.format(Maestral.get_conf("main", "path"), default_dir_name))
            self.pushButtonDropboxPathCalcel.setText("Quit")
            self.stackedWidget.setCurrentIndex(2)
            self.stackedWidgetButtons.setCurrentIndex(2)
        else:
            self.stackedWidget.setCurrentIndex(0)
            self.stackedWidgetButtons.setCurrentIndex(0)
github SamSchott / maestral-dropbox / maestral / sync / daemon.py View on Github external
logger.debug(f"Starting Maestral daemon on socket '{sock_name}'")

    try:
        os.remove(sock_name)
    except FileNotFoundError:
        pass

    daemon = server.Daemon(unixsocket=sock_name)

    _write_pid(config_name)  # write PID to file

    try:
        # we wrap this in a try-except block to make sure that the PID file is always
        # removed, even when Maestral crashes for some reason

        ExposedMaestral = server.expose(Maestral)
        m = ExposedMaestral(run=run)

        daemon.register(m, f"maestral.{config_name}")
        daemon.requestLoop(loopCondition=m._loop_condition)
        daemon.close()
    except Exception:
        import traceback
        traceback.print_exc()
    finally:
        _delete_pid(config_name)  # remove PID file
github SamSchott / maestral-dropbox / maestral / gui / setup_dialog.py View on Github external
def on_verify_token_finished(self, res):

        if res == OAuth2Session.Success:
            self.auth_session.save_creds()

            # switch to next page
            self.stackedWidget.slideInIdx(2)
            self.pushButtonDropboxPathSelect.setFocus()
            self.lineEditAuthCode.clear()  # clear since we might come back on unlink

            # start Maestral after linking to Dropbox account
            self.mdbx = Maestral(run=False)
            self.mdbx.get_account_info()
        elif res == OAuth2Session.InvalidToken:
            msg = "Please make sure that you entered the correct authentication token."
            msg_box = UserDialog("Authentication failed.", msg, parent=self)
            msg_box.open()
        elif res == OAuth2Session.ConnectionFailed:
            msg = "Please make sure that you are connected to the internet and try again."
            msg_box = UserDialog("Connection failed.", msg, parent=self)
            msg_box.open()

        self.progressIndicator.stopAnimation()
        self.pushButtonAuthPageLink.setEnabled(True)
        self.lineEditAuthCode.setEnabled(True)
github SamSchott / maestral-dropbox / maestral / gui / setup_dialog.py View on Github external
self.pushButtonAuthPageLink.clicked.connect(self.on_auth_clicked)
        self.pushButtonDropboxPathCalcel.clicked.connect(self.on_reject_requested)
        self.pushButtonDropboxPathSelect.clicked.connect(self.on_dropbox_location_selected)
        self.pushButtonDropboxPathUnlink.clicked.connect(self.unlink_and_go_to_start)
        self.pushButtonFolderSelectionBack.clicked.connect(self.stackedWidget.slideInPrev)
        self.pushButtonFolderSelectionSelect.clicked.connect(self.on_folders_selected)
        self.pushButtonClose.clicked.connect(self.on_accept_requested)
        self.selectAllCheckBox.clicked.connect(self.on_select_all_clicked)

        default_dir_name = CONF.get("main", "default_dir_name")

        self.labelDropboxPath.setText(self.labelDropboxPath.text().format(default_dir_name))

        # check if we are already authenticated, skip authentication if yes
        if not pending_link:
            self.mdbx = Maestral(run=False)
            self.mdbx.get_account_info()
            self.labelDropboxPath.setText("""
            
            <p align="left">
            Your Dropbox folder has been moved or deleted from its original location.
            Maestral will not work properly until you move it back. It used to be located
            at: </p><p align="left">{0}</p>
            <p align="left">
            To move it back, click "Quit" below, move the Dropbox folder back to its
            original location, and launch Maestral again.
            </p>
            <p align="left">
            To re-download your Dropbox, please select a location for your Dropbox
            folder below. Maestral will create a new folder named "{1}" in the
            selected location.</p>
            <p align="left"></p>
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def link(config_name: str, running: bool):
    """Links Maestral with your Dropbox account."""

    if not _is_maestral_linked(config_name):
        if running:
            click.echo("Maestral is already running. Please link through the CLI or GUI.")
            return

        from maestral.sync.main import Maestral
        Maestral(run=False)

    else:
        click.echo("Maestral is already linked.")
github SamSchott / maestral-dropbox / maestral / sync / daemon.py View on Github external
from maestral.sync.utils.appdirs import get_runtime_path
        sock_name = get_runtime_path("maestral", config_name + ".sock")

        sys.excepthook = Pyro5.errors.excepthook
        maestral_daemon = client.Proxy(URI.format(config_name, "./u:" + sock_name))
        try:
            maestral_daemon._pyroBind()
            return maestral_daemon
        except Pyro5.errors.CommunicationError:
            maestral_daemon._pyroRelease()

    if fallback:
        from maestral.sync.main import Maestral, sh
        sh.setLevel(logging.CRITICAL)
        m = Maestral(run=False)
        return m
    else:
        raise Pyro5.errors.CommunicationError
github SamSchott / maestral-dropbox / maestral / cli.py View on Github external
def _is_maestral_linked(config_name):
    """
    This does not create a Maestral instance and is therefore safe to call from anywhere
    at any time.
    """
    os.environ["MAESTRAL_CONFIG"] = config_name
    from maestral.sync.main import Maestral
    if Maestral.pending_link():
        click.echo("No Dropbox account linked.")
        return False
    else:
        return True
github SamSchott / maestral-dropbox / maestral / gui / folders_dialog.py View on Github external
self.selectAllCheckBox.setEnabled(True)

    def changeEvent(self, QEvent):

        if QEvent.type() == QtCore.QEvent.PaletteChange:
            self.update_dark_mode()

    def update_dark_mode(self):
        if self.dbx_model:
            self.dbx_model.reloadData([Qt.DecorationRole])  # reload folder icons


if __name__ == "__main__":

    from maestral.sync.main import Maestral
    mdbx = Maestral(run=False)

    app = QtWidgets.QApplication(["test"])
    app.setAttribute(Qt.AA_UseHighDpiPixmaps)
    fd = FoldersDialog(mdbx)
    fd.show()
    fd.populate_folders_list()
    app.exec_()