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