Exemple #1
0
def progs():
    if not request.forms:        # GET
        return programs.status()

    obj = request.forms
    func = getattr(programs, "%s_%s" % (obj.get('action', ''), 
        obj.get('program', '')), None)
    if not func:
        log.debug("action '%s' not found" % obj.get('action', ''))
        return {'error': "action '%s' not found" % obj.get('action','')}

    # only keyword arguments allowed
    kwargs = {}
    spec = inspect.getargspec(func)
    for variable in spec.args:
        value = obj.get(variable, None)
        if not value is None:
            kwargs[variable] = value

    try:
        func(**kwargs)
    except:
        log.exception()
    return programs.status()
Exemple #2
0
def status():
    status = {}
    status['lights'] = lightbot.status()
    status['programs'] = programs.status()
    return status