def check_auth(username, password): """This function is called to check if a username / password combination is valid. """ config = get_app_configurations() with open(config["credentials"], "r") as fh: u, p = fh.readline().rstrip().split(",") return username == u and password == p
#!/usr/bin/python # Serve static pages # Serve pages from path specified in the app configutation # file # The path should relative to the location of this blueprint from flask import Blueprint from utils.crossdomains import crossdomain from utils.config import get_app_configurations #get app configurations config = get_app_configurations() static = Blueprint('static', __name__, static_folder=config['static_dir']) @static.route('/') def serve_index(): """ The default request will serve index.html page """ return static.send_static_file('index.html') @static.route('/<path:path>') def serve_static_page(path): """ Serve the page specified in the path """ return static.send_static_file(path)
# Move to end of LRU slide = self._cache.pop(path) self._cache[path] = slide return slide osr = OpenSlide(path) slide = DeepZoomGenerator(osr, **self.dz_opts) try: mpp_x = osr.properties[openslide.PROPERTY_NAME_MPP_X] mpp_y = osr.properties[openslide.PROPERTY_NAME_MPP_Y] slide.mpp = (float(mpp_x) + float(mpp_y)) / 2 except (KeyError, ValueError): slide.mpp = 0 with self._lock: if path not in self._cache: if len(self._cache) == self.cache_size: self._cache.popitem(last=False) self._cache[path] = slide return slide cache = Cache(config={'CACHE_TYPE':'memcached'}) config = get_app_configurations() opts = { 'tile_size': int(config['tile_size']), 'overlap': int(config['overlap']), 'limit_bounds': int(config['limit_bounds']) } slide_cache = SlideCache(config['slide_cache_size'], opts)
#!/usr/bin/python # initialize the flask app # add configuration to the application # register the blueprints with the app from routes.deepzoom import dz from routes.slides import slides from routes.static import static from flask import Flask from utils.config import get_app_configurations import pymongo from flask import jsonify from bson import ObjectId import json #attach configurations stored in app.cfg to the app app = Flask('thumbnailer') app.config.from_envvar('DEEPZOOM_MULTISERVER_SETTINGS', silent=True) app.config.update(get_app_configurations()) #register the route blueprints to the app app.register_blueprint(dz) app.register_blueprint(slides) app.register_blueprint(static) if __name__ == "__main__": app.run(host='0.0.0.0', port=6060, debug=True)
#!/usr/bin/python # initialize the flask app # add configuration to the application # register the blueprints with the app from routes.deepzoom import dz from routes.slides import slides from routes.static import static from flask import Flask from utils.config import get_app_configurations #start the flask app app = Flask('dsa_adrc') #attach configurations stored in app.cfg to the app app.config.from_envvar('DEEPZOOM_MULTISERVER_SETTINGS', silent=True) app.config.update(get_app_configurations()) #register the route blueprints to the app app.register_blueprint(dz) app.register_blueprint(slides) app.register_blueprint(static)