예제 #1
0
>>> flask run --debugger
"""

# When running under WSGI, system environment variables are not automatically made available to Python code, and
# an app restart will result in configurations being lost. We work around this with an explicit load from the shell
# environment, sourcing from the Elastic Beanstalk-provided /opt/python/current/env file if available.
if __name__.startswith('_mod_wsgi'):
    command = [
        'bash', '-c', '{ source /opt/python/current/env || true; } && env'
    ]
    shell_environment = subprocess.Popen(command, stdout=subprocess.PIPE)
    for line in shell_environment.stdout:
        key, _, value = line.decode('utf-8').rstrip().partition('=')
        os.environ[key] = value

application = create_app()

host = application.config['HOST']
port = application.config['PORT']

if __name__ == '__main__':
    application.logger.info('Starting development server on %s:%s', host, port)
    application.run(host=host, port=port)
elif __name__.startswith('_mod_wsgi'):
    # Grab the current EC2 instance id and stash it in an environment variable.
    try:
        instance_metadata = subprocess.Popen(['ec2-metadata', '-i'],
                                             stdout=subprocess.PIPE)
        os.environ['EC2_INSTANCE_ID'] = next(instance_metadata.stdout).decode(
            'utf-8').partition(':')[2].strip()
    except Exception as e:
예제 #2
0
파일: consoler.py 프로젝트: dkawase/nessie
from pprintpp import pprint as pp  # noqa
"""Run Flask-wrapped code from a Python console.

* From the command line:
    ``nessie> python -i consoler.py``

* In PyCharm preferences, go to "Build, Execution, Deployment"
* For "Console", enable "Always show debug console"
* For "Python Console", enable "Add source roots to PYTHONPATH"
* Add this line to the starting script:
    ``runfile('consoler.py')``
* Save
* Click on "Python Console"
* Click the bug icon to start a debugging session:

>>> from nessie.externals import redshift
>>> assignments = redshift.fetch('select * from canvas.assignment_dim limit 10')
>>> pp(assignments)
[
    Record(id=12340000001234567, canvas_id=1234567 course_id=12340000009876564, title='Diagnostic Essay'...
"""

app = create_app()
ac = app.app_context()
ac.push()

print(
    'You are now in a Flask app context. To run normal app teardown processes, type:'
)
print('   ac.pop()')