[cli] added config-file --clean option

This commit is contained in:
Sam Schott 2021-02-13 10:36:37 +00:00
parent 5e8642f615
commit b7b379f1d3
2 changed files with 44 additions and 28 deletions

View File

@ -25,9 +25,10 @@
the equivalent command from the Settings group (e.g., `maestral move-dir`). 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 * 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 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 local changes. To use this, set the respective config values for `upload` or
an unsynced local change would be overwritten by a remote change, the local file will `download` to False. Note that conflict resolution remain unaffected. For instance,
be moved to a "conflicting copy" first. when an unsynced local change would be overwritten by a remote change, the local file
will be moved to a "conflicting copy" first.
#### Changed: #### Changed:
@ -50,6 +51,8 @@
* Renamed command `file-status` to `filestatus`. * Renamed command `file-status` to `filestatus`.
* Added a `--yes, -Y` flag to the `unlink` to command to skip the confirmation prompt. * 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`. * 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 * 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 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 double the current values, whichever is higher. Advise to apply the changes with

View File

@ -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.") @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 .daemon import is_running
from .config import ( from .config import (
@ -1187,36 +1193,43 @@ def config_files() -> None:
remove_configuration, remove_configuration,
) )
# clean up stale configs if clean:
for name in list_configs(): # Clean up stale config files.
dbid = MaestralConfig(name).get("account", "account_id")
if dbid == "" and not is_running(name):
remove_configuration(name)
# display remaining configs for name in list_configs():
names = list_configs() conf = MaestralConfig(name)
emails = [] path = conf.get_config_fpath()
paths = [] dbid = conf.get("account", "account_id")
for name in names: if dbid == "" and not is_running(name):
config = MaestralConfig(name) remove_configuration(name)
state = MaestralState(name) cli.echo(f"Removed: {path}")
emails.append(state.get("account", "email")) else:
paths.append(config.get_config_fpath()) # Display config files.
names = list_configs()
emails = []
paths = []
table = cli.Table( for name in names:
[ config = MaestralConfig(name)
cli.Column("Config name", names), state = MaestralState(name)
cli.Column("Account", emails),
cli.Column("Path", paths, elide=cli.Elide.Leading),
]
)
cli.echo("") emails.append(state.get("account", "email"))
table.echo() paths.append(config.get_config_fpath())
cli.echo("")
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("")
# ====================================================================================== # ======================================================================================