def query_profiler(
    data_type,
    path,
    needle=None,
    verbose=False,
    ending=True,
    numeric=False,
    periods=True,
):
    """
    query_profiler(data_type, path, needle=None, verbose=False,
                      ending=True, numeric=False, periods=True,)

    needle:   Needle to search for in haystack. Returns T/F and ignores
              other conditions. Use path=[]
    verbose:  Ending parenthesis and their contents if they exist.
    ending:   Last word. "160 GB" => "160".
    numeric:  All non-numeric chars.
    periods:  All periods. Exclusive of numeric option.

    Returns the value at the end of a path of keys.
    Try: "SPStorageDataType",
    ["Macintosh HD", "Physical Volumes", "disk0s2", "Size"]
    Options for keeping / removing part of the string. True = keep,
    False = remove.
   """
    output = subprocess.Popen(
        ["system_profiler", data_type], stdout=subprocess.PIPE).communicate()[0]
    path_index = 0
    if needle:
        return True if needle in output else False
    for line in output.splitlines():
        if line.strip().startswith(path[path_index]):
            if path_index >= 1 - len(path):
                # Return only the value. Ignore "key: ".
                value = line.strip()[len(path[path_index]) + 2:]
                if not verbose:
                    # Chop off ending content in parenthesis if it exists.
                    if value[-1] == ")":
                        value = value[:value.find("(") - 1]
                if not ending:
                    # Chop off last word of value.
                    value = value.rsplit(" ", 1)[0]

                if not periods:
                    # Remove all periods.
                    value = re.sub(r"\.", "", value)
                elif numeric:
                    # Remove non-numeric chars.
                    value = re.sub(r"\D", "", value)
                return value
            else:
                path_index += 1
dataset/ETHPy150Open facebook/IT-CPE/code/lib/modules/sys_tools.py/query_profiler/swapped operands of `-`