diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index f0a857d285f2e30a947962e05ce6159eeec27268..16b79ba6f62e89dce251217b16ee355ac2f8a107 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -185,13 +185,30 @@ def return_binary_c_version_info(parsed: bool = False) -> Union[str, dict]: Either the raw string of binary_c or a parsed version of this in the form of a nested dictionary """ + found_prev = False + if "BINARY_C_MACRO_HEADER" in os.environ: + # the envvar is already present. lets save that and put that back later + found_prev = True + prev_value = os.environ["BINARY_C_MACRO_HEADER"] + + # + os.environ["BINARY_C_MACRO_HEADER"] = "macroxyz" + + # Get version_info version_info = _binary_c_bindings.return_version_info().strip() + # parse if wanted if parsed: version_info = parse_binary_c_version_info(version_info) - return version_info + # delete value + del os.environ["BINARY_C_MACRO_HEADER"] + # put stuff back if we found a previous one + if found_prev: + os.environ["BINARY_C_MACRO_HEADER"] = prev_value + + return version_info def parse_binary_c_version_info(version_info_string: str) -> dict: """ @@ -376,10 +393,27 @@ def parse_binary_c_version_info(version_info_string: str) -> dict: # TODO: filter a bit more. misc_dict = {} + + # Filter out git revision git_revision = [el for el in cleaned if el.startswith("git revision")] misc_dict["git_revision"] = ( git_revision[0].split("git revision ")[-1].replace('"', "") ) + cleaned = cleaned - set(git_revision) + + # filter out git url + git_url = [el for el in cleaned if el.startswith("git URL")] + misc_dict["git_url"] = ( + git_url[0].split("git URL ")[-1].replace('"', "") + ) + cleaned = cleaned - set(git_url) + + # filter out version + version = [el for el in cleaned if el.startswith("Version")] + misc_dict["version"] = ( + str(version[0].split("Version ")[-1]) + ) + cleaned = cleaned - set(version) git_branch = [el for el in cleaned if el.startswith("git branch")] misc_dict["git_branch"] = git_branch[0].split("git branch ")[-1].replace('"', "") @@ -402,7 +436,7 @@ def parse_binary_c_version_info(version_info_string: str) -> dict: val = " is ".join(split[1:]).strip() misc_dict[key] = val - misc_dict["uncaught"] = "\n".join(cleaned) + misc_dict["uncaught"] = list(cleaned) version_info_dict["miscellaneous"] = misc_dict if misc_dict else None return version_info_dict