Skip to content

Commit

Permalink
Show upload size for recipes and packages (#16103)
Browse files Browse the repository at this point in the history
* Show upload size for big recipe/packages

* Cleanup

* Use human_size helper

* Cleanup

* Hijack one test to also check for the size
  • Loading branch information
AbrilRBS committed Apr 18, 2024
1 parent 524c440 commit 7b668f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 15 additions & 4 deletions conans/client/cmd/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from conans.paths import (CONAN_MANIFEST, CONANFILE, EXPORT_SOURCES_TGZ_NAME,
EXPORT_TGZ_NAME, PACKAGE_TGZ_NAME, CONANINFO)
from conans.util.files import (clean_dirty, is_dirty, gather_files,
gzopen_without_timestamps, set_dirty_context_manager, mkdir)
gzopen_without_timestamps, set_dirty_context_manager, mkdir,
human_size)

UPLOAD_POLICY_FORCE = "force-upload"
UPLOAD_POLICY_SKIP = "skip-upload"
Expand Down Expand Up @@ -220,10 +221,11 @@ def upload(self, upload_data, remote):

def upload_recipe(self, ref, bundle, remote):
output = ConanOutput(scope=str(ref))
output.info(f"Uploading recipe '{ref.repr_notime()}'")
t1 = time.time()
cache_files = bundle["files"]

output.info(f"Uploading recipe '{ref.repr_notime()}' ({_total_size(cache_files)})")

t1 = time.time()
self._app.remote_manager.upload_recipe(ref, cache_files, remote)

duration = time.time() - t1
Expand All @@ -232,11 +234,12 @@ def upload_recipe(self, ref, bundle, remote):

def upload_package(self, pref, prev_bundle, remote):
output = ConanOutput(scope=str(pref.ref))
output.info(f"Uploading package '{pref.repr_notime()}'")
cache_files = prev_bundle["files"]
assert (pref.revision is not None), "Cannot upload a package without PREV"
assert (pref.ref.revision is not None), "Cannot upload a package without RREV"

output.info(f"Uploading package '{pref.repr_notime()}' ({_total_size(cache_files)})")

t1 = time.time()
self._app.remote_manager.upload_package(pref, cache_files, remote)
duration = time.time() - t1
Expand All @@ -259,3 +262,11 @@ def compress_files(files, name, dest_dir, compresslevel=None, ref=None):
duration = time.time() - t1
ConanOutput().debug(f"{name} compressed in {duration} time")
return tgz_path


def _total_size(cache_files):
total_size = 0
for file in cache_files.values():
stat = os.stat(file)
total_size += stat.st_size
return human_size(total_size)
4 changes: 4 additions & 0 deletions conans/test/integration/command/source_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import textwrap
import unittest
from collections import OrderedDict
Expand Down Expand Up @@ -156,6 +157,9 @@ def test_retrieve_exports_sources(self):
client.run("create . --name=hello --version=0.1")
rrev = client.exported_recipe_revision()
client.run("upload hello/0.1 -r server0")
# Ensure we uploaded it
assert re.search(r"Uploading recipe 'hello/0.1#.*' \(.*\)", client.out)
assert re.search(r"Uploading package 'hello/0.1#.*' \(.*\)", client.out)
client.run("remove * -c")

# install from server0 that has the sources, upload to server1 (does not have the package)
Expand Down

0 comments on commit 7b668f3

Please sign in to comment.