This repository was archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from minhoryang/issue_84_config_extraction
Issue #84, [ACTION REQUIRED] python manage.py config
- Loading branch information
Showing
5 changed files
with
63 additions
and
11 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,5 +1,6 @@ | ||
.python-version | ||
DOWNLOADED/ | ||
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from os import urandom | ||
|
||
SQLALCHEMY_TRACK_MODIFICATIONS = True | ||
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{{ username }}:{{ password }}@{{ server }}/{{ database }}?charset=utf8mb4' | ||
SECRET_KEY = urandom(24) | ||
UPLOAD_FOLDER = '{{ folder }}' |
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,11 +1,56 @@ | ||
# manage.py | ||
from flask_script import ( | ||
Manager, | ||
prompt, | ||
prompt_pass, | ||
) | ||
from flask_migrate import MigrateCommand | ||
from jinja2 import Template | ||
|
||
from app import app # app.py파일의 app변수를 가져온다. | ||
|
||
from flask_script import Manager | ||
from flask_migrate import MigrateCommand | ||
|
||
manager = Manager(app) | ||
manager.add_command('db', MigrateCommand) | ||
_default = 'awesometitle' | ||
_server = 'localhost' | ||
_folder = './DOWNLOADED/' | ||
|
||
|
||
@manager.command | ||
def config( | ||
username=_default, | ||
password=None, | ||
server=_server, | ||
database=_default, | ||
folder=_folder, | ||
): | ||
"""Generate config.py for AwesomeTitle. | ||
If there were some given parameters, those questions will be handled | ||
automatically. | ||
""" | ||
# TODO : Is Existed config.py? | ||
if username is _default: | ||
username = prompt("MySQL DB Username", default=username) | ||
if not password: | ||
password = prompt_pass("MySQL DB Password") | ||
if server is _server: | ||
server = prompt("MySQL DB Server", default=server) | ||
if database is _default: | ||
database = prompt("MySQL DB Database", default=database) | ||
if folder is _folder: | ||
folder = prompt("Image Upload Folder", default=folder) | ||
with open("config.py.tmpl") as tmpl: | ||
Template( | ||
tmpl.read() | ||
).stream( | ||
username=username, | ||
password=password, | ||
server=server, | ||
database=database, | ||
folder=folder, | ||
).dump("config.py") | ||
|
||
|
||
if __name__ == '__main__': | ||
manager.run() | ||
manager.run() |