Allow requiring login only for accounts that miss files

This commit is contained in:
Gabriel Augendre 2019-12-28 14:56:14 +01:00
parent 8787129be6
commit 5108ca59f4
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
4 changed files with 52 additions and 14 deletions

View file

@ -3,16 +3,29 @@
Cleantoots helps you delete your old toots. Because not everything we say on social medias should stay there for eternity.
## Initial config
## Config
### Initial setup
Only once
```bash
python -m pip install cleantoots
cleantoots setup-config # See the following section for config options
cleantoots login
cleantoots config setup # See the following section for config file options
cleantoots config login
```
### View and edit
You can later view the parsed config file with
```bash
cleantoots config list
```
You can edit the config file using
```bash
cleantoots config edit
```
This will open the config file using your preferred editor (`EDITOR` env variable).
## Config options
```ini
@ -68,6 +81,14 @@ cleantoots clean # Defaults to a dry run. Does NOT delete.
cleantoots clean --delete # Delete without prompt.
```
## Add an account
```bash
cleantoots config edit # Opens editor so you can add your config
cleantoots config list # Check your newly added account
cleantoots config login --only-missing # Store credentials for your newly created account
cleantoots clean --delete
```
## Tested environments
Cleantoots test suite runs on Python 3.6, 3.7 and 3.8
on latest versions of macOS, Windows and Ubuntu as GitHub Actions understands it.

View file

@ -77,19 +77,33 @@ def edit(config):
@config_command.command()
@click.option(
"-m",
"--only-missing",
help="Prompt for login only on accounts that miss a credentials file.",
is_flag=True,
)
@click.pass_obj
def login(config):
def login(config, only_missing):
"""Fetch credentials for each app described in config file."""
if not _config_has_sections(config):
return
for section in config.sections():
section = config[section]
Mastodon.create_app(
"cleantoots",
api_base_url=section.get("api_base_url"),
to_file=config.file(section.get("app_secret_file")),
)
app_file_exists = config.isfile(section.get("app_secret_file"))
user_file_exists = config.isfile(section.get("user_secret_file"))
if not (only_missing and app_file_exists):
Mastodon.create_app(
"cleantoots",
api_base_url=section.get("api_base_url"),
to_file=config.file(section.get("app_secret_file")),
)
mastodon = Mastodon(client_id=config.file(section.get("app_secret_file")))
_open_url(mastodon.auth_request_url())
code = click.prompt("Enter code for {}".format(section.get("api_base_url")))
mastodon.log_in(code=code, to_file=config.file(section.get("user_secret_file")))
if not (only_missing and user_file_exists and app_file_exists):
_open_url(mastodon.auth_request_url())
code = click.prompt("Enter code for {}".format(section.get("api_base_url")))
mastodon.log_in(
code=code, to_file=config.file(section.get("user_secret_file"))
)

View file

@ -25,6 +25,9 @@ class CleanTootsConfig(configparser.ConfigParser):
def file(self, filename):
return os.path.join(self.dir, filename)
def isfile(self, filename):
return os.path.isfile(self.file(filename))
@click.group(context_settings=CONTEXT_SETTINGS)
@click.option(

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "cleantoots"
version = "0.3.1"
version = "0.3.2"
description = "Cleanup your toot history."
license = "GPL-3.0-or-later"
authors = ["Gabriel Augendre <gabriel@augendre.info>"]