111 lines
2.6 KiB
Python
111 lines
2.6 KiB
Python
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)
|
|
|
|
return jsonify({
|
|
'start': adv_start,
|
|
'end': adv_end,
|
|
'total': adv_total,
|
|
'logs': [{'message': 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())
|