Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show upload size for recipes and packages #16103

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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