[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`).
* 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

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.")
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,14 +1193,21 @@ def config_files() -> None:
remove_configuration,
)
# clean up stale configs
if clean:
# Clean up stale config files.
for name in list_configs():
dbid = MaestralConfig(name).get("account", "account_id")
conf = MaestralConfig(name)
path = conf.get_config_fpath()
dbid = conf.get("account", "account_id")
if dbid == "" and not is_running(name):
remove_configuration(name)
cli.echo(f"Removed: {path}")
# display remaining configs
else:
# Display config files.
names = list_configs()
emails = []
paths = []