#!/usr/bin/env python3

import os as _os
import shutil as _shutil
import argparse as _argparse


def file_copy(
	path_from,
	path_to
):
	_shutil.copyfile(path_from, path_to)


def file_remove(
	path
):
	_os.remove(path)


def shell_execute(
	command
):
	_os.system(command)
	


def main(
):
	## args
	
	argument_parser = _argparse.ArgumentParser()
	argument_parser.add_argument(
		"-t",
		"--include-tests",
		action = "store_true"
	)
	args = argument_parser.parse_args()
	
	
	## consts

	path_prj_core_from = "tools/heimdall-core.prj.json"
	path_prj_core_to = "heimdall-core.prj.json"
	path_prj_app_from = "tools/heimdall-app.prj.json"
	path_prj_app_to = "heimdall-app.prj.json"
	path_prj_test_from = "tools/heimdall-test.prj.json"
	path_prj_test_to = "heimdall-test.prj.json"


	## exec

	file_copy(path_prj_core_from, path_prj_core_to)
	file_copy(path_prj_app_from, path_prj_app_to)
	file_copy(path_prj_test_from, path_prj_test_to)
	
	shell_execute("tools/koralle --execute %s" % path_prj_app_to)
	shell_execute("chmod +r build/heimdall")
	if (not args.include_tests):
		pass
	else:
		shell_execute("koralle --execute %s" % path_prj_test_to)
	
	file_remove(path_prj_test_to)
	file_remove(path_prj_app_to)
	file_remove(path_prj_core_to)
	

main()
