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)
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)
def start(foreground: bool, verbose: bool, config_name: str) -> None: # ---- run setup if necessary ------------------------------------------------------ # We run the setup in the current process. This avoids starting a subprocess despite # running with the --foreground flag, prevents leaving a zombie process if the setup # fails with an exception and does not confuse systemd. from maestral.main import Maestral m = Maestral(config_name, log_to_stdout=verbose) if m.pending_link: # this may raise KeyringAccessError link_dialog(m) if m.pending_dropbox_folder: path = select_dbx_path_dialog(config_name, allow_merge=True) while True: try: m.create_dropbox_directory(path) break except OSError: click.echo( "Could not create folder. Please make sure that you have " "permissions to write to the selected location or choose a " "different location." ) exclude_folders_q = click.confirm( "Would you like to exclude any folders from syncing?", ) 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".\n' ) click.echo("Loading...", nl=False) # get all top-level Dropbox folders entries = m.list_folder("/", recursive=False) excluded_items: List[str] = [] click.echo("\rLoading... Done") # paginate through top-level folders, ask to exclude for e in entries: if e["type"] == "FolderMetadata": yes = click.confirm( 'Exclude "{path_display}" from sync?'.format(**e) ) if yes: path_lower = cast(str, e["path_lower"]) excluded_items.append(path_lower) m.set_excluded_items(excluded_items) # free resources del m if foreground: # stop daemon process after setup and restart in our current process stop_maestral_daemon_process(config_name) start_maestral_daemon(config_name, log_to_stdout=verbose, start_sync=True) else: # start daemon process click.echo("Starting Maestral...", nl=False) res = start_maestral_daemon_process( config_name, log_to_stdout=verbose, start_sync=True ) if res == Start.Ok: click.echo("\rStarting Maestral... " + OK) elif res == Start.AlreadyRunning: click.echo("\rStarting Maestral... Already running.") else: click.echo("\rStarting Maestral... " + FAILED) click.echo("Please check logs for more information.")