/
manage.py
94 lines (68 loc) · 2.25 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import shlex
import subprocess
import pwnurl.common.helpers as h
from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import MigrateCommand
from flask.ext.assets import ManageAssets
from pwnurl import __version__ as ver
from pwnurl.app import create_app
from pwnurl.models import User, Role
from pwnurl.config import configs
from pwnurl.common.extensions import assets, db
from pwnurl.common.gunicorn_server import GunicornServer
from pwnurl.common.populate_manager import manager as populate_manager
phelp = """
Python
======
locals: %s
"""
shelp = \
"""
SQLAlchemy
==========
query:
User.query.all()
User.query.filter_by(id=1).first().username
"""
env = os.environ.get('PWNURL_ENV', 'dev')
app = create_app(configs[env])
if os.environ.get('PWNURL_SETTINGS', None):
app.config.from_envvar('PWNURL_SETTINGS')
manager = Manager(app)
def config(key):
""" Return app configuration value based on specified key """
return app.config.get(key.upper(), None)
@manager.command
def test():
""" Run all Tests [nose] """
command = 'nosetests --with-coverage --cover-package=pwnurl'
status = subprocess.call(shlex.split(command))
sys.exit(status)
@manager.command
def profile(length=25):
""" Start the application under the code profiler """
from werkzeug.contrib.profiler import ProfilerMiddleware
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length])
app.run()
def _help():
""" Display both SQLAlchemy and Python help statements """
statement = '%s%s' % (shelp, phelp % ', '.join(cntx_.keys()))
print statement.strip()
cntx_ = dict(app=app, db=db, User=User, Role=Role, help=_help, h=h)
shell = dict(
make_context=lambda: cntx_,
banner='Interactive PwnUrl Shell v%s [type help() for help sheet]' % ver
)
bind_options = (config('host'), config('port'))
manager.add_command('gunicorn', GunicornServer(*bind_options))
manager.add_command('server', Server(*bind_options))
manager.add_command('assets', ManageAssets(assets))
manager.add_command('shell', Shell(**shell))
manager.add_command('db', MigrateCommand)
manager.add_command('populate', populate_manager)
if __name__ == '__main__':
manager.run()