Exemplo n.º 1
0
def _compile_quali_ai(gt):
	lang = None
	for lname in env.quali_lang_hierarchy:
		lang = Lang.query.filter(Lang.name == lname).first()
		if lang:
			break
	if not lang:
		lang = Lang.query.first()
	ai = QualiAI(gt, lang)
	ai.copy_example_code()
	for data, event in backend.compile(ai):
		print(event, ":", data)
Exemplo n.º 2
0
	def recompile_ais():
		"Kompiliert KIs"
		if prompt_bool("Quali KIs rekompilieren"):
			for gt in GameType.query.all():
				_compile_quali_ai(gt)
		all = prompt_bool("Compile all?")
		for ai in AI.query.all():
			if all or prompt_bool("Compile '"+ai.name + "' by " + ai.user.name):
				ai.latest_version().compiled = True
				print("Compiling", ai.name)
				for data, event in backend.compile(ai):
					print(event, ":", data)
		db.session.commit()
Exemplo n.º 3
0
def api_ai_compile(id):
    ai = AI.query.get(id)
    if not ai:
        return (CommonErrors.INVALID_ID[0]["error"], "error")
    if not current_user.can_access(ai):
        return (CommonErrors.NO_ACCESS[0]["error"], "error")

    if ai.latest_version().frozen:
        return {"error": "AI_Version is frozen"}, 400
    ai.latest_version().compiled = True
    ai.latest_version().qualified = False
    db.session.commit()

    yield from backend.compile(ai)
Exemplo n.º 4
0
 def recompile_ais():
     "Kompiliert KIs"
     if prompt_bool("Quali KIs rekompilieren"):
         for gt in GameType.query.all():
             _compile_quali_ai(gt)
     all = prompt_bool("Compile all?")
     for ai in AI.query.all():
         if all or prompt_bool("Compile '" + ai.name + "' by " +
                               ai.user.name):
             ai.latest_version().compiled = True
             print("Compiling", ai.name)
             for data, event in backend.compile(ai):
                 print(event, ":", data)
     db.session.commit()
Exemplo n.º 5
0
def api_ai_compile(id):
	ai = AI.query.get(id)
	if not ai:
		return (CommonErrors.INVALID_ID[0]["error"], "error")
	if not current_user.can_access(ai):
		return (CommonErrors.NO_ACCESS[0]["error"], "error")

	if ai.latest_version().frozen:
		return ("AI_Version is frozen", "error")
	ai.latest_version().compiled = True
	ai.latest_version().qualified = False
	db.session.commit()

	yield from backend.compile(ai)
Exemplo n.º 6
0
def api_ai_compile_blocking(id):
    ai = AI.query.get(id)
    if not ai:
        return (CommonErrors.INVALID_ID[0]["error"], "error")
    if not current_user.can_access(ai):
        return (CommonErrors.NO_ACCESS[0]["error"], "error")

    if ai.latest_version().frozen:
        return {"error": "AI_Version is frozen"}, 400
    ai.latest_version().compiled = True
    ai.latest_version().qualified = False
    db.session.commit()

    compile_log = ""

    for data, event in backend.compile(ai):
        if event == "log":
            compile_log += data
        if event == "error":
            return {"error": data, "compilelog": compile_log}

    return {"error": None, "compilelog": compile_log}, 200
Exemplo n.º 7
0
def api_ai_compile_blocking(id):
	ai = AI.query.get(id)
	if not ai:
		return CommonErrors.INVALID_ID
	if not current_user.can_access(ai):
		return CommonErrors.NO_ACCESS

	if ai.latest_version().frozen:
		return {"error": "AI_Version is frozen"}, 400
	ai.latest_version().compiled = True
	ai.latest_version().qualified = False
	db.session.commit()

	compile_log = ""

	for data, event in backend.compile(ai):
		if event == "log":
			compile_log += data
		if event == "error":
			return {"error": data, "compilelog": compile_log}, 200

	return {"error": None, "compilelog": compile_log}, 200
Exemplo n.º 8
0
def _compile_quali_ai(gt):
	ai = Mock()
	ai.id = -gt.id
	lang = next(filter(None, [
		Lang.query.filter(Lang.name == "Go").first(),
		Lang.query.filter(Lang.name == "Python").first(),
		Lang.query.filter(Lang.name == "Java").first(),
		Lang.query.first()
	]))
	ai.lang = lang
	ai.type = gt
	ai.name = "QualiKi-"+gt.name
	v = ai.latest_version()
	v.version_id = 1
	v.lang = ai.lang
	v.qualified, v.compiled, v.frozen = False, False, False
	v.extras.return_value = []
	ai.version_list = [v]
	ai.ftp_sync = lambda: AI.ftp_sync(ai)
	ai.copy_example_code = lambda: AI.copy_example_code(ai)
	ai.copy_example_code()
	for data, event in backend.compile(ai):
		print(event, ":", data)
Exemplo n.º 9
0
def _compile_quali_ai(gt):
    ai = Mock()
    ai.id = -gt.id
    lang = next(
        filter(None, [
            Lang.query.filter(Lang.name == "Go").first(),
            Lang.query.filter(Lang.name == "Python").first(),
            Lang.query.filter(Lang.name == "Java").first(),
            Lang.query.first()
        ]))
    ai.lang = lang
    ai.type = gt
    ai.name = "QualiKi-" + gt.name
    v = ai.latest_version()
    v.version_id = 1
    v.lang = ai.lang
    v.qualified, v.compiled, v.frozen = False, False, False
    v.extras.return_value = []
    ai.version_list = [v]
    ai.ftp_sync = lambda: AI.ftp_sync(ai)
    ai.copy_example_code = lambda: AI.copy_example_code(ai)
    ai.copy_example_code()
    for data, event in backend.compile(ai):
        print(event, ":", data)