Exemple #1
0
def create_app(env):
    app = Flask(__name__,
                static_folder='../static',
                template_folder='../templates')

    app.config.from_object(envs.get(env))
    init_ext(app)
    init_api(app)

    return app
Exemple #2
0
from flask import Flask
from flask_restful import Resource

from api import init_api
import settings
from dao import init_db

app = Flask(__name__)

#配置app
app.config.from_object(settings.Config)
#初始化API
init_api(app)
#初始化dao,或db
init_db(app)

if __name__ == '__main__':
    app.run()
Exemple #3
0
#!/usr/bin/env python3
#    Copyright (c) 2020 Merck Sharp & Dohme Corp. a subsidiary of Merck & Co., Inc., Kenilworth, NJ, USA.
#
#    This file is part of the Mutation Maker, An Open Source Oligo Design Software For Mutagenesis and De Novo Gene Synthesis Experiments.
#
#    Mutation Maker is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

from api import init_api

print("Mutation Maker version: 1.0.0")

api = init_api()
app = api.http.server()
Exemple #4
0
def get_app(production=True):
    setproctitle('api webserver [DINDI]')
    app = Flask(__name__,
                static_url_path="",
                static_folder='build',
                template_folder='build'
                )
    CORS(app)

    app.debug = not production

    private_config_get_or_create(app)
    app.db = initdb(app)
    init_security(app)
    init_api(app)
    app.db.create_all()

    UPLOAD_FOLDER = 'uploads'

    @app.errorhandler(404)
    def catch_all(e):
        url = flask.request.path
        if url == "/404/":
            jinja_env = Environment(
                loader=PackageLoader('templates'),
                autoescape=select_autoescape(['html', 'xml'])
            )

            template = jinja_env.get_template('404.html')
            return template.render(), 404
        else:
            # Catch-all
            ext = os.path.splitext(url)[-1]
            if ext in {'.jpg', '.ico', '.png', '.svg',
                       '.map', '.js', '.json', '.css'}:
                pass  # serve static from folder
            else:
                url = 'index.html'  # serve the SPA
            if url.startswith('/'):
                url = url[1:]
            if os.path.isfile(
                os.path.join(DIST_FOLDER, url)
            ):
                return flask.send_from_directory(DIST_FOLDER, url)
            else:
                logger.error("Missing file", url)
                return "File not found :( " + url

    @app.route("/upload/mini$/", methods=['POST'])
    def upload_mini():
        if 'file' not in flask.request.files:
            return flask.jsonify({"error": "No file provided"}), 400
        file = flask.request.files['file']
        filename = secure_filename(file.filename)
        full_path = os.path.join(UPLOAD_FOLDER, filename)
        os.makedirs(os.path.dirname(full_path), exist_ok=True)
        file.save(full_path)
        logger.info(f"Uploaded {filename}")
        return flask.jsonify(
            dict(
                message="Ok we received the mini$ file",
                file=filename
            )
        )

    return app
Exemple #5
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config[
    'SECRET_KEY'] = '\xc6\xed\x85\x99\xe9\xb3\xf2\xf1\xad\xed\x98\xc5\xb6=Zi\xbf\x9f\x05\xa2\xe0\xeb\xa7\xfe'
db = SQLAlchemy(app)

from commands import init_commands
import keepmydevices.views
from login import init_login
from admin import init_admin
from api import init_api

init_commands()
init_login()
init_admin()
init_api()
from flask import Flask
from flask import make_response
from flask import render_template
from flask.ext.sqlalchemy import SQLAlchemy
#import flask.ext.restless
from api import init_api

app = Flask(__name__)
app.config.from_pyfile('config')#, silent=True)
db = SQLAlchemy(app)

init_api(app, db)

@app.errorhandler(404)
def not_found(error):
	try:
		return render_template('404.html'), 404
	except:
		return make_response('{"error": "Not found"}', 404)

@app.errorhandler(204)
def not_found(error):
	return make_response('{"error": "No content"}', 404)

if __name__ == '__main__':
	app.run(port = 8000)
Exemple #7
0
	def main(cls):
		parser = optparse.OptionParser(usage="usage: %prog username ACTION [document-locator [action-specific-args]]")

		cls.commands = [
			Command('edit',   help='edit (with $EDITOR, or opener)'),
			Command('list',   help='list current texts'),
			Command('info',   help='get text info (key)', short='n'),
			Command('delete', help='delete (locator)'),
			Command('add',    help='add a new item (title, file)'),
			Command('set',    help='set new content for an item (locator, file)'),
			Command('get',    help='print out the contents of a text'),
			Command('rename', help='rename item (locator, new_title)'),
			Command('quit',   help=None),
		]

		cls.command_map = {}
		for command in cls.commands:
			if command.help is not None:
				command.add(parser)
			cls.command_map[command.short] = command.name

		cls.command_summary = ", ".join([command.description() for command in cls.commands][:-1]) + " or " + cls.commands[-1].description()

		parser.add_option('-i', '--interactive', action='store_const', const='interactive', dest='action', help='savemytext console')

		parser.add_option('-o', '--opener', help='set opener command (defaults to $EDITOR)', default=None)
		parser.add_option('-L', '--literal', dest='literal_content', action='store_true', help='use literal text content instead of file names', default=False)
		parser.add_option('--regex', help='find by case-insensitive regex (the default)', dest='locator', default='regex')
		parser.add_option('-x', '--exact', action='store_const', const='exact', help='find by exact title match (default regex)', dest='locator')
		parser.add_option('-k', '--key',   action='store_const', const='key',   help='find by DB key', dest='locator')
		parser.add_option('-I', '--index', action='store_const', const='index', help='find by index', dest='locator')

		parser.add_option('-v', '--verbose', action='store_true', default=False, help='verbose output')
		opts, args = parser.parse_args()

		try:
			if len(args) < 1:
				raise UsageError()

			user = args.pop(0)

			# general configuration - find method and editor
			cls.find = getattr(cls, 'find_by_' + opts.locator)
			cls.editor_args = (opts.opener or os.environ.get('EDITOR', 'gnome-text-editor')).split()
			cls.literal_content = opts.literal_content

			if opts.verbose:
				logging.root.setLevel(logging.DEBUG)

			action = opts.action or 'interactive'
			cls.interactively = action in ('interactive', 'edit', 'get')
			smt_func = lambda: init_api(user)
			instance = cls(smt_func)
			action_method = getattr(instance, action)
			instance.execute(action_method, args)
		except UsageError:
			parser.print_usage()
			sys.exit(1)
		except AppError, e:
			print e
			sys.exit(2)
Exemple #8
0
from api import init_api
from user import need_uid


app = Flask(__name__)
app.config.from_pyfile('config.py')
app.logger.setLevel(logging.INFO)
# jinja
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
# converter
init_converter(app)
# db
init_db(app)
# api
init_api(app)


@app.errorhandler(NotFound)
@app.errorhandler(BadRequest)
def error(error):
    code = error.code
    return render_template(
            'error.html',
            status_code=code,
            message=error.description
    ), code


@app.route('/', methods=['GET'])
def home():
Exemple #9
0
def app(monkeypatch):
    monkeypatch.setattr(config, "MODELS_FOLDER", "testdata/test-models/models")
    monkeypatch.setattr(config, "ML_HARDWARE", "cpu")
    app = init_api()
    yield app
Exemple #10
0
app = flask.Flask(__name__)

def init_projects():
    import api.db as db
    import git
    import model

    for project in db.session().query(model.Project).all():
        logger.info('Updating cache for project "%s" (%d)...', project.name, project.project_id)
        git.update_project_cache(project.project_id, project.fetch_url)

@app.route('/api/<path:path>')
def unknown_api_endpoint(**kwargs):
    flask.abort(404)

@app.route('/')
@app.route('/<path:path>')
def delegate_to_angular(**kwargs):
    return app.send_static_file('app.html')

if __name__ == '__main__':
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sparta.db'

    api.init_db(app)
    api.init_api(app)

    init_projects()

    app.run(debug=True)
Exemple #11
0
from api import init_api

server = init_api()