1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00

Merge pull request #125 from avanlaer/pull_directory

Pull directory
This commit is contained in:
setrofim 2017-05-18 08:16:44 +01:00 committed by GitHub
commit 4a936da62f
2 changed files with 33 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import time
import logging
import posixpath
import subprocess
import tarfile
import tempfile
import threading
from collections import namedtuple
@ -281,6 +282,33 @@ class Target(object):
def pull(self, source, dest, timeout=None):
return self.conn.pull(source, dest, timeout=timeout)
def get_directory(self, source_dir, dest):
""" Pull a directory from the device, after compressing dir """
# Create all file names
tar_file_name = source_dir.lstrip(self.path.sep).replace(self.path.sep, '.')
# Host location of dir
outdir = os.path.join(dest, tar_file_name)
# Host location of archive
tar_file_name = '{}.tar'.format(tar_file_name)
tempfile = os.path.join(dest, tar_file_name)
# Does the folder exist?
self.execute('ls -la {}'.format(source_dir))
# Try compressing the folder
try:
self.execute('{} tar -cvf {} {}'.format(self.busybox, tar_file_name,
source_dir))
except TargetError:
self.logger.debug('Failed to run tar command on target! ' \
'Not pulling directory {}'.format(source_dir))
# Pull the file
os.mkdir(outdir)
self.pull(tar_file_name, tempfile )
# Decompress
f = tarfile.open(tempfile, 'r')
f.extractall(outdir)
os.remove(tempfile)
# execution
def execute(self, command, timeout=None, check_exit_code=True, as_root=False):

View File

@ -442,11 +442,14 @@ class Gem5Connection(TelnetConnection):
filename = os.path.basename(source)
logger.debug("pull_file {} {}".format(source, filename))
# writefile needs the file to be copied to be in the current working
# directory so if needed, copy to the working directory
# We don't check the exit code here because it is non-zero if the source
# and destination are the same. The ls below will cause an error if the
# file was not where we expected it to be.
if os.path.dirname(source) != os.getcwd():
self._gem5_shell("cat '{}' > '{}'".format(source, filename))
if os.path.isabs(source):
if os.path.dirname(source) != self.execute('pwd',check_exit_code=False):
self._gem5_shell("cat '{}' > '{}'".format(source, filename))
self._gem5_shell("sync")
self._gem5_shell("ls -la {}".format(filename))
logger.debug('Finished the copy in the simulator')