from app.api import add_report, load_report, remove_report, get_status from app.utils import TODAY from app.helpers import log, exception_hook BASEDIR = p.dirname(__file__) DEF_PORT = 5000 DATE_FORMAT = Config.S3_DATE_FORMAT DAYS = Config.DAYS manager = Manager(create_app) manager.add_option("-m", "--cfgmode", dest="config_mode", default="Development") manager.add_option("-f", "--cfgfile", dest="config_file", type=p.abspath) manager.main = manager.run # Needed to do `manage <command>` from the cli logger = gogo.Gogo(__name__).logger @manager.option("-h", "--host", help="The server host") @manager.option("-p", "--port", help="The server port", default=DEF_PORT) @manager.option("-t", "--threaded", help="Run multiple threads", action="store_true") def serve(port, **kwargs): """Runs the flask development server""" with app.app_context(): kwargs["threaded"] = kwargs.get("threaded", app.config["PARALLEL"]) kwargs["debug"] = app.config["DEBUG"]
@manager.command def add_data_tables(): db.create_all() categorias = ("Producción", "Consumo", "Trilladoras", "Secado y tostión") for cat in categorias: categoria = Titulos(nombre=cat) db.session.add(categoria) db.session.commit() @manager.command def create_admin(): usuario = { "username": input("Usuario:"), "password": getpass("Password:"******"nombre": input("Nombre completo:"), "email": input("Email:"), "admin": True } usu = Usuarios(**usuario) db.session.add(usu) db.session.commit() # Turn on debugger by default and reloader manager.add_command( "runserver", Server(use_debugger=True, use_reloader=True, host='0.0.0.0')) if __name__ == '__main__': manager.main()
from urllib.parse import urlsplit except ImportError: from urlparse import urlsplit from app import create_app from flask import current_app as app from flask_script import Server, Manager BASEDIR = p.dirname(__file__) DEF_PORT = 5000 manager = Manager(create_app) manager.add_option( '-m', '--cfgmode', dest='config_mode', default='Development') manager.add_option('-f', '--cfgfile', dest='config_file', type=p.abspath) manager.main = manager.run # Needed to do `manage <command>` from the cli @manager.option('-h', '--host', help='The server host') @manager.option('-p', '--port', help='The server port') @manager.option( '-t', '--threaded', help='Run multiple threads', action='store_true') def runserver(live=False, offline=False, timeout=None, **kwargs): # Overriding the built-in `runserver` behavior """Runs the flask development server""" with app.app_context(): if app.config.get('SERVER'): parsed = urlsplit(app.config['SERVER']) host, port = parsed.netloc, parsed.port or DEF_PORT else: host, port = app.config['HOST'], DEF_PORT