diff options
| author | Przemyslaw Gorszkowski <przemek.gorszkowski@redembedded.com> | 2021-04-26 10:19:21 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-05-01 22:51:06 +0100 |
| commit | 6da327c788b5fc2f50897771eeb82de1cc08e4e7 (patch) | |
| tree | 7215705dca02d1a91535b884fef35b57a7049362 /bitbake/lib/bb/fetch2 | |
| parent | a854068b525877583bbd9c6a32a8dffaf18cb2b5 (diff) | |
| download | poky-6da327c788b5fc2f50897771eeb82de1cc08e4e7.tar.gz | |
bitbake: fetch/s3: Add progress handler for S3 cp command
Adds progress support for fetchers from S3.
(Bitbake rev: 90d31b2d5a81e5f41fe95907c78fd2f5f36e39ee)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2')
| -rw-r--r-- | bitbake/lib/bb/fetch2/s3.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/s3.py b/bitbake/lib/bb/fetch2/s3.py index ffca73c8e4..6b8ffd5359 100644 --- a/bitbake/lib/bb/fetch2/s3.py +++ b/bitbake/lib/bb/fetch2/s3.py | |||
| @@ -18,10 +18,47 @@ The aws tool must be correctly installed and configured prior to use. | |||
| 18 | import os | 18 | import os |
| 19 | import bb | 19 | import bb |
| 20 | import urllib.request, urllib.parse, urllib.error | 20 | import urllib.request, urllib.parse, urllib.error |
| 21 | import re | ||
| 21 | from bb.fetch2 import FetchMethod | 22 | from bb.fetch2 import FetchMethod |
| 22 | from bb.fetch2 import FetchError | 23 | from bb.fetch2 import FetchError |
| 23 | from bb.fetch2 import runfetchcmd | 24 | from bb.fetch2 import runfetchcmd |
| 24 | 25 | ||
| 26 | def convertToBytes(value, unit): | ||
| 27 | value = float(value) | ||
| 28 | if (unit == "KiB"): | ||
| 29 | value = value*1024.0; | ||
| 30 | elif (unit == "MiB"): | ||
| 31 | value = value*1024.0*1024.0; | ||
| 32 | elif (unit == "GiB"): | ||
| 33 | value = value*1024.0*1024.0*1024.0; | ||
| 34 | return value | ||
| 35 | |||
| 36 | class S3ProgressHandler(bb.progress.LineFilterProgressHandler): | ||
| 37 | """ | ||
| 38 | Extract progress information from s3 cp output, e.g.: | ||
| 39 | Completed 5.1 KiB/8.8 GiB (12.0 MiB/s) with 1 file(s) remaining | ||
| 40 | """ | ||
| 41 | def __init__(self, d): | ||
| 42 | super(S3ProgressHandler, self).__init__(d) | ||
| 43 | # Send an initial progress event so the bar gets shown | ||
| 44 | self._fire_progress(0) | ||
| 45 | |||
| 46 | def writeline(self, line): | ||
| 47 | percs = re.findall(r'^Completed (\d+.{0,1}\d*) (\w+)\/(\d+.{0,1}\d*) (\w+) (\(.+\)) with\s+', line) | ||
| 48 | if percs: | ||
| 49 | completed = (percs[-1][0]) | ||
| 50 | completedUnit = (percs[-1][1]) | ||
| 51 | total = (percs[-1][2]) | ||
| 52 | totalUnit = (percs[-1][3]) | ||
| 53 | completed = convertToBytes(completed, completedUnit) | ||
| 54 | total = convertToBytes(total, totalUnit) | ||
| 55 | progress = (completed/total)*100.0 | ||
| 56 | rate = percs[-1][4] | ||
| 57 | self.update(progress, rate) | ||
| 58 | return False | ||
| 59 | return True | ||
| 60 | |||
| 61 | |||
| 25 | class S3(FetchMethod): | 62 | class S3(FetchMethod): |
| 26 | """Class to fetch urls via 'aws s3'""" | 63 | """Class to fetch urls via 'aws s3'""" |
| 27 | 64 | ||
| @@ -52,7 +89,9 @@ class S3(FetchMethod): | |||
| 52 | 89 | ||
| 53 | cmd = '%s cp s3://%s%s %s' % (ud.basecmd, ud.host, ud.path, ud.localpath) | 90 | cmd = '%s cp s3://%s%s %s' % (ud.basecmd, ud.host, ud.path, ud.localpath) |
| 54 | bb.fetch2.check_network_access(d, cmd, ud.url) | 91 | bb.fetch2.check_network_access(d, cmd, ud.url) |
| 55 | runfetchcmd(cmd, d) | 92 | |
| 93 | progresshandler = S3ProgressHandler(d) | ||
| 94 | runfetchcmd(cmd, d, False, log=progresshandler) | ||
| 56 | 95 | ||
| 57 | # Additional sanity checks copied from the wget class (although there | 96 | # Additional sanity checks copied from the wget class (although there |
| 58 | # are no known issues which mean these are required, treat the aws cli | 97 | # are no known issues which mean these are required, treat the aws cli |
