Skip to content

Commit

Permalink
Show progress bar while updating workarea
Browse files Browse the repository at this point in the history
Get rid of the spammy output when not in debug mode, instead showing a
progress bar.
  • Loading branch information
TimoWilken authored and ktf committed Mar 6, 2024
1 parent c7efb2d commit 3842a49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 6 additions & 1 deletion alibuild_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ def update_repo(package, git_prompt):
cmd, ".", prompt=git_prompt, logOutput=False)
specs[package]["scm_refs"] = scm.parseRefs(output)

progress = ProgressPrint("Updating repositories")
requires_auth = set()
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
future_to_download = {
executor.submit(update_repo, package, git_prompt=False): package
for package in buildOrder if "source" in specs[package]
}
for future in concurrent.futures.as_completed(future_to_download):
for i, future in enumerate(concurrent.futures.as_completed(future_to_download)):
futurePackage = future_to_download[future]
progress("[%d/%d] Updating repository for %s",
i, len(future_to_download), futurePackage)
try:
future.result()
except SCMError:
Expand All @@ -103,11 +106,13 @@ def update_repo(package, git_prompt):
debug("%r requires auth; will prompt later", futurePackage)
requires_auth.add(futurePackage)
except Exception as exc:
progress.end("error", error=True)
dieOnError(True, "Error on fetching %r: %s. Aborting." %
(futurePackage, exc))
else:
debug("%r package updated: %d refs found", futurePackage,
len(specs[futurePackage]["scm_refs"]))
progress.end("done")

# Now execute git commands for private packages one-by-one, so the user can
# type their username and password without multiple prompts interfering.
Expand Down
7 changes: 3 additions & 4 deletions alibuild_helpers/workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except ImportError:
from ordereddict import OrderedDict

from alibuild_helpers.log import dieOnError, debug, info, error
from alibuild_helpers.log import dieOnError, debug, error

FETCH_LOG_NAME = "fetch-log.txt"

Expand Down Expand Up @@ -37,8 +37,7 @@ def logged_scm(scm, package, referenceSources,
must not contain any secrets. We only output the SCM command we ran, its exit
code, and the package name, so this should be safe.
"""
# This might take a long time, so show the user what's going on.
info("%s %s for repository for %s...", scm.name, command[0], package)
debug("%s %s for repository for %s...", scm.name, command[0], package)
err, output = scm.exec(command, directory=directory, check=False, prompt=prompt)
if logOutput:
debug(output)
Expand All @@ -53,7 +52,7 @@ def logged_scm(scm, package, referenceSources,
error("Could not write error log from SCM command:", exc_info=exc)
dieOnError(err, "Error during %s %s for reference repo for %s." %
(scm.name.lower(), command[0], package))
info("Done %s %s for repository for %s", scm.name.lower(), command[0], package)
debug("Done %s %s for repository for %s", scm.name.lower(), command[0], package)
return output


Expand Down
1 change: 0 additions & 1 deletion tests/test_workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


@patch("alibuild_helpers.workarea.debug", new=MagicMock())
@patch("alibuild_helpers.workarea.info", new=MagicMock())
@patch("alibuild_helpers.git.clone_speedup_options",
new=MagicMock(return_value=["--filter=blob:none"]))
class WorkareaTestCase(unittest.TestCase):
Expand Down

0 comments on commit 3842a49

Please sign in to comment.