mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00:00 
			
		
		
		
	Merge pull request #31 from derkling/fix-newline-separator
fix: AdbConnection: added automatic detection of new line separators
This commit is contained in:
		@@ -198,7 +198,8 @@ class AdbConnection(object):
 | 
				
			|||||||
        return adb_command(self.device, command, timeout=timeout)
 | 
					        return adb_command(self.device, command, timeout=timeout)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def execute(self, command, timeout=None, check_exit_code=False, as_root=False):
 | 
					    def execute(self, command, timeout=None, check_exit_code=False, as_root=False):
 | 
				
			||||||
        return adb_shell(self.device, command, timeout, check_exit_code, as_root)
 | 
					        return adb_shell(self.device, command, timeout, check_exit_code,
 | 
				
			||||||
 | 
					                         as_root, self.newline_separator)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
 | 
					    def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
 | 
				
			||||||
        return adb_background_shell(self.device, command, stdout, stderr, as_root)
 | 
					        return adb_background_shell(self.device, command, stdout, stderr, as_root)
 | 
				
			||||||
@@ -305,7 +306,8 @@ def _ping(device):
 | 
				
			|||||||
        return False
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=False):  # NOQA
 | 
					def adb_shell(device, command, timeout=None, check_exit_code=False,
 | 
				
			||||||
 | 
					              as_root=False, newline_separator='\r\n'):  # NOQA
 | 
				
			||||||
    _check_env()
 | 
					    _check_env()
 | 
				
			||||||
    if as_root:
 | 
					    if as_root:
 | 
				
			||||||
        command = 'echo \'{}\' | su'.format(escape_single_quotes(command))
 | 
					        command = 'echo \'{}\' | su'.format(escape_single_quotes(command))
 | 
				
			||||||
@@ -319,9 +321,9 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=Fals
 | 
				
			|||||||
        raw_output, error = check_output(actual_command, timeout, shell=True)
 | 
					        raw_output, error = check_output(actual_command, timeout, shell=True)
 | 
				
			||||||
        if raw_output:
 | 
					        if raw_output:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                output, exit_code, _ = raw_output.rsplit(self.newline_separator, 2)
 | 
					                output, exit_code, _ = raw_output.rsplit(newline_separator, 2)
 | 
				
			||||||
            except ValueError:
 | 
					            except ValueError:
 | 
				
			||||||
                exit_code, _ = raw_output.rsplit(self.newline_separator, 1)
 | 
					                exit_code, _ = raw_output.rsplit(newline_separator, 1)
 | 
				
			||||||
                output = ''
 | 
					                output = ''
 | 
				
			||||||
        else:  # raw_output is empty
 | 
					        else:  # raw_output is empty
 | 
				
			||||||
            exit_code = '969696'  # just because
 | 
					            exit_code = '969696'  # just because
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user