Allow requiring login only for accounts that miss files
This commit is contained in:
parent
8787129be6
commit
5108ca59f4
4 changed files with 52 additions and 14 deletions
29
README.md
29
README.md
|
@ -3,16 +3,29 @@
|
||||||
|
|
||||||
Cleantoots helps you delete your old toots. Because not everything we say on social medias should stay there for eternity.
|
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
|
Only once
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m pip install cleantoots
|
python -m pip install cleantoots
|
||||||
cleantoots setup-config # See the following section for config options
|
cleantoots config setup # See the following section for config file options
|
||||||
cleantoots login
|
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
|
## Config options
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
|
@ -68,6 +81,14 @@ cleantoots clean # Defaults to a dry run. Does NOT delete.
|
||||||
cleantoots clean --delete # Delete without prompt.
|
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
|
## Tested environments
|
||||||
Cleantoots test suite runs on Python 3.6, 3.7 and 3.8
|
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.
|
on latest versions of macOS, Windows and Ubuntu as GitHub Actions understands it.
|
||||||
|
|
|
@ -77,19 +77,33 @@ def edit(config):
|
||||||
|
|
||||||
|
|
||||||
@config_command.command()
|
@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
|
@click.pass_obj
|
||||||
def login(config):
|
def login(config, only_missing):
|
||||||
"""Fetch credentials for each app described in config file."""
|
"""Fetch credentials for each app described in config file."""
|
||||||
if not _config_has_sections(config):
|
if not _config_has_sections(config):
|
||||||
return
|
return
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
section = config[section]
|
section = config[section]
|
||||||
Mastodon.create_app(
|
app_file_exists = config.isfile(section.get("app_secret_file"))
|
||||||
"cleantoots",
|
user_file_exists = config.isfile(section.get("user_secret_file"))
|
||||||
api_base_url=section.get("api_base_url"),
|
|
||||||
to_file=config.file(section.get("app_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")))
|
mastodon = Mastodon(client_id=config.file(section.get("app_secret_file")))
|
||||||
_open_url(mastodon.auth_request_url())
|
if not (only_missing and user_file_exists and app_file_exists):
|
||||||
code = click.prompt("Enter code for {}".format(section.get("api_base_url")))
|
_open_url(mastodon.auth_request_url())
|
||||||
mastodon.log_in(code=code, to_file=config.file(section.get("user_secret_file")))
|
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"))
|
||||||
|
)
|
||||||
|
|
|
@ -25,6 +25,9 @@ class CleanTootsConfig(configparser.ConfigParser):
|
||||||
def file(self, filename):
|
def file(self, filename):
|
||||||
return os.path.join(self.dir, 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.group(context_settings=CONTEXT_SETTINGS)
|
||||||
@click.option(
|
@click.option(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "cleantoots"
|
name = "cleantoots"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
description = "Cleanup your toot history."
|
description = "Cleanup your toot history."
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
authors = ["Gabriel Augendre <gabriel@augendre.info>"]
|
authors = ["Gabriel Augendre <gabriel@augendre.info>"]
|
||||||
|
|
Loading…
Reference in a new issue