Last active
August 29, 2015 14:01
-
-
Save shonenada/f0cc9189e653a2edba01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
sh_version = '1.0' | |
author="shonenada" | |
email="[email protected]" | |
pkg_version="0.1" | |
function write_setup { | |
echo "write $1" | |
echo "from setuptools import setup, find_packages" > $1 | |
echo "" >> $1 | |
echo "" >> $1 | |
echo "install_required = [l.strip() for l in open('requestments.txt', 'r')]" >> $1 | |
echo "" >> $1 | |
echo "" >> $1 | |
echo "metadata = {" >> $1 | |
echo " 'name': '$2'," >> $1 | |
echo " 'version': '$3'," >> $1 | |
echo " 'packages': find_packages()," >> $1 | |
echo " 'author': '$4'," >> $1 | |
echo " 'author_email': '$5'," >> $1 | |
echo " 'install_requires': install_required," >> $1 | |
echo "}" >> $1 | |
} | |
function write_app { | |
echo "write $1" | |
echo "import os" > $1 | |
echo "" >> $1 | |
echo "from flask import Flask" >> $1 | |
echo "from flask._compat import string_types" >> $1 | |
echo "" >> $1 | |
echo "" >> $1 | |
echo "def create_app(import_name=None, config=None):" >> $1 | |
echo " app = Flask(import_name or __name__)" >> $1 | |
echo "" >> $1 | |
echo " app.config.from_object('$project_name.settings')" >> $1 | |
echo "" >> $1 | |
echo " if isinstance(config, dict):" >> $1 | |
echo " app.config.update(config)" >> $1 | |
echo " elif isinstance(config, string_types):" >> $1 | |
echo " app.config.from_pyfile(os.path.abspath(config))" >> $1 | |
echo "" >> $1 | |
echo " return app" >> $1 | |
} | |
function write_manage { | |
sf="$1/manage.py" | |
echo "write $sf" | |
echo "import os" > $sf | |
echo "" >> $sf | |
echo "from flask.ext.script import Manager, Server" >> $sf | |
echo "" >> $sf | |
echo "from $2.app import create_app" >> $sf | |
echo "" >> $sf | |
echo "" >> $sf | |
echo "app_root = os.path.dirname(os.path.abspath(__name__))" >> $sf | |
echo "" >> $sf | |
echo "application = create_app('$2', os.path.join(app_root, 'development.conf'))" >> $sf | |
echo "server = Server()" >> $sf | |
echo "manager = Manager(application)" >> $sf | |
echo "manager.add_command('runserver', server)" >> $sf | |
echo "" >> $sf | |
echo "" >> $sf | |
echo "@manager.option('-p', dest='port', help='port of host', default=5000)" >> $sf | |
echo "def run(port):" >> $sf | |
echo " \"\"\"Run app at 0.0.0.0\"\"\"" >> $sf | |
echo " application.run(host='0.0.0.0', port=port, debug=True)" >> $sf | |
echo "" >> $sf | |
echo "" >> $sf | |
echo "if __name__ == '__main__':" >> $sf | |
echo " manager.run()" >> $sf | |
} | |
python_version=`python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))'` | |
read -p "Make Sure Your Python version is $python_version? [Y/n]" sure | |
if [ "$sure" == "n" ] || [ "$sure" == "N" ] | |
then | |
exit 1 | |
fi | |
read -p "Your project's root path? [.] " work_dir | |
if [ $work_dir == '' ] | |
then | |
work_dir='.' | |
fi | |
if [ ! -d "$work_dir" ] | |
then | |
mkdir -p "$work_dir" | |
fi | |
read -p "Name of project: [$work_dir] " project_name | |
if [ $project_name == '' ] | |
then | |
project_name="$work_dir" | |
fi | |
read -p "Do you want to initialize virtual env.[Y/n] " init_venv | |
read -p "Flask-Script? [Y/n] " flask_script | |
read -p "SQLAlchemy? [y/N] " sqlalchemy | |
read -p "Flask-SQLAlchmey? [y/N] " flask_sqlalchemy | |
read -p "Flask-WTF? [y/N] " flask_wtf | |
read -p "Flask-Login? [y/N] " flask_login | |
read -p "Flask-RBAC? [y/N] " flask_rbac | |
read -p "Flask-Babel? [y/N] " flask_babel | |
# Initialize environments | |
if [ "$init_venv" == "Y" ] || [ "$init_venv" == "y" ] || [ "$init_venv" == "" ] | |
then | |
virtualenv "$work_dir/venv" | |
source "$work_dir/venv/bin/activate" | |
fi | |
echo "Installing flask" | |
pip install flask | |
echo "create folders" | |
mkdir -p "$work_dir/$project_name" | |
mkdir -p "$work_dir/tests" | |
echo "touch files" | |
touch "$work_dir/setup.py" | |
touch "$work_dir/development.conf" | |
touch "$work_dir/$project_name/__init__.py" | |
touch "$work_dir/$project_name/app.py" | |
touch "$work_dir/$project_name/settings.py" | |
write_setup "$work_dir/setup.py" "$project_name" "$pkg_version" "$author" "$author_email" | |
write_app "$work_dir/$project_name/app.py" | |
if [ "$flask_script" == "Y" ] || [ "$flask_script" == 'y' ] || [ "$flask_script" == "" ] | |
then | |
echo "Installing Flask-Script" | |
pip install Flask-Script | |
write_manage "$work_dir" "$project_name" | |
fi | |
if [ "$sqlalchemy" == "Y" ] || [ "$sqlalchemy" == 'y' ] | |
then | |
echo "Installing SQLAlchemy" | |
pip install SQLAlchemy | |
fi | |
if [ "$flask_sqlalchemy" == "Y" ] || [ "$flask_sqlalchemy" == 'y' ] | |
then | |
echo "Installing Flask-SQLAlchemy" | |
pip install Flask-SQLAlchemy | |
fi | |
if [ "$flask_wtf" == "Y" ] || [ "$flask_wtf" == 'y' ] | |
then | |
echo "Installing Flask-WTF" | |
pip install Flask-WTF | |
fi | |
if [ "$flask_login" == "Y" ] || [ "$flask_login" == 'y' ] | |
then | |
echo "Installing Flask-Login" | |
pip install Flask-Login | |
fi | |
if [ "$flask_rbac" == "Y" ] || [ "$flask_rbac" == 'y' ] | |
then | |
echo "Installing Flask-RBAC" | |
pip install Flask-RBAC | |
fi | |
if [ "$flask_babel" == "Y" ] || [ "$flask_babel" == 'y' ] | |
then | |
echo "Installing Flask-Babel" | |
pip install Flask-Babel | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment