summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-07-06 16:26:10 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-19 15:04:37 +0100
commit45baa90c8cb0f5e92e6a2847d84312b52b0582a2 (patch)
tree1264d6664a4d8fc710838237c3e842ff54fd1c76 /bitbake/lib/bb/fetch2/git.py
parent843f7ae4108ad862b02ae84eef4f8cf7f6a3c950 (diff)
downloadpoky-45baa90c8cb0f5e92e6a2847d84312b52b0582a2.tar.gz
bitbake: fetch2: implement progress support
Implement progress reporting support specifically for the fetchers. For fetch tasks we don't necessarily know which fetcher will be used (we might initially be fetching a git:// URI, but if we instead download a mirror tarball we may fetch that over http using wget). These programs also have different abilities as far as reporting progress goes (e.g. wget gives us percentage complete and rate, git gives this some of the time depending on what stage it's at). Additionally we filter out the progress output before it makes it to the logs, in order to prevent the logs filling up with junk. At the moment this is only implemented for the wget and git fetchers since they are the most commonly used (and svn doesn't seem to support any kind of progress output, at least not without doing a relatively expensive remote file listing first). Line changes such as the ones you get in git's output as it progresses don't make it to the log files, you only get the final state of the line so the logs aren't filled with progress information that's useless after the fact. Part of the implementation for [YOCTO #5383]. (Bitbake rev: 4027649f422ee64b1c4e1ad8d48ac295050afbff) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r--bitbake/lib/bb/fetch2/git.py52
1 files changed, 48 insertions, 4 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 59827e304f..4e2dcec0d7 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -71,11 +71,53 @@ import os
71import re 71import re
72import bb 72import bb
73import errno 73import errno
74import bb.progress
74from bb import data 75from bb import data
75from bb.fetch2 import FetchMethod 76from bb.fetch2 import FetchMethod
76from bb.fetch2 import runfetchcmd 77from bb.fetch2 import runfetchcmd
77from bb.fetch2 import logger 78from bb.fetch2 import logger
78 79
80
81class GitProgressHandler(bb.progress.LineFilterProgressHandler):
82 """Extract progress information from git output"""
83 def __init__(self, d):
84 self._buffer = ''
85 self._count = 0
86 super(GitProgressHandler, self).__init__(d)
87 # Send an initial progress event so the bar gets shown
88 self._fire_progress(-1)
89
90 def write(self, string):
91 self._buffer += string
92 stages = ['Counting objects', 'Compressing objects', 'Receiving objects', 'Resolving deltas']
93 stage_weights = [0.2, 0.05, 0.5, 0.25]
94 stagenum = 0
95 for i, stage in reversed(list(enumerate(stages))):
96 if stage in self._buffer:
97 stagenum = i
98 self._buffer = ''
99 break
100 self._status = stages[stagenum]
101 percs = re.findall(r'(\d+)%', string)
102 if percs:
103 progress = int(round((int(percs[-1]) * stage_weights[stagenum]) + (sum(stage_weights[:stagenum]) * 100)))
104 rates = re.findall(r'([\d.]+ [a-zA-Z]*/s+)', string)
105 if rates:
106 rate = rates[-1]
107 else:
108 rate = None
109 self.update(progress, rate)
110 else:
111 if stagenum == 0:
112 percs = re.findall(r': (\d+)', string)
113 if percs:
114 count = int(percs[-1])
115 if count > self._count:
116 self._count = count
117 self._fire_progress(-count)
118 super(GitProgressHandler, self).write(string)
119
120
79class Git(FetchMethod): 121class Git(FetchMethod):
80 """Class to fetch a module or modules from git repositories""" 122 """Class to fetch a module or modules from git repositories"""
81 def init(self, d): 123 def init(self, d):
@@ -196,10 +238,11 @@ class Git(FetchMethod):
196 # We do this since git will use a "-l" option automatically for local urls where possible 238 # We do this since git will use a "-l" option automatically for local urls where possible
197 if repourl.startswith("file://"): 239 if repourl.startswith("file://"):
198 repourl = repourl[7:] 240 repourl = repourl[7:]
199 clone_cmd = "%s clone --bare --mirror %s %s" % (ud.basecmd, repourl, ud.clonedir) 241 clone_cmd = "LANG=C %s clone --bare --mirror %s %s --progress" % (ud.basecmd, repourl, ud.clonedir)
200 if ud.proto.lower() != 'file': 242 if ud.proto.lower() != 'file':
201 bb.fetch2.check_network_access(d, clone_cmd) 243 bb.fetch2.check_network_access(d, clone_cmd)
202 runfetchcmd(clone_cmd, d) 244 progresshandler = GitProgressHandler(d)
245 runfetchcmd(clone_cmd, d, log=progresshandler)
203 246
204 os.chdir(ud.clonedir) 247 os.chdir(ud.clonedir)
205 # Update the checkout if needed 248 # Update the checkout if needed
@@ -214,10 +257,11 @@ class Git(FetchMethod):
214 logger.debug(1, "No Origin") 257 logger.debug(1, "No Origin")
215 258
216 runfetchcmd("%s remote add --mirror=fetch origin %s" % (ud.basecmd, repourl), d) 259 runfetchcmd("%s remote add --mirror=fetch origin %s" % (ud.basecmd, repourl), d)
217 fetch_cmd = "%s fetch -f --prune %s refs/*:refs/*" % (ud.basecmd, repourl) 260 fetch_cmd = "LANG=C %s fetch -f --prune --progress %s refs/*:refs/*" % (ud.basecmd, repourl)
218 if ud.proto.lower() != 'file': 261 if ud.proto.lower() != 'file':
219 bb.fetch2.check_network_access(d, fetch_cmd, ud.url) 262 bb.fetch2.check_network_access(d, fetch_cmd, ud.url)
220 runfetchcmd(fetch_cmd, d) 263 progresshandler = GitProgressHandler(d)
264 runfetchcmd(fetch_cmd, d, log=progresshandler)
221 runfetchcmd("%s prune-packed" % ud.basecmd, d) 265 runfetchcmd("%s prune-packed" % ud.basecmd, d)
222 runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d) 266 runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d)
223 try: 267 try: