From adedad8e32139f15a705ce67d96047db47f4ef39 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Fri, 27 Jan 2017 19:31:44 +0000 Subject: [PATCH 1/4] doc/connection: Fix missing word --- doc/connection.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/connection.rst b/doc/connection.rst index 888f626..25953e5 100644 --- a/doc/connection.rst +++ b/doc/connection.rst @@ -25,7 +25,7 @@ class that implements the following methods. Transfer a file from the host machine to the connected device. :param source: path of to the file on the host - :param dest: path of to the file on the connected + :param dest: path of to the file on the connected device. :param timeout: timeout (in seconds) for the transfer; if the transfer does not complete within this period, an exception will be raised. From 1cb4eb2285b270229c6a3637fc60bd52f5d6309b Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Fri, 27 Jan 2017 19:32:11 +0000 Subject: [PATCH 2/4] doc/connection: Document the fact that `pull` supports globs This feature is supported implicitly by SshConnection and explicitly by AdbConnection. A subsequent commit implements it for LocalConnection. --- doc/connection.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/connection.rst b/doc/connection.rst index 25953e5..1fd2fb5 100644 --- a/doc/connection.rst +++ b/doc/connection.rst @@ -31,9 +31,11 @@ class that implements the following methods. .. method:: pull(self, source, dest, timeout=None) - Transfer a file from the connected device to the host machine. + Transfer a file, or files matching a glob pattern, from the connected device + to the host machine. - :param source: path of to the file on the connected device + :param source: path of to the file on the connected device. If ``dest`` is a + directory, may be a glob pattern. :param dest: path of to the file on the host :param timeout: timeout (in seconds) for the transfer; if the transfer does not complete within this period, an exception will be raised. From b587049eb99e964aa9337e307333d5929954a979 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Fri, 27 Jan 2017 19:33:43 +0000 Subject: [PATCH 3/4] LocalConnection: Support glob patterns in pull --- devlib/host.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devlib/host.py b/devlib/host.py index d830a5e..510de44 100644 --- a/devlib/host.py +++ b/devlib/host.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from glob import iglob import os import shutil import subprocess @@ -41,7 +42,12 @@ class LocalConnection(object): def pull(self, source, dest, timeout=None, as_root=False): # pylint: disable=unused-argument self.logger.debug('cp {} {}'.format(source, dest)) - shutil.copy(source, dest) + if ('*' in source or '?' in source) and os.path.isdir(dest): + # Pull all files matching a wildcard expression + for each_source in iglob(source): + shutil.copy(each_source, dest) + else: + shutil.copy(source, dest) def execute(self, command, timeout=None, check_exit_code=True, as_root=False): self.logger.debug(command) From 179e45f98e8e227380eb9ab90b4abb3d8d9be839 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 31 Jan 2017 19:21:11 +0000 Subject: [PATCH 4/4] LocalConnection: Enrich TargetError message from execute method Add exit code, command, and output to TargetError exception message when execute fails. This brings LocalConnection into line with AdbConnection and SshConnection. --- devlib/host.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devlib/host.py b/devlib/host.py index 510de44..121e5b4 100644 --- a/devlib/host.py +++ b/devlib/host.py @@ -60,7 +60,9 @@ class LocalConnection(object): try: return check_output(command, shell=True, timeout=timeout, ignore=ignore)[0] except subprocess.CalledProcessError as e: - raise TargetError(e) + message = 'Got exit code {}\nfrom: {}\nOUTPUT: {}'.format( + e.returncode, command, e.output) + raise TargetError(message) def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False): if as_root: