@@ -595,28 +595,23 @@ def search_device(platform: str, bin_path: Path) -> SearchResult:
595595 try :
596596 # read device code
597597 if platform in ("linux" , "darwin" ):
598- # check if grep is installed and find the right path
599- try :
600- grep_command = check_output (["which" , "grep" ]).decode ().strip ()
601- except CalledProcessError :
602- logger .error (
603- "Failed to detect a device. Please make sure `grep` is installed."
604- )
605- return SearchResult (
606- msg = "Failed to detect a device. Please make sure `grep` is installed."
607- )
608598 # run the command to get the device code
609- output = check_output (
610- [
611- str (bin_path .joinpath (Path ("adb" ))),
612- "shell" ,
613- "getprop" ,
614- "|" ,
615- grep_command ,
616- "ro.product.device" ,
617- ],
599+ command = [
600+ str (bin_path .joinpath (Path ("adb" ))),
601+ "shell" ,
602+ "getprop" ,
603+ # "|",
604+ # "grep",
605+ # "ro.product.device",
606+ ]
607+ logger .info (f"Run command: { command } " )
608+ device_prop = check_output (
609+ command ,
618610 stderr = STDOUT ,
619611 ).decode ()
612+ output = [
613+ line for line in device_prop .split ("\n " ) if "ro.product.device" in line
614+ ][0 ]
620615 elif platform in ("windows" , "win32" ):
621616 # run the command to get the device code on windows
622617 output = check_output (
@@ -639,8 +634,8 @@ def search_device(platform: str, bin_path: Path) -> SearchResult:
639634 device_code = device_code ,
640635 msg = f"Found device with device code '{ device_code } '." ,
641636 )
642- except CalledProcessError :
643- logger .error ("Failed to detect a device." )
637+ except CalledProcessError as e :
638+ logger .error (f "Failed to detect a device. { e } " )
644639 return SearchResult (
645640 msg = "Failed to detect a device. Connect to USB and try again."
646641 )
0 commit comments