Example #1
0
def start(config_name: str, foreground: bool):
    """Starts the Maestral as a daemon."""

    from maestral.daemon import get_maestral_pid
    from maestral.utils.backend import pending_dropbox_folder

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

    from maestral.main import Maestral

    # run setup if not yet done
    if pending_link_cli(config_name) or pending_dropbox_folder(config_name):
        m = Maestral(config_name, run=False)
        m.reset_sync_state()
        m.create_dropbox_directory()
        m.set_excluded_items()

        del m

    # start daemon
    if foreground:
        from maestral.daemon import run_maestral_daemon
        run_maestral_daemon(config_name, run=True, log_to_stdout=True)
    else:
        start_daemon_subprocess_with_cli_feedback(config_name)
Example #2
0
def link(config_name: str, relink: bool):
    """Links Maestral with your Dropbox account."""

    if relink or pending_link_cli(config_name):
        from maestral.oauth import OAuth2Session
        from maestral.daemon import get_maestral_pid

        if get_maestral_pid(config_name):
            click.echo('Maestral is running. Please stop before linking.')
            return

        auth = OAuth2Session(config_name)
        auth.link()

    else:
        click.echo('Maestral is already linked. Use the option '
                   '\'-r\' to relink to the same account.')
Example #3
0
def start(config_name: str, foreground: bool, verbose: bool):
    """Starts the Maestral as a daemon."""

    from maestral.daemon import get_maestral_pid
    from maestral.utils.backend import pending_dropbox_folder

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

    # run setup if not yet done
    if pending_link_cli(config_name) or pending_dropbox_folder(config_name):

        from maestral.main import Maestral

        m = Maestral(config_name, run=False)
        m.reset_sync_state()
        m.create_dropbox_directory()

        exclude_folders_q = click.confirm(
            'Would you like to exclude any folders from syncing?',
            default=False,
        )

        if exclude_folders_q:
            click.echo(
                'Please choose which top-level folders to exclude. You can exclude\n'
                'individual files or subfolders later with "maestral excluded add".'
            )
            m.set_excluded_items()

        del m

    # start daemon
    if foreground:
        from maestral.daemon import run_maestral_daemon
        run_maestral_daemon(config_name, run=True, log_to_stdout=verbose)
    else:
        start_daemon_subprocess_with_cli_feedback(config_name,
                                                  log_to_stdout=verbose)
Example #4
0
def configs():
    """Lists all configured Dropbox accounts."""
    from maestral.daemon import get_maestral_pid
    from maestral.utils.backend import remove_configuration

    # clean up stale configs
    config_names = list_configs()

    for name in config_names:
        dbid = MaestralConfig(name).get('account', 'account_id')
        if dbid == '' and not get_maestral_pid(name):
            remove_configuration(name)

    # display remaining configs
    names = list_configs()
    emails = [MaestralState(c).get('account', 'email') for c in names]

    click.echo('')
    click.echo(
        format_table(columns=[names, emails],
                     headers=['Config name', 'Account']))
    click.echo('')
Example #5
0
    def _get_or_start_maestral_daemon(self):

        pid = get_maestral_pid(self.config_name)
        if pid:
            self._started = False
        else:
            if IS_MACOS_BUNDLE:
                res = start_maestral_daemon_thread(self.config_name)
            else:
                res = start_maestral_daemon_process(self.config_name)
            if res == Start.Failed:
                title = 'Could not start Maestral'
                message = ('Could not start or connect to sync daemon. Please try again '
                           'and contact the developer if this issue persists.')
                show_dialog(title, message, level='error')
                self.quit()
            elif res == Start.AlreadyRunning:
                self._started = False
            elif res == Start.Ok:
                self._started = True

        return get_maestral_proxy(self.config_name)
Example #6
0
    def quit(self, *args, stop_daemon=None):
        """Quits Maestral.

        :param bool stop_daemon: If ``True``, the sync daemon will be stopped when
            quitting the GUI, if ``False``, it will be kept alive. If ``None``, the daemon
            will only be stopped if it was started by the GUI (default).
        """
        logger.info('Quitting...')

        # stop update timer to stop communication with daemon
        self.update_ui_timer.stop()

        threaded = os.getpid() == get_maestral_pid(self.config_name)

        # stop sync daemon if we started it or ``stop_daemon`` is ``True``
        # never stop the daemon if it runs in a thread of the current process
        if threaded:
            stop_maestral_daemon_thread(self.config_name)
        elif stop_daemon or self._started:
            stop_maestral_daemon_process(self.config_name)

        # quit
        QtCore.QCoreApplication.quit()
        sys.exit(0)