├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── README.rst ├── bin └── flask-go.py ├── flask_go ├── __init__.py ├── app_template │ ├── __init__.py │ └── views.py ├── commands │ ├── __init__.py │ ├── base.py │ ├── startapp.py │ └── startproject.py ├── management.py └── project_template │ ├── manage.py │ ├── project_name │ ├── __init__.py │ ├── apps │ │ └── __init__.py │ ├── configs │ │ ├── __init__.py │ │ └── base.py │ ├── project_name.py │ └── settings.py │ └── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # If you need to exclude files such as those generated by an IDE, use 2 | # $GIT_DIR/info/exclude or the core.excludesFile configuration variable as 3 | # described in https://git-scm.com/docs/gitignore 4 | 5 | *.egg-info 6 | *.pot 7 | *.py[co] 8 | __pycache__ 9 | MANIFEST 10 | dist/ 11 | build/ 12 | test/ 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 by Cello Hsueh. 2 | 3 | Some rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | 17 | * The names of the contributors may not be used to endorse or 18 | promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include flask_go * 4 | recursive-exclude flask_go *.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flask-go 2 | Let you create flask project like use django-admin 3 | 4 | 5 | # install 6 | 7 | pip install flask-go 8 | 9 | 10 | # How to use 11 | It has two command now, `startproject` and `startapp`. 12 | If you familiar with Django, use `flask-go` just like django-admin. 13 | 14 | ## create project 15 | 16 | flask-go startproject project_name 17 | 18 | It will create project in current folder. 19 | if you want to create into specific path, you can: 20 | 21 | flask-go startproject project_name destination 22 | 23 | ## use your own template 24 | If you want to use your own project template files, `flask-go` also support `--template` command option. 25 | 26 | flask-go startproject project_name --template /Users/Cello/Code/my_project_template 27 | 28 | `flask-go` will replace `project_name` string in folder and file name and replace `%(project_name)s` in code text. 29 | 30 | ## create blueprint 31 | Like `startproject` command, but change to use `startapp`. 32 | 33 | flask-go startapp myapp 34 | 35 | `startapp` also support creat into specific path and `--template` command option. 36 | 37 | After creating blueprint, you should add it into your project. 38 | Open `settings.py` and import your app: 39 | 40 | ``` 41 | # blueprint 42 | from apps.myapp.views import myapp 43 | 44 | SYSTEM_BLUEPRINTS = ( 45 | (myapp, None), # blueprint and url_prefix 46 | ) 47 | ``` 48 | 49 | ## run flask 50 | 51 | python manage.py run 52 | 53 | Have fun! -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | flask-go 2 | ======== 3 | 4 | Let you create flask project like use django-admin 5 | 6 | install 7 | ======= 8 | 9 | :: 10 | 11 | pip install flask-go 12 | 13 | How to use 14 | ========== 15 | 16 | It has two command now, ``startproject`` and ``startapp``. If you 17 | familiar with Django, use ``flask-go`` just like django-admin. 18 | 19 | create project 20 | -------------- 21 | 22 | :: 23 | 24 | flask-go startproject project_name 25 | 26 | It will create project in current folder. if you want to create into 27 | specific path, you can: 28 | 29 | :: 30 | 31 | flask-go startproject project_name destination 32 | 33 | use your own template 34 | --------------------- 35 | 36 | If you want to use your own project template files, ``flask-go`` also 37 | support ``--template`` command option. 38 | 39 | :: 40 | 41 | flask-go startproject project_name --template /Users/Cello/Code/my_project_template 42 | 43 | ``flask-go`` will replace ``project_name`` string in folder and file 44 | name and replace ``%(project_name)s`` in code text. 45 | 46 | create blueprint 47 | ---------------- 48 | 49 | Like ``startproject`` command, but change to use ``startapp``. 50 | 51 | :: 52 | 53 | flask-go startapp myapp 54 | 55 | ``startapp`` also support creat into specific path and ``--template`` 56 | command option. 57 | 58 | After creating blueprint, you should add it into your project. Open 59 | ``settings.py`` and import your app: 60 | 61 | :: 62 | 63 | # blueprint 64 | from apps.myapp.views import myapp 65 | 66 | SYSTEM_BLUEPRINTS = ( 67 | (myapp, None), # blueprint and url_prefix 68 | ) 69 | 70 | run flask 71 | --------- 72 | 73 | :: 74 | 75 | python manage.py run 76 | 77 | Have fun! -------------------------------------------------------------------------------- /bin/flask-go.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from flask_go import management 4 | 5 | if __name__ == "__main__": 6 | management.execute_from_command_line() 7 | -------------------------------------------------------------------------------- /flask_go/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CelloCello/flask-go/bdd3e1a81e332cbbf0954ed23e5add29e3501a76/flask_go/__init__.py -------------------------------------------------------------------------------- /flask_go/app_template/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CelloCello/flask-go/bdd3e1a81e332cbbf0954ed23e5add29e3501a76/flask_go/app_template/__init__.py -------------------------------------------------------------------------------- /flask_go/app_template/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from flask import render_template 4 | from flask import Blueprint 5 | 6 | %(app_name)s = Blueprint('%(app_name)s', __name__) 7 | 8 | -------------------------------------------------------------------------------- /flask_go/commands/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /flask_go/commands/base.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class BaseCommand(object): 5 | def __init__(self): 6 | pass 7 | 8 | def execute(self, *args): 9 | pass 10 | 11 | def add_arguments(self, subcmd): 12 | """parse subcmd from list to directory with key you set 13 | """ 14 | pass -------------------------------------------------------------------------------- /flask_go/commands/startapp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import argparse 4 | import re 5 | 6 | import flask_go 7 | from base import BaseCommand 8 | 9 | 10 | class Command(BaseCommand): 11 | def __init__(self): 12 | pass 13 | 14 | def execute(self, subcmd): 15 | subcmd_dict = self.parse_subcmd(subcmd) 16 | app_name = subcmd_dict["app_name"] 17 | directory = subcmd_dict["directory"] 18 | tmp_from_path = subcmd_dict["template"] 19 | if directory: 20 | directory = os.path.abspath(os.path.expanduser(directory)) 21 | directory = os.path.join(directory, app_name) 22 | else: 23 | directory = os.path.join(os.getcwd(), app_name) 24 | 25 | template_path = self.get_template(tmp_from_path) 26 | prefix_length = len(template_path) + 1 27 | #print "temp path: " + template_path 28 | print "create projcet [%s] in direct: %s" % (app_name, directory) 29 | for root, dirs, files in os.walk(template_path): 30 | # make dirs 31 | path_rest = root[prefix_length:] 32 | root_reset = path_rest.replace("app_template", app_name) 33 | root_reset = root_reset.replace("app_name", app_name) 34 | dir_path = os.path.join(directory, root_reset) 35 | if not os.path.exists(dir_path): 36 | os.mkdir(dir_path) 37 | 38 | # read template files and write to directory 39 | for filename in files: 40 | if filename.endswith(('.pyo', '.pyc', '.py.class')): 41 | # Ignore some files as they cause various breakages. 42 | continue 43 | 44 | # read template 45 | tmp_path = os.path.join(root, filename) 46 | with open(tmp_path, 'rb') as tmp_file: 47 | content = tmp_file.read() 48 | content = re.sub(r"%(?!\(\w+\)s)", "%%", content) 49 | content %= subcmd_dict 50 | 51 | # write to directory 52 | dest_path = os.path.join(dir_path, filename.replace("app_name", app_name)) 53 | with open(dest_path, 'wb') as new_file: 54 | new_file.write(content) 55 | 56 | def parse_subcmd(self, subcmd): 57 | """parse subcmd from list to directory with key you set 58 | """ 59 | parser = argparse.ArgumentParser() 60 | parser.add_argument('app_name', help='Name of the application or project.') 61 | parser.add_argument('directory', nargs='?', help='Optional destination directory') 62 | parser.add_argument('--template', help='The path to load the template from.') 63 | args = parser.parse_args(subcmd) 64 | return vars(args) 65 | 66 | def get_template(self, from_path): 67 | if from_path is None: 68 | return os.path.join(flask_go.__path__[0], "app_template") 69 | else: 70 | expanded_template = os.path.expanduser(from_path) 71 | expanded_template = os.path.normpath(expanded_template) 72 | if os.path.isdir(expanded_template): 73 | return expanded_template 74 | 75 | raise Exception("error in template: " + from_path) -------------------------------------------------------------------------------- /flask_go/commands/startproject.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import argparse 4 | import re 5 | 6 | import flask_go 7 | from base import BaseCommand 8 | 9 | 10 | class Command(BaseCommand): 11 | def __init__(self): 12 | pass 13 | 14 | def execute(self, subcmd): 15 | subcmd_dict = self.parse_subcmd(subcmd) 16 | proj_name = subcmd_dict["project_name"] 17 | directory = subcmd_dict["directory"] 18 | tmp_from_path = subcmd_dict["template"] 19 | if directory: 20 | directory = os.path.abspath(os.path.expanduser(directory)) 21 | directory = os.path.join(directory, app_name) 22 | else: 23 | directory = os.path.join(os.getcwd(), proj_name) 24 | 25 | template_path = self.get_template(tmp_from_path) 26 | prefix_length = len(template_path) + 1 27 | #print "temp path: " + template_path 28 | print "create projcet [%s] in direct: %s" % (proj_name, directory) 29 | for root, dirs, files in os.walk(template_path): 30 | 31 | # make dirs 32 | path_rest = root[prefix_length:] 33 | root_reset = path_rest.replace("project_template", proj_name) 34 | root_reset = root_reset.replace("project_name", proj_name) 35 | dir_path = os.path.join(directory, root_reset) 36 | if not os.path.exists(dir_path): 37 | os.mkdir(dir_path) 38 | 39 | # read template files and write to directory 40 | for filename in files: 41 | if filename.endswith(('.pyo', '.pyc', '.py.class')): 42 | # Ignore some files as they cause various breakages. 43 | continue 44 | 45 | # read template 46 | tmp_path = os.path.join(root, filename) 47 | with open(tmp_path, 'rb') as tmp_file: 48 | content = tmp_file.read() 49 | content = re.sub(r"%(?!\(\w+\)s)", "%%", content) 50 | content %= subcmd_dict 51 | 52 | # write to directory 53 | dest_path = os.path.join(dir_path, filename.replace("project_name", proj_name)) 54 | with open(dest_path, 'wb') as new_file: 55 | new_file.write(content) 56 | 57 | def parse_subcmd(self, subcmd): 58 | """parse subcmd from list to directory with key you set 59 | """ 60 | parser = argparse.ArgumentParser() 61 | parser.add_argument('project_name', help='Name of the application or project.') 62 | parser.add_argument('directory', nargs='?', help='Optional destination directory') 63 | parser.add_argument('--template', help='The path to load the template from.') 64 | args = parser.parse_args(subcmd) 65 | return vars(args) 66 | 67 | def get_template(self, from_path): 68 | if from_path is None: 69 | return os.path.join(flask_go.__path__[0], "project_template") 70 | else: 71 | expanded_template = os.path.expanduser(from_path) 72 | expanded_template = os.path.normpath(expanded_template) 73 | if os.path.isdir(expanded_template): 74 | return expanded_template 75 | 76 | raise Exception("error in template: " + from_path) -------------------------------------------------------------------------------- /flask_go/management.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from importlib import import_module 5 | 6 | app_name = "flask_go" 7 | commands = { 8 | "startproject": "create a project", 9 | "startapp": "create a blueprint app", 10 | } 11 | 12 | 13 | def load_command_class(name): 14 | module = import_module("%s.commands.%s" % (app_name, name)) 15 | return module.Command() 16 | 17 | 18 | def get_command(name): 19 | try: 20 | commands[name] 21 | except: 22 | print "Unknow command: %r" % name 23 | return None 24 | 25 | return load_command_class(name) 26 | 27 | 28 | def help_text(): 29 | text = [ 30 | "Available subcommands:", 31 | "" 32 | ] 33 | 34 | for key, value in commands.iteritems(): 35 | cmd_text = "%s\t\t%s" % (key, value) 36 | text.append(cmd_text) 37 | 38 | return "\n".join(text) + "\n\n" 39 | 40 | 41 | def execute_from_command_line(): 42 | try: 43 | cmd = sys.argv[1] 44 | except IndexError: 45 | cmd = "help" 46 | 47 | try: 48 | subcmd = sys.argv[2:] 49 | except: 50 | print "error" 51 | 52 | if cmd == "help": 53 | sys.stdout.write(help_text()) 54 | else: 55 | exe = get_command(cmd) 56 | if exe: 57 | exe.execute(subcmd) 58 | -------------------------------------------------------------------------------- /flask_go/project_template/manage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from flask_script import Manager 4 | 5 | from %(project_name)s import create_app 6 | 7 | 8 | app = create_app(app_name="%(project_name)s") 9 | mgr = Manager(app) 10 | 11 | 12 | @mgr.command 13 | def run(): 14 | app.run() 15 | 16 | 17 | if __name__ == "__main__": 18 | mgr.run() 19 | -------------------------------------------------------------------------------- /flask_go/project_template/project_name/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from .%(project_name)s import * -------------------------------------------------------------------------------- /flask_go/project_template/project_name/apps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CelloCello/flask-go/bdd3e1a81e332cbbf0954ed23e5add29e3501a76/flask_go/project_template/project_name/apps/__init__.py -------------------------------------------------------------------------------- /flask_go/project_template/project_name/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CelloCello/flask-go/bdd3e1a81e332cbbf0954ed23e5add29e3501a76/flask_go/project_template/project_name/configs/__init__.py -------------------------------------------------------------------------------- /flask_go/project_template/project_name/configs/base.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class BaseConfig(object): 5 | DEBUG = True 6 | -------------------------------------------------------------------------------- /flask_go/project_template/project_name/project_name.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | 4 | from flask import Flask 5 | 6 | import settings 7 | 8 | 9 | def _config_app(app): 10 | """set flask config 11 | """ 12 | app.config.from_object(settings.SYSTEM_CONFIG_PATH) 13 | 14 | 15 | def _config_ext(app): 16 | """set config of extensions 17 | """ 18 | pass 19 | 20 | 21 | def _set_blueprints(app): 22 | for bp, prefix in settings.SYSTEM_BLUEPRINTS: 23 | print "blueprint: %s, prefix: %s" % (bp.name, prefix) 24 | print "root_path: " + bp.root_path 25 | app.register_blueprint(bp, url_prefix=prefix) 26 | 27 | 28 | def create_app(app_name): 29 | """create Flask app 30 | """ 31 | app = Flask(app_name) 32 | _config_app(app) 33 | _config_ext(app) 34 | _set_blueprints(app) 35 | 36 | return app 37 | -------------------------------------------------------------------------------- /flask_go/project_template/project_name/settings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | 5 | # blueprint 6 | #from apps.myapp.views import myapp 7 | 8 | # config 9 | SYSTEM_CONFIG_NAME = "%(project_name)s".upper() + "_CONFIG" 10 | SYSTEM_CONFIG_PATH = "%(project_name)s.configs.base.BaseConfig" 11 | env_config = os.environ.get(SYSTEM_CONFIG_NAME) 12 | if env_config: 13 | SYSTEM_CONFIG_PATH = "%(project_name)s.configs." + env_config 14 | 15 | 16 | # blueprint 17 | SYSTEM_BLUEPRINTS = ( 18 | #(myapp, None), 19 | ) 20 | -------------------------------------------------------------------------------- /flask_go/project_template/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==0.10.1 2 | Flask-Script==2.0.5 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from setuptools import setup, find_packages 4 | 5 | 6 | EXCLUDE_FROM_PACKAGES = [ 7 | 'flask_go.project_template', 8 | #'flask_go.project_template.project_name', 9 | 'flask_go.app_template' 10 | ] 11 | 12 | setup( 13 | name='flask-go', 14 | version='0.1.1', 15 | description='Let you create flask project like use django-admin', 16 | url='https://github.com/CelloCello/flask-go', 17 | author='Cello Hsueh', 18 | author_email="cello1124@gmail.com", 19 | license='BSD', 20 | packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES), 21 | include_package_data=True, 22 | scripts=['bin/flask-go.py'], 23 | entry_points={'console_scripts': [ 24 | 'flask-go = flask_go.management:execute_from_command_line', 25 | ]}, 26 | install_requires=[ 27 | 'flask', 28 | 'flask-script', 29 | ], 30 | zip_safe=False, 31 | classifiers=[ 32 | 'Development Status :: 4 - Beta', 33 | 'Environment :: Web Environment', 34 | 'Intended Audience :: Developers', 35 | 'License :: OSI Approved :: BSD License', 36 | 'Operating System :: OS Independent', 37 | 'Programming Language :: Python', 38 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 39 | 'Topic :: Software Development :: Libraries :: Python Modules' 40 | ] 41 | ) --------------------------------------------------------------------------------