Initial commit
This commit is contained in:
commit
c0b4ca1021
21 changed files with 677 additions and 0 deletions
49
app/commands.py
Normal file
49
app/commands.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import click
|
||||
from app import db
|
||||
from flask import current_app
|
||||
from app.models import Setting, User
|
||||
|
||||
|
||||
def seed_defaults():
|
||||
defaults = {
|
||||
"butterbox_name": current_app.config["BUTTERBOX_NAME"],
|
||||
"butterbox_logo": current_app.config["BUTTERBOX_LOGO"],
|
||||
"ssid": current_app.config["BUTTERBOX_SSID"],
|
||||
"wifi_password": current_app.config["BUTTERBOX_WIFI_PASSWORD"],
|
||||
"disable_access_point": current_app.config["DISABLE_ACCESS_POINT"],
|
||||
"apply_changes": "false",
|
||||
"onboarding_complete": "false",
|
||||
"lock_root_password": "false",
|
||||
"disable_file_viewer": current_app.config["DISABLE_FILE_VIEWER"],
|
||||
"disable_map_viewer": current_app.config["DISABLE_MAP_VIEWER"],
|
||||
"disable_chat": current_app.config["DISABLE_CHAT"],
|
||||
"disable_app_store": current_app.config["DISABLE_APP_STORE"],
|
||||
"ssh_password": "",
|
||||
"admin_password": current_app.config["ADMIN_PASSWORD"],
|
||||
}
|
||||
|
||||
for key, value in defaults.items():
|
||||
exists = Setting.query.filter_by(key=key).first()
|
||||
if not exists:
|
||||
db.session.add(Setting(key=key, value=value))
|
||||
click.echo("Created new setting {}".format(key))
|
||||
else:
|
||||
click.echo("Found existing setting {}".format(key))
|
||||
db.session.commit()
|
||||
|
||||
admin_user_exists = User.query.filter_by(username='admin').first()
|
||||
if not admin_user_exists:
|
||||
u = User(username='admin')
|
||||
u.set_password('admin')
|
||||
db.session.add(u)
|
||||
db.session.commit()
|
||||
click.echo("Created new admin user")
|
||||
else:
|
||||
click.echo("Found existing admin user")
|
||||
|
||||
|
||||
@click.command("seed-settings")
|
||||
def seed_settings_command():
|
||||
"""Seed default settings into the database (only if missing)."""
|
||||
seed_defaults()
|
||||
click.echo("Finished seeding default settings.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue