From 8b9f6448db63487cbf2a87a73a35acb642d49cf0 Mon Sep 17 00:00:00 2001 From: Daniel Van Der Maden Date: Thu, 26 Dec 2019 23:07:47 -0800 Subject: [PATCH] [util] Change cli download location to a bin dir within cwd. --- pyhmy/util.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pyhmy/util.py b/pyhmy/util.py index d0ccf66..354edc5 100644 --- a/pyhmy/util.py +++ b/pyhmy/util.py @@ -54,7 +54,7 @@ def get_bls_build_variables(): hmy_path = f"{get_gopath()}/src/github.com/harmony-one" bls_dir = f"{hmy_path}/bls" mcl_dir = f"{hmy_path}/mcl" - assert os.path.exists(bls_dir), f" Harmony BLS repo not found at {bls_dir}" + assert os.path.exists(bls_dir), f"Harmony BLS repo not found at {bls_dir}" assert os.path.exists(mcl_dir), f"Harmony MCL repo not found at {mcl_dir}" if sys.platform.startswith("darwin"): variables["CGO_CFLAGS"] = f"-I{bls_dir}/include -I{mcl_dir}/include -I{openssl_dir}/include" @@ -68,19 +68,23 @@ def get_bls_build_variables(): return variables -def download_cli(bin_name="hmy", replace=False): +def download_cli(bin_name="hmy", replace=False, verbose=True): """ - This function will download the statically linked CLI binary to the current - working directory. + This function will download the statically linked CLI binary into a bin directory + within the current working directory. :param bin_name: The desired filename of the binary :param replace: A flag to force a replacement of the binary/file. + :param verbose: A flag to enable a report message once the binary is downloaded. """ assert isinstance(bin_name, str), "binary name must be a string" assert bin_name, "binary name must be non-empty" assert '/' not in bin_name, "binary name must not be path" - if os.path.exists(f"{os.getcwd()}/{bin_name}") and not replace: + if os.path.exists(f"{os.getcwd()}/bin/{bin_name}") and not replace: return + old_cwd = os.getcwd() + os.makedirs(f"{old_cwd}/bin", exist_ok=True) + os.chdir(f"{old_cwd}/bin") hmy_script_path = f"{os.getcwd()}/hmy.sh" with open(hmy_script_path, 'w') as f: f.write(requests.get("https://raw.githubusercontent.com/harmony-one/go-sdk/master/scripts/hmy.sh") @@ -92,6 +96,9 @@ def download_cli(bin_name="hmy", replace=False): os.rename(f"{os.getcwd()}/hmy", f"{os.getcwd()}/{bin_name}") if os.path.exists(f"{os.getcwd()}/.hmy_temp"): os.rename(f"{os.getcwd()}/.hmy_temp", f"{os.getcwd()}/hmy") + if verbose: + print(f"Saved harmony binary to: {os.getcwd()}/{bin_name}") + os.chdir(old_cwd) def json_load(string):