Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #87 from minhoryang/issue_84_config_extraction
Browse files Browse the repository at this point in the history
Issue #84, [ACTION REQUIRED] python manage.py config
  • Loading branch information
minhoryang committed Mar 6, 2016
2 parents f1351e9 + 54c7591 commit 2561a77
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.python-version
DOWNLOADED/
config.py



Expand Down
9 changes: 7 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
redirect,
)

import config
from db import (
admin,
db,
Expand All @@ -22,7 +21,13 @@

app = Flask(__name__)

app.config.from_object(config)
try:
import config
app.config.from_object(config)
except ImportError as e:
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
if __name__ == "__main__":
raise Exception("Please run `python manage.py config` first.")

admin.init_app(app)
bcrypt.init_app(app)
Expand Down
5 changes: 0 additions & 5 deletions config.py

This file was deleted.

6 changes: 6 additions & 0 deletions config.py.tmpl
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 }}'
53 changes: 49 additions & 4 deletions manage.py
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()

0 comments on commit 2561a77

Please sign in to comment.