#!/usr/bin/env python3

import sys
import subprocess
import os

import binary_updaters


def debug(base_dir, branch_name):
    exe_path = os.path.join(binary_updaters.binary_dir(base_dir, branch_name), 'shardok', 'shardok-server')

    subprocess.run(['/usr/bin/gdbserver', ':12345', exe_path])

    return


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

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

shardok_artifact_name = 'shardok.tar.gz'
shardok_base_dir = 'shardok'

binary_updaters.update(base_dir=shardok_base_dir,
                       artifact_name=shardok_artifact_name,
                       branch_name=selected_branch_name)

debug(base_dir=shardok_base_dir, branch_name=selected_branch_name)
