def print_controllers(self, controllers, colored=False): if not controllers: print("Empty.") return for controller in controllers: if colored: print( color( self.controller_to_str(controller) + f" | {len(controller['ports'])} ports")) else: print( self.controller_to_str(controller) + f" | {len(controller['ports'])} ports") for port in controller["ports"]: if not colored: print(" " + self.port_to_str(port)) elif port["devices"]: print(" " + color(self.port_to_str(port)).green.bold) elif (self.get_controller_from_list( controller, self.controllers_historical) and [ i for i in self.get_controller_from_list( controller, self.controllers_historical)["ports"] if i["index"] == port["index"] ][0]["devices"]): print(" " + color(self.port_to_str(port)).cyan.bold) else: print(" " + self.port_to_str(port)) if port["comment"]: print(" " + port["comment"]) for device in port["devices"]: self.print_devices(device)
def select_ports(self): if not self.controllers_historical: utils.TUIMenu("Select Ports and Build Kext", "Select an option: ", in_between=["No ports! Use the discovery mode."], loop=True).start() return selection_index = 1 by_port = [] for controller in self.controllers_historical: controller["selected_count"] = 0 for port in controller["ports"]: if "selected" not in port: port["selected"] = bool(port["devices"]) port["selected"] = port["selected"] or ( bool(self.get_companion_port(port)["devices"]) if self.get_companion_port(port) else False) controller["selected_count"] += 1 if port["selected"] else 0 port["selection_index"] = selection_index selection_index += 1 by_port.append(port) while True: self.dump_historical() for controller in self.controllers_historical: controller["selected_count"] = sum( 1 if port["selected"] else 0 for port in controller["ports"]) utils.header("Select Ports and Build Kext") print() for controller in self.controllers_historical: port_count_str = f"{controller['selected_count']}/{len(controller['ports'])}" port_count_str = color(port_count_str).red if controller[ "selected_count"] > 15 else color(port_count_str).green print( self.controller_to_str(controller) + f" | {port_count_str} ports") for port in controller["ports"]: port_info = f"[{'#' if port['selected'] else ' '}] {port['selection_index']}.{(len(str(selection_index)) - len(str(port['selection_index'])) + 1) * ' ' }" + self.port_to_str( port) companion = self.get_companion_port(port) if companion: port_info += f" | Companion to {companion['selection_index']}" if port["selected"]: print(color(port_info).green.bold) else: print(port_info) if port["comment"]: print( len(f"[{'#' if port['selected'] else ' '}] {port['selection_index']}.{(len(str(selection_index)) - len(str(port['selection_index'])) + 1) * ' ' }" ) * " " + color(port["comment"]).blue.bold) for device in port["devices"]: self.print_devices(device, indentation=" " + len(str(selection_index)) * " " * 2) print() print( f"Binding companions is currently {color('on').green if self.settings['auto_bind_companions'] else color('off').red}.\n" ) print( textwrap.dedent(f"""\ K. Build {'USBMap' if self.settings['use_native'] else 'UTBMap'}.kext A. Select All N. Select None P. Enable All Populated Ports D. Disable All Empty Ports T. Show Types B. Back - Select ports to toggle with comma-delimited lists (eg. 1,2,3,4,5) - Change types using this formula T:1,2,3,4,5:t where t is the type - Set custom names using this formula C:1:Name - Name = None to clear""" )) output = input("Select an option: ") if not output: continue elif output.upper() == "B": break elif output.upper() == "K": if not self.validate_selections(): continue self.build_kext() continue elif output.upper() in ("N", "A"): for port in by_port: port["selected"] = output.upper() == "A" elif output.upper() == "P": for port in by_port: if port["devices"] or ( self.get_companion_port(port)["devices"] if self.get_companion_port(port) else False): port["selected"] = True elif output.upper() == "D": for port in by_port: if not port["devices"] and not ( self.get_companion_port(port)["devices"] if self.get_companion_port(port) else False): port["selected"] = False elif output.upper() == "T": self.print_types() continue elif output[0].upper() == "T": # We should have a type if len(output.split(":")) != 3: continue try: port_nums, port_type = output.split(":")[1:] port_nums = port_nums.replace(" ", "").split(",") port_type = shared.USBPhysicalPortTypes(int(port_type)) for port_num in list(port_nums): if port_num not in port_nums: continue port_num = int(port_num) - 1 if port_num not in range(len(by_port)): continue companion = self.get_companion_port(by_port[port_num]) if self.settings["auto_bind_companions"] and companion: companion["type"] = port_type if str(companion["selection_index"]) in port_nums: port_nums.remove( str(companion["selection_index"])) by_port[port_num]["type"] = port_type except ValueError: continue elif output[0].upper() == "C": # We should have a new name if len(output.split(":")) < 2: continue try: port_nums = output.split(":")[1].replace(" ", "").split(",") port_comment = output.split(":", 2)[2:] for port_num in list(port_nums): if port_num not in port_nums: continue port_num = int(port_num) - 1 if port_num not in range(len(by_port)): continue by_port[port_num]["comment"] = port_comment[ 0] if port_comment else None except ValueError: continue else: try: port_nums = output.replace(" ", "").split(",") for port_num in list(port_nums): if port_num not in port_nums: continue port_num = int(port_num) - 1 if port_num not in range(len(by_port)): continue companion = self.get_companion_port(by_port[port_num]) if self.settings["auto_bind_companions"] and companion: companion[ "selected"] = not by_port[port_num]["selected"] if str(companion["selection_index"]) in port_nums: port_nums.remove( str(companion["selection_index"])) by_port[port_num][ "selected"] = not by_port[port_num]["selected"] except ValueError: continue
else: print(plugin["Name"] + " by " + organization + " release " + release["name"] + " (" + release_date.isoformat() + ") not added") to_add.append({"plugin": plugin, "release": release}) # for i in to_add: addRelease(i) # Start setting up builder here. builder = builder.Builder() failed = [] succeeded = [] errored = [] print(color(f"\nBuilding {len(to_build)} things").bold) for plugin in to_build: print(f"\nBuilding {color(plugin['plugin']['Name']).bold}") try: started = datetime.datetime.now() files = None files = builder.build(plugin["plugin"], commithash=plugin["commit"]["sha"]) except Exception as error: duration = datetime.datetime.now() - started print("An error occurred!") print(error) traceback.print_tb(error.__traceback__) if files: print(f"Files: {files}") print(