-
-
Save cstrap/4047161 to your computer and use it in GitHub Desktop.
flask application basic setup
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
#!/usr/local/bin/python | |
from optparse import OptionParser | |
import os | |
PATH_SEPARATOR = os.sep | |
html_page = "<!DOCTYPE html>\n" \ | |
" <html>\n" \ | |
" <body>\n" \ | |
" <h1>Flask Application</h1>\n" \ | |
"</body>\n" \ | |
"</html>" | |
def createPath(path): | |
if not os.path.isdir(path): | |
os.makedirs(path) | |
def init(appname): | |
# create the application root | |
createPath(appname) | |
# __init__ | |
init_file = PATH_SEPARATOR.join([appname, '__init__.py']) | |
if not os.path.exists(init_file): | |
open(init_file, 'w').close() | |
# create the static directory | |
path = [appname, 'static'] | |
createPath(PATH_SEPARATOR.join(path)) | |
path = [appname, 'static', 'js'] | |
createPath(PATH_SEPARATOR.join(path)) | |
# create the template directory | |
path = [appname, 'static', 'img'] | |
createPath(PATH_SEPARATOR.join(path)) | |
# create the template directory | |
path = [appname, 'templates'] | |
createPath(PATH_SEPARATOR.join(path)) | |
# index.html | |
index = PATH_SEPARATOR.join([appname, 'templates', 'index.html']) | |
if not os.path.exists(index): | |
index_file = open(index, 'w') | |
index_file.write(html_page) | |
index_file.close() | |
if __name__ == '__main__': | |
parser = OptionParser() | |
parser.add_option("-a", "--app", dest="appname", | |
help="application name", default='flask_app') | |
(options, args) = parser.parse_args() | |
print 'Start ...' | |
print ' creating %s app' %options.appname | |
init(options.appname) | |
print ' done !!!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment