From 48df5fbbd200e35f51d81846428271edf386fbcd Mon Sep 17 00:00:00 2001 From: isa Date: Tue, 13 Feb 2024 16:07:59 -0500 Subject: [PATCH] Commit the working code --- bisdef.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 bisdef.py diff --git a/bisdef.py b/bisdef.py new file mode 100644 index 0000000..0e6b46d --- /dev/null +++ b/bisdef.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +import sys, os, math, linecache, re + +# change numerator and denominator variables progressively to perform a proper bissection search manually +numerator = 1 +denominator = 2 + +defconfig_file_name = "defconfig_clean" + +def usage(): + print("""Usage: bissect_conf [ ] + +Will output a defconfig file with the changes detected from the comparison_file to the config_in file +Example usage: + $ bissect_conf comparison_file defconfig_not_working +""") + sys.exit(0) + +def main(): + global merge_style + outup_f = open("defconfig", "w") + + + # parse command line args + if ("-h" in sys.argv or "--help" in sys.argv): + usage() + + compare_file = open("compare.defconfig") + compare_file_data = compare_file.readlines() + compare_file_num = len(compare_file_data) + + defconfig_file = open(defconfig_file_name) + defconfig_data = defconfig_file.readlines() + + # split into number of chunks equal to denominator + denomi_lines = math.ceil(compare_file_num/denominator) + + for i in range(denomi_lines*(numerator-1), denomi_lines*(numerator)): # first line is at 1 + compare_file_line = compare_file_data[i] + +############################################################################################################## + # the comparison file describes a change which starts with a "-" + if compare_file_line.startswith("-"): + compare_file_line = compare_file_line[1:] + current_config_name = "CONFIG_" + compare_file_line.split(" ")[0] + + # cycle through entire defconfig file and search for config_name + for j in range(0, len(defconfig_data)): + if current_config_name+" " in defconfig_data[j] or current_config_name+"=" in defconfig_data[j]: + defconfig_data[j] = current_config_name+"="+compare_file_line.split(" ")[1] + + if j == len(defconfig_data) - 1: + defconfig_data.append(current_config_name+"="+compare_file_line.split(" ")[1]) + +############################################################################################################## + # the comparison file describes a change which starts with a "+" + elif compare_file_line.startswith("+"): + compare_file_line = compare_file_line[1:] + current_config_name = "CONFIG_" + compare_file_line.split(" ")[0] + #current_config_name = current_config_name.strip() + + # cycle through entire defconfig file and search for config_name + for j in range(0, len(defconfig_data)): + if current_config_name in defconfig_data[j]: + defconfig_data[j] = "" + +############################################################################################################## + else: + current_config_name = "CONFIG_" + compare_file_line.split(" ")[1] + print(compare_file_line) + for j in range(0, len(defconfig_data)): + if current_config_name+" " in defconfig_data[j] or current_config_name+"=" in defconfig_data[j]: + defconfig_data[j] = current_config_name+"="+compare_file_line.split(" ")[2]+"\n" + + outup_f.writelines(defconfig_data) + +main() \ No newline at end of file