forked from SGCSRelease/legacy-awesome-title
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
90 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
click | ||
flask | ||
flask-admin | ||
flask-migrate | ||
|