Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | # Copyright (C) 2016 Intel Corporation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | |
| 7 | from oeqa.utils.buildproject import BuildProject |
| 8 | |
| 9 | class TargetBuildProject(BuildProject): |
| 10 | |
| 11 | def __init__(self, target, uri, foldername=None, dl_dir=None): |
| 12 | self.target = target |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 13 | self.targetdir = "~/buildtest/" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | BuildProject.__init__(self, uri, foldername, dl_dir=dl_dir) |
| 15 | |
| 16 | def download_archive(self): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 17 | self.target.run("mkdir " + self.targetdir + " || true") |
| 18 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | self._download_archive() |
| 20 | |
| 21 | status, output = self.target.copyTo(self.localarchive, self.targetdir) |
| 22 | if status: |
| 23 | raise Exception('Failed to copy archive to target, ' |
| 24 | 'output: %s' % output) |
| 25 | |
| 26 | cmd = 'tar xf %s%s -C %s' % (self.targetdir, |
| 27 | self.archive, |
| 28 | self.targetdir) |
| 29 | status, output = self.target.run(cmd) |
| 30 | if status: |
| 31 | raise Exception('Failed to extract archive, ' |
| 32 | 'output: %s' % output) |
| 33 | |
| 34 | # Change targetdir to project folder |
| 35 | self.targetdir = self.targetdir + self.fname |
| 36 | |
| 37 | # The timeout parameter of target.run is set to 0 |
| 38 | # to make the ssh command run with no timeout. |
| 39 | def _run(self, cmd): |
| 40 | ret = self.target.run(cmd, 0) |
| 41 | msg = "Command %s failed with exit code %s: %s" % (cmd, ret[0], ret[1]) |
| 42 | if ret[0] != 0: |
| 43 | raise Exception(msg) |
| 44 | return ret[0] |