Exemplo n.º 1
0
def config_js():
    ''' Produce a `config.js' from the [websocket] section of our config
        file. We have to muck about a bit to convert None etc. to JavaScript
        types ... '''

    newconf = cf.config('websocket')
    basic_auth = True
    if 'basic_auth' in newconf and newconf['basic_auth'] == False:
        basic_auth = False

    newconf['activo'] = cf.g('features', 'activo', False)
    for key in newconf:
        if type(newconf[key]) == str:
            if newconf[key][0] != '"' and newconf[key][0] != '"':
                newconf[key] = "'" + newconf[key] + "'"
        if type(newconf[key]) == bool:
            newconf[key] = 'true' if newconf[key] else 'false';
        # print key, " = ", type(newconf[key]), " : ",  newconf[key]

    newconf['configfile'] = cf.configfile

    if basic_auth == True:
        u = request.auth[0]
        u = u.replace("'", "\\'")

        p = request.auth[1]
        p = p.replace("'", "\\'")

        newconf['username'] = "******".format(u)
        newconf['password'] = "******".format(p)

    response.content_type = 'text/javascript; charset: UTF-8'
    return template('config-js', newconf)
Exemplo n.º 2
0
def config_js():
    ''' Produce a `config.js' from the [websocket] section of our config
        file. We have to muck about a bit to convert None etc. to JavaScript
        types ... '''

    newconf = cf.config('websocket')
    basic_auth = True
    if 'basic_auth' in newconf and newconf['basic_auth'] == False:
        basic_auth = False

    newconf['activo'] = cf.g('features', 'activo', False)
    for key in newconf:
        if type(newconf[key]) == str:
            if newconf[key][0] != '"' and newconf[key][0] != '"':
                newconf[key] = "'" + newconf[key] + "'"
        if type(newconf[key]) == bool:
            newconf[key] = 'true' if newconf[key] else 'false'
        # print key, " = ", type(newconf[key]), " : ",  newconf[key]

    newconf['configfile'] = cf.configfile

    if basic_auth == True:
        u = request.auth[0]
        u = u.replace("'", "\\'")

        p = request.auth[1]
        p = p.replace("'", "\\'")

        newconf['username'] = "******".format(u)
        newconf['password'] = "******".format(p)

    response.content_type = 'text/javascript; charset: UTF-8'
    return template('config-js', newconf)
Exemplo n.º 3
0
                track.append(tp)
            except:
                pass

    log.info("TRACK: (username=%s, tid=%s, topic=%s) RETURN %s recs" % (username, tid, topic, len(track)))

    data = {
        'topic'    : topic,
        'message'  : message,
        'tstamp'   : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(int(time.time()))),
        'track'    : track,
    }


    response.content_type = 'application/json'
    response.status = status
    return json.dumps(data, sort_keys=True, indent=2)
    return json.dumps(data, sort_keys=True, separators=(',',':'))

#  ---------------------------------------------------------------

if __name__ == '__main__':

    ctrldconf = cf.config('ctrld')
    bottle.debug(True)
    bottle.run(app,
        # server='python_server',
        host=ctrldconf.get('listen_host', "127.0.0.1"),
        port=ctrldconf.get('listen_port', 8809),
        )
Exemplo n.º 4
0
    data = {
        'topic':
        topic,
        'message':
        message,
        'tstamp':
        time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(int(time.time()))),
        'track':
        track,
    }

    response.content_type = 'application/json'
    response.status = status
    return json.dumps(data, sort_keys=True, indent=2)
    return json.dumps(data, sort_keys=True, separators=(',', ':'))


#  ---------------------------------------------------------------

if __name__ == '__main__':

    ctrldconf = cf.config('ctrld')
    bottle.debug(True)
    bottle.run(
        app,
        # server='python_server',
        host=ctrldconf.get('listen_host', "127.0.0.1"),
        port=ctrldconf.get('listen_port', 8809),
    )
Exemplo n.º 5
0
Arquivo: o2s.py Projeto: padelt/pista
jobtopic = None
devices = {}
imeilist = {}
jobs = {}
jobnames = {}
tasknames = {}
placenames = {}
machinenames = {}

createalltables()
jobnames[0] = ""
tasknames[0] = ""
placenames[0] = ""
machinenames[0] = ""

geo = RevGeo(cf.config('revgeo'), storage=storage)
wp = None

base_topics = []

alarm_plugin = None
if cf.g('features', 'alarm') is not None:
    try:
        alarm_plugin = imp.load_source('alarmplugin', cf.g('features', 'alarm'))
    except Exception, e:
        log.error("Can't import alarm_plugin {0}: {1}".format(storage_plugin, e))
        print e
        sys.exit(2)

if sys.version < '3':
    import codecs
Exemplo n.º 6
0
#    return static_file(filename, root='static')

@app.get('/<filename:re:.*\.(jpg|gif|png|ico)>')
def images(filename):
    return static_file(filename, root='static')

@app.get('/<filename:re:.*\.(eot|ttf|woff|svg|woff2)>')
def images(filename):
    return static_file(filename, root='static')

# from: http://michael.lustfield.net/nginx/bottle-uwsgi-nginx-quickstart
class StripPathMiddleware(object):
    '''
    Get that slash out of the request
    '''
    def __init__(self, a):
        self.a = a
    def __call__(self, e, h):
        e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
        return self.a(e, h)

if __name__ == '__main__':
    pistaconf = cf.config('pista')
    bottle.debug(True)
    bottle.run(app=StripPathMiddleware(app),
        # server='python_server',
        host=pistaconf.get('listen_host', "127.0.0.1"),
        port=pistaconf.get('listen_port', 8080),
        reloader=True)
    log.info("Bottle returns")
Exemplo n.º 7
0
jobtopic = None
devices = {}
imeilist = {}
jobs = {}
jobnames = {}
tasknames = {}
placenames = {}
machinenames = {}

createalltables()
jobnames[0] = ""
tasknames[0] = ""
placenames[0] = ""
machinenames[0] = ""

geo = RevGeo(cf.config('revgeo'), storage=storage)
wp = None

base_topics = []

alarm_plugin = None
if cf.g('features', 'alarm') is not None:
    try:
        alarm_plugin = imp.load_source('alarmplugin',
                                       cf.g('features', 'alarm'))
    except Exception, e:
        log.error("Can't import alarm_plugin {0}: {1}".format(
            storage_plugin, e))
        print e
        sys.exit(2)
Exemplo n.º 8
0

@app.get('/<filename:re:.*\.(eot|ttf|woff|svg|woff2)>')
def images(filename):
    return static_file(filename, root='static')


# from: http://michael.lustfield.net/nginx/bottle-uwsgi-nginx-quickstart
class StripPathMiddleware(object):
    '''
    Get that slash out of the request
    '''
    def __init__(self, a):
        self.a = a

    def __call__(self, e, h):
        e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
        return self.a(e, h)


if __name__ == '__main__':
    pistaconf = cf.config('pista')
    bottle.debug(True)
    bottle.run(
        app=StripPathMiddleware(app),
        # server='python_server',
        host=pistaconf.get('listen_host', "127.0.0.1"),
        port=pistaconf.get('listen_port', 8080),
        reloader=True)
    log.info("Bottle returns")