Change to the new paging format with the commands available at the top.

This commit is contained in:
yackob03 2014-02-10 19:12:43 -05:00
parent dee6088b90
commit 6fd343741b
7 changed files with 213 additions and 140 deletions

View file

@ -1184,10 +1184,31 @@ def get_repo_build_status(namespace, repository, build_uuid):
def get_repo_build_logs(namespace, repository, build_uuid):
permission = ModifyRepositoryPermission(namespace, repository)
if permission.can():
response_obj = {}
build = model.get_repository_build(namespace, repository, build_uuid)
start = int(request.args.get('start', -1000))
start_param = request.args.get('start', None)
end = int(request.args.get('end', -1))
last_command = None
include_commands = request.args.get('commands', 'false')
if include_commands.lower() not in {'0', 'false'}:
commands = [cmd for cmd in build_logs.get_commands(build.uuid)]
response_obj['commands'] = commands
if commands:
last_command = commands[-1]
elif start_param is None:
last_command = build_logs.get_last_command(build.uuid)
if start_param is None:
if last_command:
start = last_command['index']
else:
start = 0
else:
start = int(start_param)
count, logs = build_logs.get_log_entries(build.uuid, start, end)
if start < 0:
@ -1196,13 +1217,15 @@ def get_repo_build_logs(namespace, repository, build_uuid):
if end < 0:
end = count + end
return jsonify({
response_obj.update({
'start': start,
'end': end,
'total': count,
'logs': [log for log in logs],
})
return jsonify(response_obj)
abort(403) # Permission denied

View file

@ -1,124 +0,0 @@
import math
from random import SystemRandom
from flask import jsonify, request
from loremipsum import get_sentences
from endpoints.api import api
def generate_image_completion(rand_func):
images = {}
for image_id in range(rand_func.randint(1, 11)):
total = int(math.pow(abs(rand_func.gauss(0, 1000)), 2))
current = rand_func.randint(0, total)
image_id = 'image_id_%s' % image_id
images[image_id] = {
'total': total,
'current': current,
}
return images
def generate_fake_status():
response = {
'id': 'deadbeef-dead-beef-dead-beefdeadbeef',
'status': None,
}
random = SystemRandom()
phases = {
'waiting': {},
'starting': {
'total_commands': 7,
'current_command': 0,
},
'initializing': {},
'error': {},
'complete': {},
'building': {
'total_commands': 7,
'current_command': random.randint(1, 7),
},
'pushing': {
'total_commands': 7,
'current_command': 7,
'push_completion': random.random(),
'image_completion': generate_image_completion(random),
},
}
phase = random.choice(phases.keys())
response['phase'] = phase
response['status'] = (phases[phase])
return response
BASE_BUILDING_URL = '/repository/devtable/building/build/'
@api.route(BASE_BUILDING_URL, methods=['GET'])
def get_fake_repo_build_status_list():
return jsonify({'builds': [generate_fake_status()]})
@api.route(BASE_BUILDING_URL + 'deadbeef-dead-beef-dead-beefdeadbeef/logs',
methods=['GET'])
def get_fake_repo_build_logs():
start = int(request.args.get('start', 0))
end = int(request.args.get('end', 0))
had_start = 'start' in request.args
had_end = 'end' in request.args
adv_start = 0
adv_end = 0
adv_total = 0
lorem_logs = []
if had_start and had_end:
numlogs = end - start + 1
adv_start = start
adv_end = end
adv_total = end + 1
lorem_logs = get_sentences(numlogs)
elif had_start:
adv_start = start
adv_end = start + 9
lorem_logs = get_sentences(10)
adv_total = adv_end + 1
elif had_end:
adv_start = max(0, (end - 9))
adv_end = end
adv_total = end + 1
lorem_logs = get_sentences(adv_end - adv_start + 1)
else:
adv_start = 100
adv_end = 109
adv_total = 110
lorem_logs = get_sentences(10)
def wrap_log_message(rand, msg):
if rand.randint(1, 10) == 1:
block = {
'is_command': True,
'message': 'Step %s : %s' % (rand.randint(1, 10), msg)
}
else:
block = {
'message': msg,
}
return block
rnd = SystemRandom()
return jsonify({
'start': adv_start,
'end': adv_end,
'total': adv_total,
'logs': [wrap_log_message(rnd, sentence) for sentence in lorem_logs]
})
@api.route(BASE_BUILDING_URL + '/deadbeef-dead-beef-dead-beefdeadbeef/status',
methods=['GET'])
def get_fake_repo_build_status():
return jsonify(generate_fake_status())