forked from conan-io/conan-package-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conan-io#282 Add CONAN_REMOVE_OUTDATE_PACKAGES option
- The new option will run conan remove <ref> -r <remote> -f --outdated after to upload a package Signed-off-by: Uilian Ries <[email protected]>
- Loading branch information
1 parent
d4dcf59
commit 2a95fc6
Showing
7 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
class Eraser(object): | ||
""" Helper to connect on remove and remove outdated packages | ||
""" | ||
|
||
def __init__(self, conan_api, remote_manager, auth_manager, printer, remove): | ||
""" Initialize Eraser instance | ||
:param conan_api: Conan API instance | ||
:param remote_manager: Remote manager instance | ||
:param auth_manager: Authication manager to access the remote | ||
:param printer: CPT output | ||
:param remove: True if should remove outdated packages from remote. Otherwise, False. | ||
""" | ||
self.conan_api = conan_api | ||
self.remote_manager = remote_manager | ||
self.auth_manager = auth_manager | ||
self.printer = printer | ||
self.remove = remove | ||
|
||
def remove_outdated_packages(self, reference): | ||
""" Remove outdated packages from remote | ||
:param reference: Package reference e.g. foo/0.1.0@user/channel | ||
""" | ||
if not self.remote_manager or not self.remote_manager.upload_remote_name: | ||
self.printer.print_message("Remove outdated skipped, no remote available") | ||
return | ||
remote_name = self.remote_manager.upload_remote_name | ||
|
||
if not self.auth_manager or not self.auth_manager.credentials_ready(remote_name): | ||
self.printer.print_message("Remove outdated skipped, credentials for remote '%s' not available" % remote_name) | ||
return | ||
|
||
if self.remove: | ||
self.printer.print_message("Removing outdated packages for '%s'" % str(reference)) | ||
self.auth_manager.login(remote_name) | ||
self.conan_api.remove(pattern=str(reference), | ||
force=True, | ||
remote_name=remote_name, | ||
outdated=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from conans.client.tools import environment_append | ||
from conans.test.utils.tools import TestClient, TestServer | ||
|
||
from cpt.test.test_client.tools import get_patched_multipackager | ||
|
||
|
||
class EraseTest(unittest.TestCase): | ||
|
||
old_conanfile = """from conans import ConanFile | ||
class Pkg(ConanFile): | ||
name = "lib" | ||
version = "1.0" | ||
options = {"shared": [True, False]} | ||
default_options = "shared=False" | ||
def build(self): | ||
self.output.warn("OLD") | ||
""" | ||
|
||
new_conanfile = """from conans import ConanFile | ||
class Pkg(ConanFile): | ||
name = "lib" | ||
version = "1.0" | ||
options = {"shared": [True, False], "foo": [True, False]} | ||
default_options = "shared=False", "foo=True" | ||
def build(self): | ||
self.output.warn("NEW") | ||
""" | ||
|
||
def test_remove_updated_packages_env_var(self): | ||
ts = TestServer(users={"user": "password"}) | ||
tc = TestClient(servers={"default": ts}, users={"default": [("user", "password")]}) | ||
tc.save({"conanfile.py": self.old_conanfile}) | ||
with environment_append({"CONAN_UPLOAD": ts.fake_url, "CONAN_LOGIN_USERNAME": "user", | ||
"CONAN_PASSWORD": "password", "CONAN_USERNAME": "user", | ||
"CONAN_REMOVE_OUTDATED_PACKAGES": "1"}): | ||
mulitpackager = get_patched_multipackager(tc, build_policy="missing", | ||
exclude_vcvars_precommand=True) | ||
mulitpackager.add({}, {"shared": True}) | ||
mulitpackager.add({}, {"shared": False}) | ||
mulitpackager.run() | ||
self.assertIn("Uploading package 1/2", tc.out) | ||
self.assertIn("Uploading package 2/2", tc.out) | ||
self.assertIn("OLD", tc.out) | ||
self.assertIn("Removing outdated packages for 'lib/1.0@user/testing'", tc.out) | ||
|
||
def test_remove_updated_packages_params(self): | ||
ts = TestServer(users={"user": "password"}) | ||
tc = TestClient(servers={"default": ts}, users={"default": [("user", "password")]}) | ||
tc.save({"conanfile.py": self.old_conanfile}) | ||
with environment_append({"CONAN_UPLOAD": ts.fake_url, "CONAN_LOGIN_USERNAME": "user", | ||
"CONAN_PASSWORD": "password", "CONAN_USERNAME": "user"}): | ||
mulitpackager = get_patched_multipackager(tc, build_policy="missing", | ||
exclude_vcvars_precommand=True, | ||
remove_outdated_packages=True) | ||
mulitpackager.add({}, {"shared": True}) | ||
mulitpackager.add({}, {"shared": False}) | ||
mulitpackager.run() | ||
self.assertIn("Uploading package 1/2", tc.out) | ||
self.assertIn("Uploading package 2/2", tc.out) | ||
self.assertIn("OLD", tc.out) | ||
self.assertIn("Removing outdated packages for 'lib/1.0@user/testing'", tc.out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from collections import namedtuple | ||
from conans.test.utils.tools import TestBufferConanOutput | ||
from cpt.eraser import Eraser | ||
from cpt.printer import Printer | ||
from cpt.test.unit.packager_test import MockConanAPI | ||
|
||
|
||
class AuthTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.conan_api = MockConanAPI() | ||
self.output = TestBufferConanOutput() | ||
self.printer = Printer(self.output.write) | ||
|
||
def test_invalid_remote(self): | ||
eraser = Eraser(self.conan_api, None, None, self.printer, True) | ||
eraser.remove_outdated_packages("foo/0.1.0@user/channel") | ||
self.assertIn("Remove outdated skipped, no remote available", self.output) | ||
self.assertFalse(self.conan_api.calls) | ||
|
||
def test_invalid_authentication(self): | ||
FakeRemoteManager = namedtuple("FakeRemoteManager", "upload_remote_name") | ||
remote_manager = FakeRemoteManager(upload_remote_name="default") | ||
eraser = Eraser(self.conan_api, remote_manager, None, self.printer, True) | ||
eraser.remove_outdated_packages("foo/0.1.0@user/channel") | ||
self.assertIn("Remove outdated skipped, credentials for remote 'default' not available", self.output) | ||
self.assertFalse(self.conan_api.calls) |