Skip to content

Commit

Permalink
Print only packages confirmed interactively in conan upload (#14512)
Browse files Browse the repository at this point in the history
* upload and output only confirmed refs in CLI

* new check
  • Loading branch information
memsharded authored Aug 21, 2023
1 parent 1d449da commit d739ab6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
60 changes: 38 additions & 22 deletions conan/cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ def summary_upload_list(results):
"""
cli_out_write("Upload summary:")
info = results["results"]
result = {}
for remote, remote_info in info.items():
new_info = result.setdefault(remote, {})
for ref, content in remote_info.items():
for rev, rev_content in content["revisions"].items():
pkgids = rev_content.get('packages')
if pkgids:
new_info.setdefault(f"{ref}:{rev}", list(pkgids))
print_serial(result)

def format_upload(item):
if isinstance(item, dict):
result = {}
for k, v in item.items():
if isinstance(v, dict):
v.pop("info", None)
v.pop("timestamp", None)
v.pop("files", None)
upload_value = v.pop("upload", None)
if upload_value is not None:
msg = "Uploaded" if upload_value else "Skipped, already in server"
force_upload = v.pop("force_upload", None)
if force_upload:
msg += " - forced"
k = f"{k} ({msg})"
result[k] = format_upload(v)
return result
return item
info = {remote: format_upload(values) for remote, values in info.items()}
print_serial(info)


@conan_command(group="Creator", formatters={"text": summary_upload_list,
Expand Down Expand Up @@ -82,15 +94,14 @@ def upload(conan_api: ConanAPI, parser, *args):
package_list = conan_api.list.select(ref_pattern, package_query=args.package_query)

if package_list.recipes:
if args.check:
conan_api.cache.check_integrity(package_list)
# Check if the recipes/packages are in the remote
conan_api.upload.check_upstream(package_list, remote, enabled_remotes, args.force)

# If only if search with "*" we ask for confirmation
if not args.list and not args.confirm and "*" in args.pattern:
_ask_confirm_upload(conan_api, package_list)

if args.check:
conan_api.cache.check_integrity(package_list)
# Check if the recipes/packages are in the remote
conan_api.upload.check_upstream(package_list, remote, enabled_remotes, args.force)
conan_api.upload.prepare(package_list, enabled_remotes, args.metadata)

if not args.dry_run:
Expand All @@ -111,17 +122,22 @@ def upload(conan_api: ConanAPI, parser, *args):
}


def _ask_confirm_upload(conan_api, upload_data):
def _ask_confirm_upload(conan_api, package_list):
ui = UserInput(conan_api.config.get("core:non_interactive"))
for ref, bundle in upload_data.refs().items():
for ref, bundle in package_list.refs().items():
msg = "Are you sure you want to upload recipe '%s'?" % ref.repr_notime()
ref_dict = package_list.recipes[str(ref)]["revisions"]
if not ui.request_boolean(msg):
bundle["upload"] = False
for _, prev_bundle in upload_data.prefs(ref, bundle).items():
prev_bundle["upload"] = False

ref_dict.pop(ref.revision)
# clean up empy refs
if not ref_dict:
package_list.recipes.pop(str(ref))
else:
for pref, prev_bundle in upload_data.prefs(ref, bundle).items():
for pref, prev_bundle in package_list.prefs(ref, bundle).items():
msg = "Are you sure you want to upload package '%s'?" % pref.repr_notime()
pkgs_dict = ref_dict[ref.revision]["packages"]
if not ui.request_boolean(msg):
prev_bundle["upload"] = False
pref_dict = pkgs_dict[pref.package_id]["revisions"]
pref_dict.pop(pref.revision)
if not pref_dict:
pkgs_dict.pop(pref.package_id)
23 changes: 21 additions & 2 deletions conans/test/integration/command/upload/upload_complete_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from conans.paths import CONAN_MANIFEST
from conans.test.utils.tools import (NO_SETTINGS_PACKAGE_ID, TestClient, TestRequester, TestServer,
GenConanfile)
from conans.util.env import environment_update
from conans.util.files import load


Expand Down Expand Up @@ -71,20 +72,38 @@ def test_upload_with_pattern():

def test_check_upload_confirm_question():
server = TestServer()
client = TestClient(servers={"default": server}, inputs=["yes", "admin", "password", "n", "n"])
client = TestClient(servers={"default": server},
inputs=["yes", "admin", "password", "n", "n", "n"])
client.save({"conanfile.py": GenConanfile("hello1", "1.2.1")})
client.run("export . --user=frodo --channel=stable")
client.run("upload hello* -r default")

assert "Uploading recipe 'hello1/1.2.1@frodo/stable" in client.out

client.save({"conanfile.py": GenConanfile("hello2", "1.2.1")})
client.run("export . --user=frodo --channel=stable")
client.run("create . --user=frodo --channel=stable")
client.run("upload hello* -r default")

assert "Uploading recipe 'hello2/1.2.1@frodo/stable" not in client.out


def test_check_upload_confirm_question_yes():
server = TestServer()
client = TestClient(servers={"default": server},
inputs=["yes", "yes", "yes", "yes", "yes", "admin", "password"])
client.save({"conanfile.py": GenConanfile("hello1", "1.2.1")})
client.run("create . ")
client.save({"conanfile.py": GenConanfile("hello1", "1.2.1").with_package_file("file.txt",
env_var="MYVAR")})

with environment_update({"MYVAR": "0"}):
client.run("create . ")
with environment_update({"MYVAR": "1"}):
client.run("create . ")
client.run("upload hello*#*:*#* -r default")
assert str(client.out).count("(Uploaded)") == 5


class UploadTest(unittest.TestCase):

def _get_client(self, requester=None):
Expand Down

0 comments on commit d739ab6

Please sign in to comment.