Skip to content

Commit

Permalink
Fix deprecated code SGCSRelease#112
Browse files Browse the repository at this point in the history
After flask version 0.11, it no more uses manage.py. For this reason
every commands inside of manage.py moves to app.py And thus, commands
are a bit changed.

For example, "./manage.py config" changes to "flask config".

Flask-Script extension, which is command line tool, is deprecated.
Instead of it, there is a better python package named "click". So, I
replaced flask_script to click.
  • Loading branch information
JimJeon committed Apr 8, 2018
1 parent 46e2011 commit 5926e19
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 92 deletions.
92 changes: 89 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,93 @@
#!env python

from AwesomeTitleServer import app
from os import urandom, makedirs
from os.path import abspath, dirname, exists, join

import click
from flask_migrate import Migrate
from jinja2 import Template

if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
from AwesomeTitleServer import app, db


_default = 'awesometitle'
_server = 'localhost'
_folder = 'datas/DOWNLOADED/'

migrate = Migrate(app, db)


@app.cli.command()
@click.option('--mysql', default=None,
help='Whether use mysql')
@click.option('--username', default=_default,
help='Mysql username')
@click.option('--password', default=None,
prompt=True, confirmation_prompt=True, hide_input=True,
help='Mysql password')
@click.option('--server', default=_server,
help='Mysql server')
@click.option('--database', default=_default,
help='Mysql database')
@click.option('--folder', default=_folder,
help='Image upload folder')
def config(
mysql,
username,
password,
server,
database,
folder,
):
"""Generate config.py for AwesomeTitle.
If there were some given parameters, those questions will be handled
automatically.
"""
# TODO : Is Existed config.py?

base = dirname(abspath(__file__))

# XXX : Check '-m' or '--mysql' options entered.
if mysql is None:
use_mysql = click.confirm("Use MySQL?", default=True)
else:
if mysql == "True":
use_mysql = True
elif mysql == "False":
use_mysql = False
else:
raise Exception("`-m` or `--mysql` needed `True` or `False`.")
if use_mysql is True:
# XXX : Check '-u' or '--username' options entered.
if username is _default:
username = click.prompt("MySQL DB Username", default=username)
# XXX : Check '-p' or '--password' options entered.
if not password:
password = click.prompt("MySQL DB Password", hide_input=True)
# XXX : Check '-s' or '--server' options entered.
if server is _server:
server = click.prompt("MySQL DB Server", default=server)
# XXX : Check '-d' or '--database' options entered.
if database is _default:
database = click.prompt("MySQL DB Database", default=database)
# XXX : Check '-f' or '--folder' options entered.
if folder is _folder:
folder = click.prompt("Image Upload Folder", default=folder)
folder = join(base, folder)
if not exists(folder):
makedirs(folder)
secret_key = urandom(24)
with open("confs/config.py.tmpl") as tmpl:
Template(
tmpl.read()
).stream(
base=base,
username=username,
password=password,
server=server,
database=database,
folder=folder,
secret_key=secret_key,
use_mysql=use_mysql,
).dump("AwesomeTitleServer/config.py")
89 changes: 0 additions & 89 deletions manage.py

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
click
flask
flask-admin
flask-migrate
Expand Down

0 comments on commit 5926e19

Please sign in to comment.