Esempio n. 1
0
def main():
    try:
        rfk.init()
        if rfk.CONFIG.has_option('database', 'url'):
            init_db(rfk.CONFIG.get('database', 'url'))
        else:
            init_db("%s://%s:%s@%s/%s" % (rfk.CONFIG.get('database', 'engine'),
                                          rfk.CONFIG.get('database', 'username'),
                                          rfk.CONFIG.get('database', 'password'),
                                          rfk.CONFIG.get('database', 'host'),
                                          rfk.CONFIG.get('database', 'database')))
        for relay in Relay.query.all():
            try:
                relay.usage = get_stats_direct(relay)
                rs = RelayStatistic.get_relaystatistic(relay, RelayStatistic.TYPE.TRAFFIC)
                if relay.usage is not None:
                    rs.statistic.set(now(), relay.usage)
                relay.status = Relay.STATUS.ONLINE
                rfk.database.session.commit()
            except urllib2.URLError as e:
                rfk.database.session.rollback()
                relay.status = Relay.STATUS.UNKNOWN
                rfk.database.session.commit()
                print "Could not reach server: {}:{} - ".format(relay.address, relay.port, str(e))
            except socket.timeout as e:
                rfk.database.session.rollback()
                relay.status = Relay.STATUS.UNKNOWN
                rfk.database.session.commit()
                print "Could not reach server: {}:{} - ".format(relay.address, relay.port, str(e))
    except Exception as e:
        print e
    finally:
        rfk.database.session.rollback()
        rfk.database.session.remove()
Esempio n. 2
0
def main():
    try:
        rfk.init()
        if rfk.CONFIG.has_option('database', 'url'):
            init_db(rfk.CONFIG.get('database', 'url'))
        else:
            init_db("%s://%s:%s@%s/%s" % (rfk.CONFIG.get('database', 'engine'),
                                          rfk.CONFIG.get('database', 'username'),
                                          rfk.CONFIG.get('database', 'password'),
                                          rfk.CONFIG.get('database', 'host'),
                                          rfk.CONFIG.get('database', 'database')))
        for user in User.query.yield_per(50):
            for stat in stats:
                stat(user)
        rfk.database.session.commit()
    except Exception as e:
        rfk.database.session.rollback()
        raise
    finally:
        rfk.database.session.remove()
Esempio n. 3
0
def main():
    try:
        rfk.init()
        if rfk.CONFIG.has_option('database', 'url'):
            init_db(rfk.CONFIG.get('database', 'url'))
        else:
            init_db("%s://%s:%s@%s/%s" %
                    (rfk.CONFIG.get('database', 'engine'),
                     rfk.CONFIG.get('database', 'username'),
                     rfk.CONFIG.get('database', 'password'),
                     rfk.CONFIG.get('database', 'host'),
                     rfk.CONFIG.get('database', 'database')))
        for user in User.query.yield_per(50):
            for stat in stats:
                stat(user)
        rfk.database.session.commit()
    except Exception as e:
        rfk.database.session.rollback()
        raise
    finally:
        rfk.database.session.remove()
Esempio n. 4
0
def main():
    try:
        rfk.init()
        if rfk.CONFIG.has_option('database', 'url'):
            init_db(rfk.CONFIG.get('database', 'url'))
        else:
            init_db("%s://%s:%s@%s/%s" %
                    (rfk.CONFIG.get('database', 'engine'),
                     rfk.CONFIG.get('database', 'username'),
                     rfk.CONFIG.get('database', 'password'),
                     rfk.CONFIG.get('database', 'host'),
                     rfk.CONFIG.get('database', 'database')))
        for relay in Relay.query.all():
            try:
                relay.usage = get_stats_direct(relay)
                rs = RelayStatistic.get_relaystatistic(
                    relay, RelayStatistic.TYPE.TRAFFIC)
                if relay.usage is not None:
                    rs.statistic.set(now(), relay.usage)
                relay.status = Relay.STATUS.ONLINE
                rfk.database.session.commit()
            except urllib2.URLError as e:
                rfk.database.session.rollback()
                relay.status = Relay.STATUS.UNKNOWN
                rfk.database.session.commit()
                print "Could not reach server: {}:{} - ".format(
                    relay.address, relay.port, str(e))
            except socket.timeout as e:
                rfk.database.session.rollback()
                relay.status = Relay.STATUS.UNKNOWN
                rfk.database.session.commit()
                print "Could not reach server: {}:{} - ".format(
                    relay.address, relay.port, str(e))
    except Exception as e:
        print e
    finally:
        rfk.database.session.rollback()
        rfk.database.session.remove()
Esempio n. 5
0
    opposite operation to :func:`to_user_timezone`.
    """
    if datetime.tzinfo is None:
        datetime = flask.ext.babel.get_timezone().localize(datetime)
    return datetime.astimezone(pytz.utc).replace(tzinfo=pytz.UTC)


flask.ext.babel.to_utc = to_utc

import rfk
from rfk.database import init_db


rfk.init()
if rfk.CONFIG.has_option('database', 'url'):
    init_db(rfk.CONFIG.get('database', 'url'))
else:
    init_db("%s://%s:%s@%s/%s" % (rfk.CONFIG.get('database', 'engine'),
                                  rfk.CONFIG.get('database', 'username'),
                                  rfk.CONFIG.get('database', 'password'),
                                  rfk.CONFIG.get('database', 'host'),
                                  rfk.CONFIG.get('database', 'database')))
from rfk.site import app

app.template_folder = '../templates/'
app.static_folder = '../static/'
app.static_url_path = '/static'


def main():
    app.run(host='0.0.0.0', debug=True)