Example #1
0
import base64
import datetime
import redis
import os
import sys

reload(sys)
sys.setdefaultencoding("utf8")

from web.models import utils, RedisHandler, RedisSessionInterface, cache, OauthBackend
from web.models.whoosh import SenIndexer, DocIndexer, DefinitionIndexer, Searcher
from web.config import CONFIG, ENV

app = Flask(__name__)
# root dir
app.config["ROOT_DIR"] = os.path.dirname(os.path.abspath(__file__))

# upload config
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
app.config["UPLOAD_FOLDER"] = app.config["ROOT_DIR"] + CONFIG["UPLAOD_DIR"]

# server config
app.config["SERVER_NAME"] = CONFIG["SERVER_NAME"]
app.config["CSRF_ENABLED"] = True
app.config["SECRET_KEY"] = os.urandom(24)

# gen basic auth
CONFIG["BASIC_AUTH"] = "Basic %s" % base64.encodestring("%s:%s" % (CONFIG["NAME"], CONFIG["PASSWORD"]))[:-1]

# session config
if "REDIS_SESSION" in CONFIG:
from flask import Flask, render_template
import os
import numpy as np
import fnmatch
import datetime
import warnings
import pyfits
import cPickle as pickle

warnings.filterwarnings("ignore", category=Warning)

app = Flask(__name__)
app.config["ROOT_DIR"] = r"/home/makov/tmp/tomo_root/Raw/2012_10_22/bone_Cu15x10_30x1sec/original"
# app.config['ROOT_DIR'] = r'/media/tmp/flash_backup/2cryst'
app.config["FILES_LIST"] = []
app.config["FILES_INFO"] = {}

pickle_file_name = "preload.bin"
if os.path.exists(pickle_file_name):
    with open(pickle_file_name, "r") as pf:
        app.config["FILES_INFO"] = pickle.load(pf)


@app.route("/")
def index():
    data = get_data()
    return render_template("index.html", data=data)


def get_data():
    update_files_list(app.config["ROOT_DIR"], app.config["FILES_LIST"])