Commit 42abf4ec authored by David Hendriks's avatar David Hendriks
Browse files

wrote help functionality and formatted the code

parent 929526e8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@
*** TODO Have the notebook with example on nbviewer 
** Features:
*** Help functionality
**** TODO Add help functionality to the module by calling the binary_c help api
**** DONE Add help functionality to the module by calling the binary_c help api
     CLOSED: [2019-12-16 Mon 00:20]

*** Floors Stroopwafel
**** TODO Implement the code that FLoor will provide 
+0 −2
Original line number Diff line number Diff line
def ding():
	print("ding")
+1 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import socket
import tempfile
import ctypes


def autogen_C_logging_code(logging_dict):
    """
    Function that autogenerates PRINTF statements for binaryc. intput is a dictionary where the key is the header of that logging line and items which are lists of parameters\
@@ -206,7 +207,6 @@ def return_compilation_dict(verbose=False):
    ]
    libs = "{} {}".format(" ".join(library_paths), " ".join(non_library_paths))


    if verbose:
        print(
            "Building shared library for custom logging with (binary_c.h) at {} on {}\n".format(
+55 −31
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ def create_arg_string(arg_dict):
    arg_string = arg_string.strip()
    return arg_string


def get_defaults():
    """
    Function that calls the binaryc get args function and cast it into a dictionary
@@ -42,7 +43,8 @@ def get_arg_keys():

    return get_defaults().keys()

def get_help(param_name, return_dict):

def get_help(param_name, return_dict=False):
    """
    Function that returns the help info for a given parameter. 

@@ -64,13 +66,21 @@ def get_help(param_name, return_dict):

    if param_name in available_arg_keys:
        help_info = binary_c_python_api.return_help(param_name)
        cleaned = [el for el in help_info.split('\n') if not el=='']
        cleaned = [el for el in help_info.split("\n") if not el == ""]

        # Get line numbers
        did_you_mean_nr = [i for i, el in enumerate(cleaned) if el.startswith('Did you mean')]
        parameter_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('binary_c help')]
        default_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('Default')]
        macros_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('Available')]
        did_you_mean_nr = [
            i for i, el in enumerate(cleaned) if el.startswith("Did you mean")
        ]
        parameter_line_nr = [
            i for i, el in enumerate(cleaned) if el.startswith("binary_c help")
        ]
        default_line_nr = [
            i for i, el in enumerate(cleaned) if el.startswith("Default")
        ]
        macros_line_nr = [
            i for i, el in enumerate(cleaned) if el.startswith("Available")
        ]

        help_info_dict = {}

@@ -78,30 +88,35 @@ def get_help(param_name, return_dict):
        if did_you_mean_nr:
            alternatives = cleaned[did_you_mean_nr[0] + 1 : parameter_line_nr[0]]
            alternatives = [el.strip() for el in alternatives]
            help_info_dict['alternatives'] = alternatives
            help_info_dict["alternatives"] = alternatives

        # Information about the parameter
        parameter_line = cleaned[parameter_line_nr[0]]
        parameter_name = parameter_line.split(":")[1].strip().split(' ')[0]
        parameter_value_input_type = ' '.join(parameter_line.split(":")[1].strip().split(' ')[1:]).replace('<', '').replace('>', '')
        parameter_name = parameter_line.split(":")[1].strip().split(" ")[0]
        parameter_value_input_type = (
            " ".join(parameter_line.split(":")[1].strip().split(" ")[1:])
            .replace("<", "")
            .replace(">", "")
        )

        help_info_dict['parameter_name'] = parameter_name
        help_info_dict['parameter_value_input_type'] = parameter_value_input_type
        help_info_dict["parameter_name"] = parameter_name
        help_info_dict["parameter_value_input_type"] = parameter_value_input_type

        description_line = ' '.join(cleaned[parameter_line_nr[0]+1 : default_line_nr[0]])
        help_info_dict['description'] = description_line
        description_line = " ".join(
            cleaned[parameter_line_nr[0] + 1 : default_line_nr[0]]
        )
        help_info_dict["description"] = description_line

        # Default:
        default_line = cleaned[default_line_nr[0]]
        default_value = default_line.split(':')[-1].strip()
        default_value = default_line.split(":")[-1].strip()

        help_info_dict['default'] = default_value
        help_info_dict["default"] = default_value

        # Get Macros:
        if macros_line_nr:
            macros = cleaned[macros_line_nr[0] + 1 :]
            help_info_dict['macros'] = macros

            help_info_dict["macros"] = macros

        for key in help_info_dict.keys():
            print("{}:\n\t{}".format(key, help_info_dict[key]))
@@ -110,9 +125,17 @@ def get_help(param_name, return_dict):
            return help_info_dict

    else:
        print("{} is not a valid parameter name. Please choose from the following parameters:\n\t{}".format(param_name, list(available_arg_keys)))
        print(
            "{} is not a valid parameter name. Please choose from the following parameters:\n\t{}".format(
                param_name, list(available_arg_keys)
            )
        )
        return None


get_help("RLOF_method")


def run_system(**kwargs):
    """
    Wrapper to run a system with settings 
@@ -197,11 +220,11 @@ def run_system_with_log(**kwargs):
    # print(arg_string)

    # Run it and get output
    buffer = ""
    output = binary_c_python_api.run_binary_with_logfile(arg_string)

    return output


def parse_output(output, selected_header):
    """
    Function that parses output of binary_c:
@@ -234,14 +257,16 @@ def parse_output(output, selected_header):
            if header == selected_header:
                # Check if the line contains '=' symbols:
                value_dict = {}
                if all('=' in el for el in values_list):
                if all("=" in el for el in values_list):
                    for el in values_list:
                        key, val = el.split("=")
                        value_dict[key.strip()] = val.strip()
                    value_dicts.append(value_dict)
                else:
                    if any('=' in el for el in values_list):
                        raise ValueError('Caught line contains some = symbols but not all of them do. aborting run')
                    if any("=" in el for el in values_list):
                        raise ValueError(
                            "Caught line contains some = symbols but not all of them do. aborting run"
                        )
                    else:
                        for i, val in enumerate(values_list):
                            value_dict[i] = val
@@ -264,9 +289,8 @@ def parse_output(output, selected_header):
    return final_values_dict



def load_logfile(logfile):
    with open(logfile, 'r') as f:
    with open(logfile, "r") as f:
        logfile_data = f.readlines()

    time_list = []
@@ -296,6 +320,6 @@ def load_logfile(logfile):
        ecc_list.append(split_line[6])
        rel_r1_list.append(split_line[7])
        rel_r2_list.append(split_line[8])
        event_list.append(' '.join(split_line[9:]))
        event_list.append(" ".join(split_line[9:]))

    print(event_list)
+15 −15
Original line number Diff line number Diff line
@@ -14,20 +14,20 @@ import os
import sys

# Include paths for python code
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../binarycpython'))
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../../binarycpython"))
# sys.path.insert(0, os.path.abspath('../../examples'))
sys.path.insert(0, os.path.abspath('../../binarycpython/utils'))
sys.path.insert(0, os.path.abspath("../../binarycpython/utils"))
sys.path.insert(0, os.path.join(os.getenv("BINARY_C"), "src/API/"))

# include paths for c code
cautodoc_root = os.path.abspath('../../')
cautodoc_root = os.path.abspath("../../")

# -- Project information -----------------------------------------------------

project = 'binary_c-python'
copyright = '2019, Jeff Andrews, Robert Izzard, David Hendriks'
author = 'Jeff Andrews, Robert Izzard, David Hendriks'
project = "binary_c-python"
copyright = "2019, Jeff Andrews, Robert Izzard, David Hendriks"
author = "Jeff Andrews, Robert Izzard, David Hendriks"


# -- General configuration ---------------------------------------------------
@@ -36,16 +36,16 @@ author = 'Jeff Andrews, Robert Izzard, David Hendriks'
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
	'sphinx.ext.autodoc',
	'sphinx.ext.doctest',
	'hawkmoth',
	'm2r',
    "sphinx.ext.autodoc",
    "sphinx.ext.doctest",
    "hawkmoth",
    "m2r",
]

source_suffix = ['.rst', '.md']
source_suffix = [".rst", ".md"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
@@ -58,9 +58,9 @@ exclude_patterns = []
# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
Loading