Example #1
0
def create_app(app_mode='DEBUG'):
    """ Create application, register blueprints, etc """
    # create an application
    app = Flask(__name__)
    # set logging
    if app_mode == '':
        app_mode = os.environ.get('APP_MODE', 'DEBUG')
    if app_mode == 'PROD':
        app.config.from_object(ProductionConfig)
        #create_rotating_log(app, 'app.log')
        logging.basicConfig(
            filename='app.log',
            format='%(asctime)s %(levelname)s %(message)s',
            level=logging.DEBUG)
    elif app_mode == 'OPENSHIFT':
        app.config.from_object(OpenshiftConfig)
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s'
        )
    else:
        #app.debug_log_format = '%(asctime)s %(levelname)s %(message)s'
        #app.logger.setLevel(logging.DEBUG)
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s'
        )
        app.config.from_object(Config)
    logging.debug('Starting app in %s mode' % app_mode)
    # register blueprints
    app.register_blueprint(ui)
    #register jinja2 functions
    app.jinja_env.globals.update(max=max)
    # set secret for sessions
    app.secret_key = 'Qm9enl7mikELxCbcMvsP'
    # set login manager
    app.users = dict()
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = '/auth'
    login_manager.user_callback = user_loader
    # register flask-debugtoolbar
    if app_mode == 'DEBUG':
        app.dtb = DebugToolbarExtension(app)
    # init tinydb
    app.repo = Repository()
    app.repo.init_db(app.config['TINYDB_FILE'])
    # init WgDataProvider
    WgDataProvider.APP_ID = app.config['APP_ID']
    WgDataProvider.CACHE_DIR = app.config['CACHE_DIR']
    return app
Example #2
0
def create_app(options):
    app = Flask(__name__)

    app.secret_key = 'ed788cab1d449175885623bf5fad28101898b059380a263f'

    config = ConfigParser.ConfigParser()
    config.readfp(open(options.config))

    app.mopts = misc.MagicOptions(config_defaults, dict(config.items(options.section)), vars(options), dict(section=options.section))
    app.users = dict(config.items('users_' + options.section))
    engine = create_engine(app.mopts.uri)
    adjust_schemas(staging=app.mopts.staging_schema, model=app.mopts.model_schema)
    Session = sessionmaker(bind=engine)  # autocommit=True)

    auth.init_login_manager(app)
    jinja_local.jinja_filters.init_app(app)
    misc.menu.init_app(app)

    app.register_blueprint(auth.auth)
#    app.register_blueprint(errors.errors)
    app.register_blueprint(home.homebp, url_prefix='/home')
    app.register_blueprint(crn.crnbp, url_prefix='/crn')

#    @app.route('/')
#    def root():
#        return redirect(url_for('binterface.ctl_jobs', filter='php_only'))

    @app.after_request
    def session_commit(response):
        session = getattr(g, 'session', None)
        if session is not None:
            g.session.commit()
        return response

    @app.before_request
    def before_request():
        g.session = Session()

    @app.teardown_request
    def teardown_request(exception):
        session = getattr(g, 'session', None)
        if session is not None:
            session.close()
    return app
Example #3
0

def getrandbytes(k):
    '''
    get an ascii string of randbits
    '''
    bits = getrandbits(k * 8)
    hex_bits = hex(bits)[2:].strip('L')
    if len(hex_bits) % 2 == 1:
        hex_bits = '0' + hex_bits
    return unhexlify(hex_bits)


###############################
# TOQU: save this stuff to a DB
app.users = {}
try:
    with open('users.json') as users_jsonfile:
        app.users = json.loads(users_jsonfile.read())
except IOError:
    pass
except ValueError:
    pass
###############################


def hash_password(salt, password):
    '''
    salt and hash the password
    '''
    saltpass = "".join([chr(ord(c)) for c in salt] +
Example #4
0
    clear_old_delays()
    app.day = str(t.tm_year) + str(t.tm_yday)
    return payments

@app.route("/getresults", methods=['POST'])
def send_results():
    user = request.form['username']
    results = calculate_results(app.users, app.groups[app.users[user][1]], 10)
    for ower, payment in results.items():
        app.ledger[ower].append(payment)
    return (str(app.ledger[user]) if app.ledger[user] else "you get paid") + "\n"

if __name__ == "__main__":
    os.environ['TZ'] = 'US/Eastern'
    app.groups = {}
    app.users = {} # map from username to (list of delays)
    app.ledger = {}
    app.alarms = defaultdict(list) # map from username to alarms for the user
    t = time.localtime()
    app.day = str(t.tm_year) + str(t.tm_yday - 1)

    if len(sys.argv) == 2:
        CONSUMER_ID = ANDREW_CONSUMER_ID
        CONSUMER_SECRET = ANDREW_CONSUMER_SECRET
        APP_SECRET = ANDREW_APP_SECRET
        p = 8081
    else:
        p = 8080
    app.secret_key = APP_SECRET
    app.delays = {}
    app.successes = {}
Example #5
0
import cPickle as pickle
import pusher
import sys

app = Flask(__name__)
app.rooms = {}
app.default_matrix = [
	{"sample": "kick", "path": "/static/samples/kick.mp3", "melodic": False, "triggers": [True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False]},
	{"sample": "hat", "path": "/static/samples/hat.mp3", "melodic": False, "triggers": [False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False]},
	{"sample": "snare", "path": "/static/samples/snare.mp3", "melodic": False, "triggers": [False, False, False, False, True, False, False, False, False, False, False, False, True, False, False, False]},
	{"sample": "crash" ,"path": "/static/samples/crash.mp3", "melodic": False, "triggers": [True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]},
	{"sample": "bass", "path": "/static/samples/bass.mp3", "melodic": True,
	 "triggers": [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False],
	 "notes": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], "editing": True}
]
app.users = {}

def randomRoomName():
	return "%s%d" % (random.choice(app.words), random.randint(1, 99))

def persist():
	pickle.dump(app.rooms, open("db", "w"))
	app.persist_timer = threading.Timer(5.0, persist)
	app.persist_timer.start()

@app.route("/change/<room>/<sample>/<position>", methods=['POST', 'DELETE'])
def change(room, sample, position):
	enabled = request.method == 'POST'

	for track in app.rooms[room]:
		if track["sample"] == sample: