def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.client_cache = ClientCache(temp_folder(), temp_folder(), self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.client_cache, self.remote_client, self.output)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.paths = ConanPaths(temp_folder(), temp_folder(), self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.paths, self.remotes, self.remote_client, self.output) def test_no_remotes(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") client.save(files) client.run("export lasote/stable") client.run("upload Hello0/0.1@lasote/stable", ignore_error=True) self.assertIn("ERROR: There is no configured default remote", client.user_io.out) def test_properties(self): # Remote names self.assertEquals(self.manager.remote_names, ["default", "other", "last"]) # Remote url self.assertEquals(self.manager.remote_url("default"), "url1") self.assertEquals(self.manager.remote_url("other"), "url2") def remote_selection_test(self): # If no remote is specified will look to first self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference) # If remote is specified took it self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, "other") def method_called_test(self): self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, "other") self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_conanfile.called) self.manager.get_conanfile(self.conan_reference) self.assertTrue(self.remote_client.get_conanfile.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference) self.assertTrue(self.remote_client.get_package.called)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads( "openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.paths = ConanPaths(temp_folder(), None, self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.paths, self.remotes, self.remote_client, self.output) def test_properties(self): # Remote names self.assertEquals(self.manager.remote_names, ["default", "other", "last"]) # Remote url self.assertEquals(self.manager.remote_url("default"), "url1") self.assertEquals(self.manager.remote_url("other"), "url2") def remote_selection_test(self): # If no remote is specified will look to first self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference) # If remote is specified took it self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, "other") def method_called_test(self): self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, "other") self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_conanfile.called) self.manager.get_conanfile(self.conan_reference) self.assertTrue(self.remote_client.get_conanfile.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference) self.assertTrue(self.remote_client.get_package.called)
def _init_collaborators(self, user_io=None): output = TestBufferConanOutput() self.user_io = user_io or MockedUserIO(self.users, out=output) self.runner = TestRunner(output, runner=self.conan_runner) # Check if servers are real real_servers = False for server in self.servers.values(): if isinstance(server, str): # Just URI real_servers = True if real_servers: requester = requests else: if self.requester_class: requester = self.requester_class(self.servers) else: requester = TestRequester(self.servers) # Verify client version against remotes self.requester = VersionCheckerRequester(requester, self.client_version, self.min_server_compatible_version, output) put_headers = self.client_cache.read_put_headers() self.rest_api_client = RestApiClient(output, requester=self.requester, put_headers=put_headers) # To store user and token self.localdb = LocalDB(self.client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(self.rest_api_client, self.user_io, self.localdb) # Handle remote connections self.remote_manager = RemoteManager(self.client_cache, auth_manager, self.user_io.out)
def init_dynamic_vars(self, user_io=None): output = TestBufferConanOutput() # Migration system self.paths = migrate_and_get_paths(self.base_folder, output, storage_folder=self.storage_folder) self.user_io = user_io or MockedUserIO(self.users, out=output) self.runner = TestRunner(output) requester = TestRequester(self.servers) # Verify client version against remotes self.requester = VersionCheckerRequester( requester, self.client_version, self.min_server_compatible_version, output) self.rest_api_client = RestApiClient(output, requester=self.requester) # To store user and token self.localdb = LocalDB(self.paths.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(self.rest_api_client, self.user_io, self.localdb) # Handle remote connections self.remote_manager = RemoteManager(self.paths, self.servers.items(), auth_manager, self.user_io.out)
def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.client_cache = ClientCache(temp_folder(), temp_folder(), self.output) self.manager = RemoteManager(self.client_cache, self.remote_client, self.output)
def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.paths = ConanPaths(temp_folder(), temp_folder(), self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.paths, self.remote_client, self.output)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.paths = ConanPaths(temp_folder(), None, self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.paths, self.remotes, self.remote_client, self.output) def test_properties(self): # Remote names self.assertEquals(self.manager.remote_names, ["default", "other", "last"]) # Remote url self.assertEquals(self.manager.remote_url("default"), "url1") self.assertEquals(self.manager.remote_url("other"), "url2") def remote_selection_test(self): # If no remote is specified will look to first self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference) # If remote is specified took it self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, "other") def method_called_test(self): self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, "other") self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_conanfile.called) self.manager.get_conanfile(self.conan_reference) self.assertTrue(self.remote_client.get_conanfile.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference) self.assertTrue(self.remote_client.get_package.called)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads( "openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.client_cache = ClientCache(temp_folder(), temp_folder(), self.output) self.manager = RemoteManager(self.client_cache, self.remote_client, self.output) def test_no_remotes(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") client.save(files) client.run("export lasote/stable") client.run("upload Hello0/0.1@lasote/stable", ignore_error=True) self.assertIn("ERROR: No default remote defined", client.user_io.out) def method_called_test(self): save( os.path.join(self.client_cache.package(self.package_reference), CONANINFO), "asdasd") manifest = FileTreeManifest.create( self.client_cache.package(self.package_reference)) save( os.path.join(self.client_cache.package(self.package_reference), CONAN_MANIFEST), str(manifest)) self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, Remote("other", "url", True), 1, 0) self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference, Remote("other", "url", True)) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_recipe.called) self.manager.get_recipe(self.conan_reference, temp_folder(), Remote("other", "url", True)) self.assertTrue(self.remote_client.get_recipe.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference, temp_folder(), Remote("other", "url", True)) self.assertTrue(self.remote_client.get_package.called)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.client_cache = ClientCache(temp_folder(), temp_folder(), self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.client_cache, self.remote_client, self.output) def test_no_remotes(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") client.save(files) client.run("export lasote/stable") client.run("upload Hello0/0.1@lasote/stable", ignore_error=True) self.assertIn("ERROR: No default remote defined", client.user_io.out) def remote_selection_test(self): save(os.path.join(self.client_cache.export(self.conan_reference), CONANFILE), "asdasd") save(os.path.join(self.client_cache.export(self.conan_reference), CONAN_MANIFEST), "asdasd") # If no remote is specified will look to first self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, None) # If remote is specified took it self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, Remote("other", "url")) def method_called_test(self): save(os.path.join(self.client_cache.package(self.package_reference), CONANINFO), "asdasd") manifest = FileTreeManifest.create(self.client_cache.package(self.package_reference)) save(os.path.join(self.client_cache.package(self.package_reference), CONAN_MANIFEST), str(manifest)) self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, Remote("other", "url")) self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference, Remote("other", "url")) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_recipe.called) self.manager.get_recipe(self.conan_reference, temp_folder(), Remote("other", "url")) self.assertTrue(self.remote_client.get_recipe.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference, temp_folder(), Remote("other", "url")) self.assertTrue(self.remote_client.get_package.called)
class RemoteManagerTest(unittest.TestCase): """Unit test""" def setUp(self): self.conan_reference = ConanFileReference.loads( "openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.remote_client = MockRemoteClient() self.output = TestBufferConanOutput() self.paths = ConanPaths(temp_folder(), temp_folder(), self.output) self.remotes = [("default", "url1"), ("other", "url2"), ("last", "url3")] self.manager = RemoteManager(self.paths, self.remote_client, self.output) def test_no_remotes(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") client.save(files) client.run("export lasote/stable") client.run("upload Hello0/0.1@lasote/stable", ignore_error=True) self.assertIn("ERROR: No default remote defined", client.user_io.out) def remote_selection_test(self): # If no remote is specified will look to first self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, Remote("other", "url")) # If remote is specified took it self.assertRaises(NotFoundException, self.manager.upload_conan, self.conan_reference, Remote("other", "url")) def method_called_test(self): self.assertFalse(self.remote_client.upload_package.called) self.manager.upload_package(self.package_reference, Remote("other", "url")) self.assertTrue(self.remote_client.upload_package.called) self.assertFalse(self.remote_client.get_conan_digest.called) self.manager.get_conan_digest(self.conan_reference, Remote("other", "url")) self.assertTrue(self.remote_client.get_conan_digest.called) self.assertFalse(self.remote_client.get_conanfile.called) self.manager.get_conanfile(self.conan_reference, Remote("other", "url")) self.assertTrue(self.remote_client.get_conanfile.called) self.assertFalse(self.remote_client.get_package.called) self.manager.get_package(self.package_reference, Remote("other", "url")) self.assertTrue(self.remote_client.get_package.called)
def instance_remote_manager(client_cache): requester = requests.Session() requester.proxies = client_cache.conan_config.proxies # Verify client version against remotes version_checker_requester = VersionCheckerRequester(requester, Version(CLIENT_VERSION), Version(MIN_SERVER_COMPATIBLE_VERSION), out) # To handle remote connections rest_api_client = RestApiClient(out, requester=version_checker_requester) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, out) return remote_manager
def instance_remote_manager(client_cache): requester = get_basic_requester(client_cache) # Verify client version against remotes version_checker_req = VersionCheckerRequester(requester, Version(client_version), Version(MIN_SERVER_COMPATIBLE_VERSION), out) # To handle remote connections put_headers = client_cache.read_put_headers() rest_api_client = RestApiClient(out, requester=version_checker_req, put_headers=put_headers) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, out) return remote_manager
def main(args): """ main entry point of the conans application, using a Command to parse parameters """ if hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): import colorama colorama.init() color = True else: color = False out = ConanOutput(sys.stdout, color) user_io = UserIO(out=out) user_folder = os.path.expanduser("~") paths = migrate_and_get_paths(user_folder, out) # Verify client version against remotes version_checker_requester = VersionCheckerRequester( requests, Version(CLIENT_VERSION), Version(MIN_SERVER_COMPATIBLE_VERSION), out) # To handle remote connections rest_api_client = RestApiClient(out, requester=version_checker_requester) # To store user and token localdb = LocalDB(paths.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(paths, paths.conan_config.remotes, auth_manager, out) command = Command(paths, user_io, os.system, remote_manager, localdb) current_dir = os.getcwd() try: import signal def sigint_handler(signal, frame): print('You pressed Ctrl+C!') sys.exit(0) signal.signal(signal.SIGINT, sigint_handler) error = command.run(args) finally: os.chdir(current_dir) sys.exit(error)
def instance_remote_manager(requester, client_cache, user_io, _client_version, min_server_compatible_version): # Verify client version against remotes version_checker_req = VersionCheckerRequester(requester, _client_version, min_server_compatible_version, user_io.out) # To handle remote connections put_headers = client_cache.read_put_headers() rest_api_client = RestApiClient(user_io.out, requester=version_checker_req, put_headers=put_headers) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, user_io.out) return localdb, rest_api_client, remote_manager
def init_dynamic_vars(self, user_io=None): # Migration system output = TestBufferConanOutput() self.user_io = user_io or MockedUserIO(self.users, out=output) self.cache = ClientCache(self.base_folder, output) # Migration system migrator = ClientMigrator(self.cache, Version(__version__), output) migrator.migrate() http_requester = self._get_http_requester() config = self.cache.config if self.conan_runner: self.runner = self.conan_runner else: self.runner = ConanRunner(config.print_commands_to_output, config.generate_run_log_file, config.log_run_to_output, output=output) self.requester = ConanRequester(config, http_requester) self.hook_manager = HookManager(self.cache.hooks_path, config.hooks, self.user_io.out) put_headers = self.cache.read_put_headers() self.rest_api_client = RestApiClient( self.user_io.out, self.requester, revisions_enabled=config.revisions_enabled, put_headers=put_headers) # To store user and token self.localdb = LocalDB.create(self.cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(self.rest_api_client, self.user_io, self.localdb) # Handle remote connections self.remote_manager = RemoteManager(self.cache, auth_manager, self.user_io.out, self.hook_manager) return output, self.requester