mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 16:01:20 +00:00 
			
		
		
		
	target: Add Target.pull(via_temp=False) parameter
Allow pulling a file via a temporary location on the target, to side-step performance issues when pulling big files from sysfs.
This commit is contained in:
		
				
					committed by
					
						
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							477e82c444
						
					
				
				
					commit
					b719808ef2
				
			@@ -649,7 +649,7 @@ class Target(object):
 | 
			
		||||
        return paths
 | 
			
		||||
 | 
			
		||||
    @call_conn
 | 
			
		||||
    def pull(self, source, dest, as_root=False, timeout=None, globbing=False):  # pylint: disable=arguments-differ
 | 
			
		||||
    def pull(self, source, dest, as_root=False, timeout=None, globbing=False, via_temp=False):  # pylint: disable=arguments-differ
 | 
			
		||||
        source = str(source)
 | 
			
		||||
        dest = str(dest)
 | 
			
		||||
 | 
			
		||||
@@ -658,17 +658,21 @@ class Target(object):
 | 
			
		||||
        else:
 | 
			
		||||
            sources = [source]
 | 
			
		||||
 | 
			
		||||
        # The SSH server might not have the right permissions to read the file,
 | 
			
		||||
        # so use a temporary copy instead.
 | 
			
		||||
        via_temp |= as_root
 | 
			
		||||
 | 
			
		||||
        mapping = self._prepare_xfer('pull', sources, dest, pattern=source if globbing else None, as_root=as_root)
 | 
			
		||||
 | 
			
		||||
        def do_pull(sources, dest):
 | 
			
		||||
            self.conn.pull(sources, dest, timeout=timeout)
 | 
			
		||||
 | 
			
		||||
        if as_root:
 | 
			
		||||
        if via_temp:
 | 
			
		||||
            for sources, dest in mapping.items():
 | 
			
		||||
                for source in sources:
 | 
			
		||||
                    with self._xfer_cache_path(source) as device_tempfile:
 | 
			
		||||
                        self.execute("cp -r -- {} {}".format(quote(source), quote(device_tempfile)), as_root=True)
 | 
			
		||||
                        self.execute("{} chmod 0644 -- {}".format(self.busybox, quote(device_tempfile)), as_root=True)
 | 
			
		||||
                        self.execute("cp -r -- {} {}".format(quote(source), quote(device_tempfile)), as_root=as_root)
 | 
			
		||||
                        self.execute("{} chmod 0644 -- {}".format(self.busybox, quote(device_tempfile)), as_root=as_root)
 | 
			
		||||
                        do_pull([device_tempfile], dest)
 | 
			
		||||
        else:
 | 
			
		||||
            for sources, dest in mapping.items():
 | 
			
		||||
 
 | 
			
		||||
@@ -249,7 +249,7 @@ Target
 | 
			
		||||
        matches, ``dest`` must be a folder (or will be created as such if it
 | 
			
		||||
        does not exists yet).
 | 
			
		||||
 | 
			
		||||
.. method:: Target.pull(source, dest [, as_root, timeout, globbing])
 | 
			
		||||
.. method:: Target.pull(source, dest [, as_root, timeout, globbing, via_temp])
 | 
			
		||||
 | 
			
		||||
   Transfer a file from the target device to the host machine.
 | 
			
		||||
 | 
			
		||||
@@ -267,6 +267,10 @@ Target
 | 
			
		||||
        pattern instead of being take as-is. If the pattern has multiple
 | 
			
		||||
        matches, ``dest`` must be a folder (or will be created as such if it
 | 
			
		||||
        does not exists yet).
 | 
			
		||||
   :param via_temp: If ``True``, copy the file first to a temporary location on
 | 
			
		||||
        the target, and then pull it. This can avoid issues some filesystems,
 | 
			
		||||
        notably paramiko + OpenSSH combination having performance issues when
 | 
			
		||||
        pulling big files from sysfs.
 | 
			
		||||
 | 
			
		||||
.. method:: Target.execute(command [, timeout [, check_exit_code [, as_root [, strip_colors [, will_succeed [, force_locale]]]]]])
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user