def list_jobs(): fields = ('#', 'job:*->tags', 'job:*->description') jobs = [{ 'id': d[0], 'description': d[2], 'tags': [t for t in d[1].split(',') if t] } for d in chunks(g.db.sort(KEY_JOBS, get=fields), 3)] return jsonify(jobs=jobs)
def list_recipes(): fields = ('#', 'recipe:*->tags', 'recipe:*->description') rows = [{ 'id': d[0], 'description': d[2], 'tags': [t for t in d[1].split(',') if t] } for d in chunks(g.db.sort(KEY_RECIPES, get=fields), 3)] return jsonify(recipes=rows)
def list_agents(): fields = ('#', 'agent:info:*->nick', 'agent:info:*->state', 'agent:info:*->seen', 'agent:info:*->labels') all = [{ 'id': d[0], 'nick': d[1], 'state': d[2], 'seen': int(d[3]), 'labels': [t for t in d[4].split(',') if t] } for d in chunks(g.db.sort(jdb.KEY_ALL, get=fields), 5)] return jsonify(agent_no=len(all), agents=all)
def get_recent_done(): recent = [] fields = ('#', 'build:*->number', 'build:*->created', 'build:*->description', 'build:*->build_id', 'build:*->result', 'build:*->job_name') for d in chunks( g.db.sort(BUILD_HISTORY, start=0, num=10, by='nosort', get=fields), 7): recent.append( dict(number=int(d[1]), created=d[2], description=d[3], job=d[6], build_id=d[4] or None, state=SESSION_STATE_DONE, result=d[5])) return jsonify(recent=recent)
def get_job(name): try: job = Job.load(name, ref=request.args.get('ref')) except JobNotFound: abort(404) blen = job.latest_build history = [] if request.args.get('history'): fields = ('#', 'build:*->number', 'build:*->created', 'build:*->description', 'build:*->build_id', 'build:*->state', 'build:*->result') for d in chunks( g.db.sort(KEY_JOB_BUILDS % name, start=blen - 10, num=10, by='nosort', get=fields), 7): history.append( dict(number=int(d[1]), created=d[2], description=d[3], build_id=d[4] or None, state=d[5], result=d[6])) history.reverse() yaml_str = job.yaml if request.args.get('yaml') else None return jsonify(name=job.name, ref=job.ref, recipe=job.recipe, recipe_ref=job.recipe_ref, description=job.description, tags=job.tags, success_no=job.last_success, latest_no=blen, history=history, parameters=job.parameters, merged_params=job.get_merged_params(), yaml=yaml_str)