diff options
author | Alexandru N. Onea <onea.alex@gmail.com> | 2020-06-23 12:00:49 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-06-25 10:24:02 +0100 |
commit | cb1fbec4d95e9cbb36ec84c605981444eeb81dd4 (patch) | |
tree | 8441d3f2c06947c041b0c1c025ef222bfd5b96ee /bitbake/lib | |
parent | 3bd3b51367e4f05e7b7efa7dbf71646ea137e094 (diff) | |
download | poky-cb1fbec4d95e9cbb36ec84c605981444eeb81dd4.tar.gz |
bitbake: perforce: add basic progress handler for perforce
This patch adds a basic implementation of a progress handler for the
perforce fetcher, based on the number of files to be downloaded and the
output behavior of the p4 print command used in the fetcher
implementation.
(Bitbake rev: f0582292bf79b0988048683dfd086aa3b9787344)
Signed-off-by: Alexandru N. Onea <onea.alex@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/fetch2/perforce.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py index f57c2a4f52..83128cdeba 100644 --- a/bitbake/lib/bb/fetch2/perforce.py +++ b/bitbake/lib/bb/fetch2/perforce.py | |||
@@ -17,6 +17,36 @@ from bb.fetch2 import FetchError | |||
17 | from bb.fetch2 import logger | 17 | from bb.fetch2 import logger |
18 | from bb.fetch2 import runfetchcmd | 18 | from bb.fetch2 import runfetchcmd |
19 | 19 | ||
20 | class PerforceProgressHandler (bb.progress.BasicProgressHandler): | ||
21 | """ | ||
22 | Implements basic progress information for perforce, based on the number of | ||
23 | files to be downloaded. | ||
24 | |||
25 | The p4 print command will print one line per file, therefore it can be used | ||
26 | to "count" the number of files already completed and give an indication of | ||
27 | the progress. | ||
28 | """ | ||
29 | def __init__(self, d, num_files): | ||
30 | self._num_files = num_files | ||
31 | self._count = 0 | ||
32 | super(PerforceProgressHandler, self).__init__(d) | ||
33 | |||
34 | # Send an initial progress event so the bar gets shown | ||
35 | self._fire_progress(-1) | ||
36 | |||
37 | def write(self, string): | ||
38 | self._count = self._count + 1 | ||
39 | |||
40 | percent = int(100.0 * float(self._count) / float(self._num_files)) | ||
41 | |||
42 | # In case something goes wrong, we try to preserve our sanity | ||
43 | if percent > 100: | ||
44 | percent = 100 | ||
45 | |||
46 | self.update(percent) | ||
47 | |||
48 | super(PerforceProgressHandler, self).write(string) | ||
49 | |||
20 | class Perforce(FetchMethod): | 50 | class Perforce(FetchMethod): |
21 | """ Class to fetch from perforce repositories """ | 51 | """ Class to fetch from perforce repositories """ |
22 | def supports(self, ud, d): | 52 | def supports(self, ud, d): |
@@ -150,10 +180,12 @@ class Perforce(FetchMethod): | |||
150 | bb.utils.remove(ud.pkgdir, True) | 180 | bb.utils.remove(ud.pkgdir, True) |
151 | bb.utils.mkdirhier(ud.pkgdir) | 181 | bb.utils.mkdirhier(ud.pkgdir) |
152 | 182 | ||
183 | progresshandler = PerforceProgressHandler(d, len(filelist)) | ||
184 | |||
153 | for afile in filelist: | 185 | for afile in filelist: |
154 | p4fetchcmd = self._buildp4command(ud, d, 'print', afile) | 186 | p4fetchcmd = self._buildp4command(ud, d, 'print', afile) |
155 | bb.fetch2.check_network_access(d, p4fetchcmd, ud.url) | 187 | bb.fetch2.check_network_access(d, p4fetchcmd, ud.url) |
156 | runfetchcmd(p4fetchcmd, d, workdir=ud.pkgdir) | 188 | runfetchcmd(p4fetchcmd, d, workdir=ud.pkgdir, log=progresshandler) |
157 | 189 | ||
158 | runfetchcmd('tar -czf %s p4' % (ud.localpath), d, cleanup=[ud.localpath], workdir=ud.pkgdir) | 190 | runfetchcmd('tar -czf %s p4' % (ud.localpath), d, cleanup=[ud.localpath], workdir=ud.pkgdir) |
159 | 191 | ||