Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'archivy init' does not purge old configuration before interactive init #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion archivy/cli.py
Expand Up @@ -7,7 +7,7 @@
from flask.cli import FlaskGroup, load_dotenv, shell_command

from archivy import app
from archivy.config import Config
from archivy.config import Config, VERSION
from archivy.click_web import create_click_web_app
from archivy.data import open_file, format_file, unformat_file
from archivy.helpers import load_config, write_config
Expand Down Expand Up @@ -38,6 +38,18 @@ def init(ctx):
except FileNotFoundError:
pass

# ask if to remove old users
try:
users_db = (Path(app.config['INTERNAL_DIR']) / 'db.json').resolve(strict=True)
remove_old_users = click.confirm("Found an existing user database. Do you want "
"to remove them?")
if remove_old_users:
users_db.unlink()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also remove other db objects. Maybe we can just inform them there are other created users and provide a delete-user command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other information can the db contain?

except FileNotFoundError:
pass
# remove the old configuration, and add version to it
write_config({"version": VERSION})

config = Config()
delattr(config, "SECRET_KEY")

Expand Down
5 changes: 5 additions & 0 deletions archivy/config.py
@@ -1,10 +1,15 @@
import os
import appdirs

# version of archivy configuration file
VERSION = 1


class Config(object):
"""Configuration object for the application"""

VERSION = VERSION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can directly define it as VERSION = 1 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed.


def __init__(self):
self.SECRET_KEY = os.urandom(32)
self.PORT = 5000
Expand Down