Exemplo n.º 1
0
def init(ctx):
    try:
        load_config()
        click.confirm(
            "Config already found. Do you wish to reset it? "
            "Otherwise run `archivy config`",
            abort=True,
        )
    except FileNotFoundError:
        pass

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

    click.echo("This is the archivy installation initialization wizard.")
    data_dir = click.prompt(
        "Enter the full path of the "
        "directory where you'd like us to store data.",
        type=str,
        default=str(Path(".").resolve()),
    )

    es_enabled = click.confirm(
        "Would you like to enable Elasticsearch? For this to work "
        "when you run archivy, you must have ES installed."
        "See https://archivy.github.io/setup-search/ for more info.")
    if es_enabled:
        config.SEARCH_CONF["enabled"] = 1
    else:
        delattr(config, "SEARCH_CONF")

    create_new_user = click.confirm(
        "Would you like to create a new admin user?")
    if create_new_user:
        username = click.prompt("Username")
        password = click.prompt("Password",
                                hide_input=True,
                                confirmation_prompt=True)
        if not ctx.invoke(create_admin, username=username, password=password):
            return

    config.HOST = click.prompt(
        "Host [localhost (127.0.0.1)]",
        type=str,
        default="127.0.0.1",
        show_default=False,
    )

    config.override({"USER_DIR": data_dir})
    app.config["USER_DIR"] = data_dir

    # create data dir
    (Path(data_dir) / "data").mkdir(exist_ok=True, parents=True)

    write_config(vars(config))
    click.echo("Config successfully created at " +
               str((Path(app.config["INTERNAL_DIR"]) /
                    "config.yml").resolve()))
Exemplo n.º 2
0
from flask import Flask
from flask_compress import Compress
from flask_login import LoginManager

from archivy import helpers
from archivy.api import api_bp
from archivy.models import User
from archivy.config import Config
from archivy.helpers import load_config

app = Flask(__name__)
app.logger.setLevel(logging.INFO)
config = Config()
try:
    # if it exists, load user config
    config.override(load_config(config.INTERNAL_DIR))
except FileNotFoundError:
    pass

app.config.from_object(config)

(Path(app.config["USER_DIR"]) / "data").mkdir(parents=True, exist_ok=True)

if app.config["SEARCH_CONF"]["enabled"]:
    with app.app_context():
        es = helpers.get_elastic_client()
        try:
            es.indices.create(index=app.config["SEARCH_CONF"]["index_name"],
                              body=app.config["SEARCH_CONF"]["search_conf"])
        except elasticsearch.exceptions.RequestError:
            app.logger.info("Elasticsearch index already created")
Exemplo n.º 3
0
def init(ctx):
    try:
        load_config()
        click.confirm(
            "Config already found. Do you wish to reset it? "
            "Otherwise run `archivy config`",
            abort=True,
        )
    except FileNotFoundError:
        pass

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

    click.echo("This is the archivy installation initialization wizard.")
    data_dir = click.prompt(
        "Enter the full path of the "
        "directory where you'd like us to store data.",
        type=str,
        default=str(Path(".").resolve()),
    )

    desires_search = click.confirm(
        "Would you like to enable search on your knowledge base contents?")

    if desires_search:
        search_engine = click.prompt(
            "Then go to https://archivy.github.io/setup-search/ to see the different backends you can use for search and how you can configure them.",
            type=click.Choice(["elasticsearch", "ripgrep", "cancel"]),
            show_choices=True,
        )
        if search_engine != "cancel":
            config.SEARCH_CONF["enabled"] = 1
            config.SEARCH_CONF["engine"] = search_engine
        else:
            delattr(config, "SEARCH_CONF")

    create_new_user = click.confirm(
        "Would you like to create a new admin user?")
    if create_new_user:
        username = click.prompt("Username")
        password = click.prompt("Password",
                                hide_input=True,
                                confirmation_prompt=True)
        if not ctx.invoke(create_admin, username=username, password=password):
            return

    config.HOST = click.prompt(
        "Host [localhost (127.0.0.1)]",
        type=str,
        default="127.0.0.1",
        show_default=False,
    )

    config.override({"USER_DIR": data_dir})
    app.config["USER_DIR"] = data_dir

    # create data dir
    (Path(data_dir) / "data").mkdir(exist_ok=True, parents=True)

    write_config(vars(config))
    click.echo("Config successfully created at " +
               str((Path(app.config["INTERNAL_DIR"]) /
                    "config.yml").resolve()))