From b7b379f1d3d931ee8a50e77c1e742dfd5e87a186 Mon Sep 17 00:00:00 2001 From: Sam Schott Date: Sat, 13 Feb 2021 10:36:37 +0000 Subject: [PATCH] [cli] added config-file --clean option --- CHANGELOG.md | 9 ++++--- src/maestral/cli.py | 63 +++++++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc7699f..4ee4491c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,9 +25,10 @@ the equivalent command from the Settings group (e.g., `maestral move-dir`). * Added the ability to turn off one sync direction, for instance to enable download syncs only. This can be useful when you want to mirror a remote folder while ignoring - local changes. Note that conflict resolution remain unaffected. For instance, when - an unsynced local change would be overwritten by a remote change, the local file will - be moved to a "conflicting copy" first. + local changes. To use this, set the respective config values for `upload` or + `download` to False. Note that conflict resolution remain unaffected. For instance, + when an unsynced local change would be overwritten by a remote change, the local file + will be moved to a "conflicting copy" first. #### Changed: @@ -50,6 +51,8 @@ * Renamed command `file-status` to `filestatus`. * Added a `--yes, -Y` flag to the `unlink` to command to skip the confirmation prompt. * Renamed the `configs` command to list config files to `config-files`. + * Added an option `--clean` to `config-files` to remove all stale config files without + a linked Dropbox account. * Improved error message when the user is running out of inotify watches: Recommend default values of `max_user_watches = 524,288` and `max_user_instances = 1024` or double the current values, whichever is higher. Advise to apply the changes with diff --git a/src/maestral/cli.py b/src/maestral/cli.py index 5a41fb38..98b7b075 100755 --- a/src/maestral/cli.py +++ b/src/maestral/cli.py @@ -1177,7 +1177,13 @@ def ls(long: bool, dropbox_path: str, include_deleted: bool, config_name: str) - @main.command(section="Information", help="List all configured Dropbox accounts.") -def config_files() -> None: +@click.option( + "--clean", + is_flag=True, + default=False, + help="Remove config files without a linked account.", +) +def config_files(clean: bool) -> None: from .daemon import is_running from .config import ( @@ -1187,36 +1193,43 @@ def config_files() -> None: remove_configuration, ) - # clean up stale configs + if clean: - for name in list_configs(): - dbid = MaestralConfig(name).get("account", "account_id") - if dbid == "" and not is_running(name): - remove_configuration(name) + # Clean up stale config files. - # display remaining configs - names = list_configs() - emails = [] - paths = [] + for name in list_configs(): + conf = MaestralConfig(name) + path = conf.get_config_fpath() + dbid = conf.get("account", "account_id") - for name in names: - config = MaestralConfig(name) - state = MaestralState(name) + if dbid == "" and not is_running(name): + remove_configuration(name) + cli.echo(f"Removed: {path}") - emails.append(state.get("account", "email")) - paths.append(config.get_config_fpath()) + else: + # Display config files. + names = list_configs() + emails = [] + paths = [] - table = cli.Table( - [ - cli.Column("Config name", names), - cli.Column("Account", emails), - cli.Column("Path", paths, elide=cli.Elide.Leading), - ] - ) + for name in names: + config = MaestralConfig(name) + state = MaestralState(name) - cli.echo("") - table.echo() - cli.echo("") + emails.append(state.get("account", "email")) + paths.append(config.get_config_fpath()) + + table = cli.Table( + [ + cli.Column("Config name", names), + cli.Column("Account", emails), + cli.Column("Path", paths, elide=cli.Elide.Leading), + ] + ) + + cli.echo("") + table.echo() + cli.echo("") # ======================================================================================