def api_module_info(module_name): try: module_info = use_module(module_name).info module_info['name'] = path.realname(module_info['name']) # hack return jsonify(module_info) except (TypeError, RuntimeError) as e: app.logger.exception(e) abort(404)
def api_module_info(module_name): try: module_info = use_module(module_name).info module_info['name'] = path.realname(module_info['name']) # hack return jsonify(module_info) except (TypeError, RuntimeError) as e: app.logger.exception(e) abort(404)
def api_module_status(module_name): # TODO add support for multiple instances if not packaging.is_installed(module_name): app.logger.warning('%s not installed', module_name) abort(404) try: mod = use_module(module_name) mod.info['name'] = path.realname(mod.info['name']) # hack except RuntimeError as e: app.logger.exception(e) abort(404) else: fields = {} for f in mod.info['fields']: if 'readable' not in f or not f['readable']: continue value = getattr(mod, f['name'])() if value is None: continue f.update(dict(zip(('time', 'value'), value))) return jsonify(mod.info)
def api_module_status(module_name): # TODO add support for multiple instances if not packaging.is_installed(module_name): app.logger.warning('%s not installed', module_name) abort(404) try: mod = use_module(module_name) mod.info['name'] = path.realname(mod.info['name']) # hack except RuntimeError as e: app.logger.exception(e) abort(404) else: fields = {} for f in mod.info['fields']: if 'readable' not in f or not f['readable']: continue value = getattr(mod, f['name'])() if value is None: continue f.update(dict(zip(('time', 'value'), value))) return jsonify(mod.info)
def api_available_module_set_rate(): """ TODO: api key """ # validate module name try: module_name = path.realname(request.form['name']) # hack except KeyError: abort(400) # check that the module is indeed available if not catalog.is_available(module_name): app.logger.warning('Module "%s" not available', module_name) abort(404) # save the new rating try: value = int(request.form['value']) Rating.create(module=module_name, value=value) return jsonify({ 'success': True }) except (ValueError, KeyError) as e: app.logger.exception(e) abort(404)