Commit e9e1beed authored by Tim Brooks's avatar Tim Brooks
Browse files

Virtualenv bootstrapping

parent 20297fe9
*.egg-info
dist
env
log
uploads
......
[submodule "mcviz.standalone"]
path = mcviz.standalone
url = https://github.com/brookst/mcviz.git
This diff is collapsed.
Subproject commit 768e431403ca8a8dd7b6d3f3df8b86da38f7bc86
"""Make bootstrap script"""
import virtualenv, textwrap
OUTPUT = virtualenv.create_bootstrap_script(textwrap.dedent("""
import os, subprocess, textwrap
from os.path import join
def after_install(options, home_dir):
dirs = ['log', 'uploads', 'renders']
for folder in dirs:
if not os.path.exists(folder):
os.makedirs(folder)
ret = subprocess.call([join(home_dir, 'bin', 'pip'), 'install', '-e',
'mcviz.standalone'])
if ret:
print("Error installing mcviz")
return
ret = subprocess.call([join(home_dir, 'bin', 'pip'), 'install', '-e', '.'])
if ret:
print("Error installing mcviz.web")
return
print("")
print("Check the user running apache can access these folders")
print("e.g. > chown ${USER}:www-data log uploads renders")
print(" > chmod 775 .")
def adjust_options(options, args):
args[:] = ["env"]
"""))
open('bootstrap.py', 'w').write(OUTPUT)
......@@ -8,11 +8,11 @@ from logging.handlers import RotatingFileHandler
from flask import Flask, abort, request, send_from_directory, render_template
from werkzeug import secure_filename
UPLOAD_FOLDER = os.path.dirname('uploads/')
RENDER_FOLDER = os.path.dirname('renders/')
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads/')
RENDER_FOLDER = os.path.join(os.getcwd(), 'renders/')
FILE_HANDLER = RotatingFileHandler('log/flask.log')
APP = Flask(__name__)
APP = Flask(__name__, template_folder=os.path.join(os.getcwd(), 'templates/'))
APP.logger.addHandler(FILE_HANDLER)
APP.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
APP.config['RENDER_FOLDER'] = RENDER_FOLDER
......@@ -98,16 +98,16 @@ def get_image(file_name):
workspace.run()
APP.logger.info("Rendering %s done", name)
return send_from_directory("renders/", file_name)
return send_from_directory(APP.config['RENDER_FOLDER'], file_name)
if __name__ == "__main__":
from logging import Formatter
TEMPLATE = "[%(asctime)s|%(levelname)-7s] %(message)s"
APP.debug = True
APP.logger.setLevel(logging.DEBUG)
for handler in APP.logger.handlers:
handler.setLevel(logging.DEBUG)
handler.setFormatter(Formatter(TEMPLATE))
APP.run(host='0')
from logging import Formatter
TEMPLATE = "[%(asctime)s|%(levelname)-7s] %(message)s"
APP.logger.setLevel(logging.DEBUG)
for handler in APP.logger.handlers:
handler.setLevel(logging.DEBUG)
handler.setFormatter(Formatter(TEMPLATE))
activate_this = 'env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from mcviz.web.app import APP as application
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment