#!/usr/bin/env python3

import os
import subprocess
import sys

import binary_updaters


def debug(base_dir, branch_name):
    exe_path = os.path.join(binary_updaters.binary_dir(base_dir, branch_name),
                            'eagle',
                            'eagle_server_deploy.jar')

    subprocess.run(['java',
                    '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005',
                    '-jar',
                    exe_path])

    return


selected_branch_name = 'main'
if len(sys.argv) > 1:
    selected_branch_name = sys.argv[1]

print(f"Running eagle from branch {selected_branch_name}")

eagle_artifact_name = 'eagle_servers.tar.gz'
eagle_base_dir = 'eagle'

binary_updaters.update(base_dir=eagle_base_dir,
                       artifact_name=eagle_artifact_name,
                       branch_name=selected_branch_name)

debug(base_dir=eagle_base_dir, branch_name=selected_branch_name)
