def setUp(self): self.conan_reference = ConanFileReference.loads( "openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.tmp_dir = temp_folder() read_perms = [("*/*@*/*", "*")] write_perms = [] authorizer = BasicAuthorizer(read_perms, write_perms) self.fake_url = "http://url" updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200)) adapter = DiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager) self.paths = SimplePaths(self.tmp_dir) self.file_manager = FileManager(self.paths, adapter) self.service = ConanService(authorizer, self.file_manager, "lasote") files = hello_source_files("test") save_files(self.paths.export(self.conan_reference), files) self.conan_digest = FileTreeManifest.create( self.paths.export(self.conan_reference)) conan_digest_path = os.path.join( self.paths.export(self.conan_reference), CONAN_MANIFEST) save(conan_digest_path, str(self.conan_digest)) files = hello_source_files("package") save_files(self.paths.package(self.package_reference), files)
def conanfile_capture_verify_manifest_folder_test(self): files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"} self.client.save(files, clean_first=True) folder = "mymanifests" self._capture_verify_manifest(".", folder=folder) conanfile = """from conans import ConanFile class ConanFileTest(ConanFile): name = "Hello2" version = "0.1" """ client = TestClient(base_folder=self.client.base_folder) client.save({CONANFILE: conanfile}) client.run("export . lasote/stable") files = {"conanfile.txt": "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable"} self.client.save(files) self.client.run("install . --build missing --manifests %s" % folder) remote = "local cache" package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, folder) paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(os.path.join(paths.export(self.reference), CONAN_MANIFEST))) self.assertTrue(os.path.exists(os.path.join(paths.package(package_reference), CONAN_MANIFEST)))
def _capture_verify_manifest(self, reference, remote="local cache", folder=""): self.client.run("install %s --build missing --manifests %s" % (str(reference), folder)) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) real_folder = folder or ".conan_manifests" output_folder = os.path.join(self.client.current_folder, real_folder) paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) # again should do nothing self.client.run("install %s --build missing --manifests %s" % (str(self.reference), folder)) self.assertNotIn("manifest", self.client.user_io.out) # now verify self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder)) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
def _capture_verify_manifest(self, reference, remote="local cache", folder=""): self.client.run("install %s --build missing --manifests %s" % (str(reference), folder)) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) real_folder = folder or ".conan_manifests" output_folder = os.path.join(self.client.current_folder, real_folder) paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) # again should do nothing self.client.run("install %s --build missing --manifests %s" % (str(self.reference), folder)) self.assertNotIn("Installed manifest", self.client.user_io.out) # now verify self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder)) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
def test_package_test(self, use_abs_folder): self.client.run("install Hello/0.1@lasote/stable --build missing") conanfile = """from conans import ConanFile class ConsumerFileTest(ConanFile): name = "Chat" version = "0.1" requires = "Hello/0.1@lasote/stable" """ test_conanfile = """from conans import ConanFile class ConsumerFileTest(ConanFile): requires = "Chat/0.1@lasote/stable" def test(self): self.output.info("TEST OK") """ if use_abs_folder: output_folder = temp_folder() dest = '="%s"' % output_folder else: dest = "" output_folder = os.path.join(self.client.current_folder, ".conan_manifests") self.client.save( { "conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile }, clean_first=True) self.client.run("create . lasote/stable --manifests%s" % dest) self.assertIn("Chat/0.1@lasote/stable (test package): TEST OK", self.client.user_io.out) self.assertIn( "Installed manifest for 'Chat/0.1@lasote/stable' from local cache", self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable' from local cache", self.client.user_io.out) paths = SimplePaths(output_folder) self.assertTrue( os.path.exists( os.path.join(paths.export(self.reference), CONAN_MANIFEST))) package_reference = PackageReference.loads( "Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue( os.path.exists( os.path.join(paths.package(package_reference), CONAN_MANIFEST))) # now verify self.client.run("create . lasote/stable --verify%s" % dest) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
def __init__(self, folder, user_io, client_cache, verify=False, interactive=False): if verify and not os.path.exists(folder): raise ConanException("Manifest folder does not exist: %s" % folder) self._paths = SimplePaths(folder) self._user_io = user_io self._client_cache = client_cache self._verify = verify self._interactive = interactive self._log = []
def _failed_package_verify(self, reference, remote="local cache"): self.client.run("install %s --build missing --manifests" % str(reference)) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, ".conan_manifests") paths = SimplePaths(output_folder) self.assertTrue( os.path.exists( os.path.join(paths.export(self.reference), CONAN_MANIFEST))) package_reference = PackageReference.loads( "Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue( os.path.exists( os.path.join(paths.package(package_reference), CONAN_MANIFEST))) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client.save(self.files) client.run("export . lasote/stable") client.run("install Hello/0.1@lasote/stable --build=missing") info = os.path.join(client.paths.package(package_reference), "conaninfo.txt") info_content = load(info) info_content += "# Dummy string" save(info, info_content) package_folder = client.paths.package(package_reference) manifest = FileTreeManifest.load(package_folder) manifest.file_sums["conaninfo.txt"] = md5(info_content) manifest.save(package_folder) client.run("upload %s --all" % str(self.reference)) # now verify, with update self.client.run("remove Hello/0.1@lasote/stable -f") self.client.run("install %s --build missing --verify" % str(self.reference), ignore_error=True) self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn( "Modified or new manifest '%s' detected" % str(package_reference), self.client.user_io.out)
def delete_empty_dirs(self, deleted_refs): paths = SimplePaths(self._store_folder) for ref in deleted_refs: ref_path = paths.conan(ref) for _ in range(4): if os.path.exists(ref_path): try: # Take advantage that os.rmdir does not delete non-empty dirs os.rmdir(ref_path) except OSError: break # not empty ref_path = os.path.dirname(ref_path)
def _failed_verify(self, reference, remote="local cache"): self.client.run("install %s --build missing --manifests" % str(reference)) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, ".conan_manifests") paths = SimplePaths(output_folder) self.assertTrue( os.path.exists( os.path.join(paths.export(self.reference), CONAN_MANIFEST))) package_reference = PackageReference.loads( "Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue( os.path.exists( os.path.join(paths.package(package_reference), CONAN_MANIFEST))) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) conanfile = """from conans import ConanFile class ConanFileTest(ConanFile): name = "Hello" version = "0.1" exports = "*" """ files = {CONANFILE: conanfile, "data.txt": "MyDataHacked"} # Export and upload the conanfile client.save(files) client.run("export . lasote/stable") client.run("upload %s --all" % str(self.reference)) # now verify, with update self.client.run("remove Hello/0.1@lasote/stable -f") self.client.run("install %s --build missing --verify" % str(self.reference), ignore_error=True) self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn( "Modified or new manifest 'Hello/0.1@lasote/stable' detected", self.client.user_io.out)
def delete_empty_dirs(self, deleted_refs): paths = SimplePaths(self._store_folder) lock_files = set([REVISIONS_FILE, "%s.lock" % REVISIONS_FILE]) for ref in deleted_refs: ref_path = paths.conan(ref) for _ in range(4 if not ref.revision else 5): if os.path.exists(ref_path): if set(os.listdir(ref_path)) == lock_files: for lock_file in lock_files: os.unlink(os.path.join(ref_path, lock_file)) try: # Take advantage that os.rmdir does not delete non-empty dirs os.rmdir(ref_path) except OSError: break # not empty ref_path = os.path.dirname(ref_path)
def conanfile_capture_verify_manifest_folder_test(self): files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"} self.client.save(files, clean_first=True) folder = "mymanifests" self._capture_verify_manifest(".", folder=folder) conanfile = """from conans import ConanFile class ConanFileTest(ConanFile): name = "Hello2" version = "0.1" """ # Do not adjust cpu_count, it is reusing a cache client = TestClient(base_folder=self.client.base_folder, cpu_count=False) client.save({CONANFILE: conanfile}) client.run("export . lasote/stable") files = { "conanfile.txt": "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable" } self.client.save(files) self.client.run("install . --build missing --manifests %s" % folder) remote = "local cache" package_reference = PackageReference.loads( "Hello/0.1@lasote/stable:%s" % NO_SETTINGS_PACKAGE_ID) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello2/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello2/0.1@lasote/stable:%s' from %s" % (NO_SETTINGS_PACKAGE_ID, remote), self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, folder) paths = SimplePaths(output_folder) self.assertTrue( os.path.exists( os.path.join(paths.export(self.reference), CONAN_MANIFEST))) self.assertTrue( os.path.exists( os.path.join(paths.package(package_reference), CONAN_MANIFEST)))
def __init__(self, base_path=None, read_permissions=None, write_permissions=None, users=None, base_url=None, plugins=None, server_version=None, min_client_compatible_version=None, server_capabilities=None): plugins = plugins or [] if not base_path: base_path = temp_folder() if server_capabilities is None: server_capabilities = SERVER_CAPABILITIES # Default enabled if not os.path.exists(base_path): raise Exception("Base path not exist! %s") # Define storage_folder, if not, it will be readed from conf file and pointed to real user home self.storage_folder = os.path.join(base_path, ".conan_server", "data") mkdir(self.storage_folder) server_config = migrate_and_get_server_config(base_path, self.storage_folder) if TestServerLauncher.port == 0: TestServerLauncher.port = server_config.port # Encode and Decode signature for Upload and Download service updown_auth_manager = JWTUpDownAuthManager(server_config.updown_secret, server_config.authorize_timeout) self.file_manager = get_file_manager(server_config, public_url=base_url, updown_auth_manager=updown_auth_manager) self.search_manager = DiskSearchManager(SimplePaths(server_config.disk_storage_path)) # Prepare some test users if not read_permissions: read_permissions = server_config.read_permissions read_permissions.append(("private_library/1.0.0@private_user/testing", "*")) read_permissions.append(("*/*@*/*", "*")) if not write_permissions: write_permissions = server_config.write_permissions if not users: users = dict(server_config.users) users[TESTING_REMOTE_PRIVATE_USER] = TESTING_REMOTE_PRIVATE_PASS authorizer = BasicAuthorizer(read_permissions, write_permissions) authenticator = BasicAuthenticator(users) credentials_manager = JWTCredentialsManager(server_config.jwt_secret, server_config.jwt_expire_time) logger.debug("Storage path: %s" % self.storage_folder) self.port = TestServerLauncher.port self.ra = ConanServer(self.port, credentials_manager, updown_auth_manager, authorizer, authenticator, self.file_manager, self.search_manager, server_version, min_client_compatible_version, server_capabilities) for plugin in plugins: self.ra.api_v1.install(plugin)
def __init__(self): user_folder = conan_expand_user("~") server_config = migrate_and_get_server_config(user_folder) authorizer = BasicAuthorizer(server_config.read_permissions, server_config.write_permissions) authenticator = BasicAuthenticator(dict(server_config.users)) credentials_manager = JWTCredentialsManager( server_config.jwt_secret, server_config.jwt_expire_time) updown_auth_manager = JWTUpDownAuthManager( server_config.updown_secret, server_config.authorize_timeout) file_manager = get_file_manager( server_config, updown_auth_manager=updown_auth_manager) search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager( SimplePaths(server_config.disk_storage_path), search_adapter) self.ra = ConanServer(server_config.port, server_config.ssl_enabled, credentials_manager, updown_auth_manager, authorizer, authenticator, file_manager, search_manager, Version(SERVER_VERSION), Version(MIN_CLIENT_COMPATIBLE_VERSION))
def __init__(self): user_folder = conan_expand_user("~") server_folder = os.path.join(user_folder, '.conan_server') server_config = migrate_and_get_server_config(user_folder) custom_auth = server_config.custom_authenticator if custom_auth: authenticator = load_authentication_plugin(server_folder, custom_auth) else: authenticator = BasicAuthenticator(dict(server_config.users)) authorizer = BasicAuthorizer(server_config.read_permissions, server_config.write_permissions) credentials_manager = JWTCredentialsManager( server_config.jwt_secret, server_config.jwt_expire_time) updown_auth_manager = JWTUpDownAuthManager( server_config.updown_secret, server_config.authorize_timeout) file_manager = get_file_manager( server_config, updown_auth_manager=updown_auth_manager) search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager( SimplePaths(server_config.disk_storage_path), search_adapter) server_capabilities = SERVER_CAPABILITIES self.ra = ConanServer(server_config.port, credentials_manager, updown_auth_manager, authorizer, authenticator, file_manager, search_manager, Version(SERVER_VERSION), Version(MIN_CLIENT_COMPATIBLE_VERSION), server_capabilities)
def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.tmp_dir = temp_folder() read_perms = [("*/*@*/*", "*")] write_perms = [] authorizer = BasicAuthorizer(read_perms, write_perms) self.fake_url = "http://url" updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200)) adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager) self.paths = SimplePaths(self.tmp_dir) self.file_manager = FileManager(self.paths, adapter) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(self.paths, search_adapter) self.service = ConanService(authorizer, self.file_manager, "lasote") self.search_service = SearchService(authorizer, self.search_manager, "lasote") files = hello_source_files("test") save_files(self.paths.export(self.conan_reference), files) self.conan_digest = FileTreeManifest.create(self.paths.export(self.conan_reference)) conan_digest_path = os.path.join(self.paths.export(self.conan_reference), CONAN_MANIFEST) save(conan_digest_path, str(self.conan_digest)) files = hello_source_files("package") save_files(self.paths.package(self.package_reference), files)
def setUp(self): folder = temp_folder() paths = SimplePaths(folder) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(paths, search_adapter) os.chdir(paths.store) self.paths = paths
def basic_test(self): folder = temp_folder() paths = SimplePaths(folder) self.assertEqual(paths._store_folder, folder) conan_ref = ConanFileReference.loads("opencv/2.4.10 @ lasote /testing") package_ref = PackageReference(conan_ref, "456fa678eae68") expected_base = os.path.join(folder, os.path.sep.join(["opencv", "2.4.10", "lasote", "testing"])) self.assertEqual(paths.conan(conan_ref), os.path.join(paths.store, expected_base)) self.assertEqual(paths.export(conan_ref), os.path.join(paths.store, expected_base, EXPORT_FOLDER)) self.assertEqual(paths.build(package_ref), os.path.join(paths.store, expected_base, BUILD_FOLDER, "456fa678eae68")) self.assertEqual(paths.package(package_ref), os.path.join(paths.store, expected_base, PACKAGES_FOLDER, "456fa678eae68"))
def test_package_test(self, use_abs_folder): self.client.run("install Hello/0.1@lasote/stable --build missing") conanfile = """from conans import ConanFile class ConsumerFileTest(ConanFile): name = "Chat" version = "0.1" requires = "Hello/0.1@lasote/stable" """ test_conanfile = """from conans import ConanFile class ConsumerFileTest(ConanFile): requires = "Chat/0.1@lasote/stable" def test(self): self.output.info("TEST OK") """ if use_abs_folder: output_folder = temp_folder() dest = '="%s"' % output_folder else: dest = "" output_folder = os.path.join(self.client.current_folder, ".conan_manifests") self.client.save({"conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile}, clean_first=True) self.client.run("create . lasote/stable --manifests%s" % dest) self.assertIn("Chat/0.1@lasote/stable (test package): TEST OK", self.client.user_io.out) self.assertIn("Installed manifest for 'Chat/0.1@lasote/stable' from local cache", self.client.user_io.out) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from local cache", self.client.user_io.out) paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) # now verify self.client.run("create . lasote/stable --verify%s" % dest) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
def _failed_package_verify(self, reference, remote="local cache"): self.client.run("install %s --build missing --manifests" % str(reference)) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, ".conan_manifests") paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client.save(self.files) client.run("export lasote/stable") client.run("install Hello/0.1@lasote/stable --build=missing") info = os.path.join(client.paths.package(package_reference), "conaninfo.txt") info_content = load(info) info_content += "# Dummy string" save(info, info_content) manifest = client.paths.load_package_manifest(package_reference) manifest.file_sums["conaninfo.txt"] = md5(info_content) save(client.paths.digestfile_package(package_reference), str(manifest)) manifest = client.paths.load_package_manifest(package_reference) client.run("upload %s --all" % str(self.reference)) # now verify, with update self.client.run("remove Hello/0.1@lasote/stable -f") self.client.run("install %s --build missing --verify" % str(self.reference), ignore_error=True) self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn("Modified or new manifest '%s' detected" % str(package_reference), self.client.user_io.out)
def _capture_verify_manifest(self, reference, remote="local cache", folder=""): self.client.run("install %s --build missing --manifests %s" % (str(reference), folder)) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn( "Installed manifest for 'Hello/0.1@lasote/stable:" "%s' from %s" % (NO_SETTINGS_PACKAGE_ID, remote), self.client.user_io.out) real_folder = folder or ".conan_manifests" output_folder = os.path.join(self.client.current_folder, real_folder) paths = SimplePaths(output_folder) self.assertTrue( os.path.exists( os.path.join(paths.export(self.reference), CONAN_MANIFEST))) package_reference = PackageReference.loads( "Hello/0.1@lasote/stable:%s" % NO_SETTINGS_PACKAGE_ID) self.assertTrue( os.path.exists( os.path.join(paths.package(package_reference), CONAN_MANIFEST))) # again should do nothing self.client.run("install %s --build missing --manifests %s" % (str(self.reference), folder)) self.assertNotIn("Installed manifest", self.client.user_io.out) # now verify self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder)) self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
def _failed_verify(self, reference, remote="local cache"): self.client.run("install %s --build missing --manifests" % str(reference)) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, ".conan_manifests") paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) conanfile = """from conans import ConanFile class ConanFileTest(ConanFile): name = "Hello" version = "0.1" exports = "*" """ files = {CONANFILE: conanfile, "data.txt": "MyDataHacked"} # Export and upload the conanfile client.save(files) client.run("export lasote/stable") client.run("upload %s --all" % str(self.reference)) # now verify, with update self.client.run("remove Hello/0.1@lasote/stable -f") self.client.run("install %s --build missing --verify" % str(self.reference), ignore_error=True) self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn("Modified or new manifest 'Hello/0.1@lasote/stable' detected", self.client.user_io.out)
def conanfile_capture_verify_manifest_folder_test(self): files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"} self.client.save(files, clean_first=True) folder = "mymanifests" self._capture_verify_manifest(".", folder=folder) conanfile = """from conans import ConanFile class ConanFileTest(ConanFile): name = "Hello2" version = "0.1" """ client = TestClient(base_folder=self.client.base_folder) client.save({CONANFILE: conanfile}) client.run("export lasote/stable") files = {"conanfile.txt": "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable"} self.client.save(files) self.client.run("install . --build missing --manifests %s" % folder) remote = "local cache" package_reference = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out) self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out) self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable' from %s" % remote, self.client.user_io.out) self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote, self.client.user_io.out) output_folder = os.path.join(self.client.current_folder, folder) paths = SimplePaths(output_folder) self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference))) self.assertTrue(os.path.exists(paths.digestfile_package(package_reference))) package_reference = PackageReference.loads("Hello2/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
def get_file_manager(config, public_url=None, updown_auth_manager=None): store_adapter = config.store_adapter if store_adapter == "disk": public_url = public_url or config.public_url disk_controller_url = "%s/%s" % (public_url, "files") if not updown_auth_manager: raise Exception("Updown auth manager needed for disk controller (not s3)") adapter = DiskAdapter(disk_controller_url, config.disk_storage_path, updown_auth_manager) paths = SimplePaths(config.disk_storage_path) else: # Want to develop new adapter? create a subclass of # conans.server.store.file_manager.StorageAdapter and implement the abstract methods raise Exception("Store adapter not implemented! Change 'store_adapter' " "variable in server.conf file to one of the available options: 'disk' ") return FileManager(paths, adapter)
def setUp(self): self.output = TestBufferConanOutput() self.loader = ConanFileLoader(None, Settings.loads(""), Profile()) self.retriever = Retriever(self.loader, self.output) self.remote_search = MockSearchRemote() paths = SimplePaths(self.retriever.folder) self.resolver = RangeResolver(self.output, paths, self.remote_search) self.builder = DepsGraphBuilder(self.retriever, self.output, self.loader, self.resolver) for v in ["0.1", "0.2", "0.3", "1.1", "1.1.2", "1.2.1", "2.1", "2.2.1"]: say_content = """ from conans import ConanFile class SayConan(ConanFile): name = "Say" version = "%s" """ % v say_ref = ConanFileReference.loads("Say/%s@memsharded/testing" % v) self.retriever.conan(say_ref, say_content)
def basic_test(self): folder = temp_folder() paths = SimplePaths(folder) self.assertEqual(paths._store_folder, folder) conan_ref = ConanFileReference.loads("opencv/2.4.10 @ lasote /testing") package_ref = PackageReference(conan_ref, "456fa678eae68") expected_base = os.path.join( folder, os.path.sep.join(["opencv", "2.4.10", "lasote", "testing"])) self.assertEqual(paths.conan(conan_ref), os.path.join(paths.store, expected_base)) self.assertEqual( paths.export(conan_ref), os.path.join(paths.store, expected_base, EXPORT_FOLDER)) self.assertEqual( paths.build(package_ref), os.path.join(paths.store, expected_base, BUILD_FOLDER, "456fa678eae68")) self.assertEqual( paths.package(package_ref), os.path.join(paths.store, expected_base, PACKAGES_FOLDER, "456fa678eae68"))
def setUp(self): folder = temp_folder() paths = SimplePaths(folder) os.chdir(paths.store) self.paths = paths
class ConanServiceTest(unittest.TestCase): def setUp(self): self.conan_reference = ConanFileReference.loads( "openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.tmp_dir = temp_folder() read_perms = [("*/*@*/*", "*")] write_perms = [] authorizer = BasicAuthorizer(read_perms, write_perms) self.fake_url = "http://url" updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200)) adapter = DiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager) self.paths = SimplePaths(self.tmp_dir) self.file_manager = FileManager(self.paths, adapter) self.service = ConanService(authorizer, self.file_manager, "lasote") files = hello_source_files("test") save_files(self.paths.export(self.conan_reference), files) self.conan_digest = FileTreeManifest.create( self.paths.export(self.conan_reference)) conan_digest_path = os.path.join( self.paths.export(self.conan_reference), CONAN_MANIFEST) save(conan_digest_path, str(self.conan_digest)) files = hello_source_files("package") save_files(self.paths.package(self.package_reference), files) def test_get_conanfile_snapshot(self): snap = self.service.get_conanfile_snapshot(self.conan_reference) base_path = self.paths.export(self.conan_reference) snap_expected = { 'hello.cpp': md5sum(os.path.join(base_path, "hello.cpp")), 'conanmanifest.txt': md5sum(os.path.join(base_path, "conanmanifest.txt")), 'main.cpp': md5sum(os.path.join(base_path, "main.cpp")), 'CMakeLists.txt': md5sum(os.path.join(base_path, "CMakeLists.txt")), 'hellotest.h': md5sum(os.path.join(base_path, "hellotest.h")) } self.assertEquals(snap, snap_expected) def test_get_conanfile_download_urls(self): urls = self.service.get_conanfile_download_urls(self.conan_reference) # Remove parameters urls = { name: url.split("?signature")[0] for name, url in urls.iteritems() } def fake_url_build(filename): return self.fake_url + "/" + "/".join( self.conan_reference) + "/export/" + filename expected_urls = { 'CMakeLists.txt': fake_url_build('CMakeLists.txt'), 'conanmanifest.txt': fake_url_build('conanmanifest.txt'), 'hello.cpp': fake_url_build('hello.cpp'), 'hellotest.h': fake_url_build('hellotest.h'), 'main.cpp': fake_url_build('main.cpp') } self.assertEquals(urls, expected_urls) def test_get_package_download_urls(self): urls = self.service.get_package_download_urls(self.package_reference) # Remove parameters urls = { name: url.split("?signature")[0] for name, url in urls.iteritems() } def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.package_reference.conan) \ + "/package/" + self.package_reference.package_id + "/" + filename expected_urls = { 'CMakeLists.txt': fake_url_build('CMakeLists.txt'), 'hello.cpp': fake_url_build('hello.cpp'), 'hellopackage.h': fake_url_build('hellopackage.h'), 'main.cpp': fake_url_build('main.cpp') } self.assertEquals(urls, expected_urls) def test_get_conanfile_upload_urls(self): urls = self.service.get_conanfile_upload_urls(self.conan_reference, { "conanfile.py": 23, "conanmanifest.txt": 24 }) # Remove parameters urls = { name: url.split("?signature")[0] for name, url in urls.iteritems() } def fake_url_build(filename): return self.fake_url + "/" + "/".join( self.conan_reference) + "/export/" + filename expected_urls = { 'conanfile.py': fake_url_build('conanfile.py'), 'conanmanifest.txt': fake_url_build('conanmanifest.txt') } self.assertEquals(urls, expected_urls) def test_get_package_upload_urls(self): urls = self.service.get_package_upload_urls(self.package_reference, { "uno.lib": 23, "dos.dll": 24 }) # Remove parameters urls = { name: url.split("?signature")[0] for name, url in urls.iteritems() } def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.package_reference.conan) \ + "/package/" + self.package_reference.package_id + "/" + filename expected_urls = { 'uno.lib': fake_url_build('uno.lib'), 'dos.dll': fake_url_build('dos.dll') } self.assertEquals(urls, expected_urls) def test_search(self): """ check the dict is returned by get_packages_info service """ # Creating and saving conans, packages, and conans.vars conan_ref2 = ConanFileReference("openssl", "3.0", "lasote", "stable") conan_ref3 = ConanFileReference("Assimp", "1.10", "fenix", "stable") conan_ref4 = ConanFileReference("assimpFake", "0.1", "phil", "stable") package_ref2 = PackageReference(conan_ref2, "12345587754") package_ref3 = PackageReference(conan_ref3, "77777777777") conan_vars = """ [options] use_Qt=%s """ conan_vars1 = conan_vars % "True" conan_vars2 = conan_vars % "False" conan_vars3 = conan_vars % "True" save_files(self.paths.package(self.package_reference), {CONANINFO: conan_vars1}) save_files(self.paths.package(package_ref2), {CONANINFO: conan_vars2}) save_files(self.paths.package(package_ref3), {CONANINFO: conan_vars3}) save_files(self.paths.export(conan_ref4), {"dummy.txt": "//"}) info = self.service.search() expected = { self.conan_reference: { "123123123": ConanInfo.loads("[options]\nuse_Qt=True") }, conan_ref2: { "12345587754": ConanInfo.loads("[options]\nuse_Qt=False") }, conan_ref3: { "77777777777": ConanInfo.loads("[options]\nuse_Qt=True") }, conan_ref4: {} } self.assertEqual(expected, info) info = self.service.search(pattern="Assimp*", ignorecase=False) self.assertEqual(info, { conan_ref3: { "77777777777": ConanInfo.loads("[options]\nuse_Qt=True") } }) def remove_test(self): conan_ref2 = ConanFileReference("OpenCV", "3.0", "lasote", "stable") conan_ref3 = ConanFileReference("Assimp", "1.10", "lasote", "stable") package_ref2 = PackageReference(conan_ref2, "12345587754") package_ref3 = PackageReference(conan_ref3, "77777777777") save_files(self.paths.export(conan_ref2), {"fake.txt": "//fake"}) save_files(self.paths.package(package_ref2), {"fake.txt": "//fake"}) save_files(self.paths.package(package_ref3), {"fake.txt": "//fake"}) # Delete all the conans folder self.service.remove_conanfile(self.conan_reference) conan_path = self.paths.conan(self.conan_reference) self.assertFalse(os.path.exists(conan_path)) # Delete one package self.service.remove_packages(conan_ref3, ["77777777777"]) package_folder_3 = self.paths.package( PackageReference(conan_ref3, '077777777777')) self.assertFalse(os.path.exists(package_folder_3)) # Raise an exception self.assertRaises( NotFoundException, self.service.remove_conanfile, ConanFileReference("Fake", "1.0", "lasote", "stable"))
def testCopier(self): output = TestBufferConanOutput() userio = MockedBooleanUserIO(True, out=output) paths = SimplePaths(temp_folder()) copier = PackageCopier(paths, userio) # Create some packages to copy reference = ConanFileReference.loads("Hello/0.1@lasote/testing") self._create_conanfile(reference, paths) self._create_package(reference, "0101001", paths) self._create_package(reference, "2222222", paths) # Copy all to destination copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) new_reference = ConanFileReference.loads("Hello/0.1@lasote/stable") self._assert_conanfile_exists(new_reference, paths) self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_exists(new_reference, "2222222", paths) self.assertIn("Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Copy again, without force and answering yes output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) self.assertIn("Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) self.assertIn("'Hello/0.1@lasote/stable' already exist. Override?", output) self.assertIn("Package '2222222' already exist. Override?", output) self.assertIn("Package '0101001' already exist. Override?", output) # Now alter the origin and copy again to same destination and confirm the copy self._create_conanfile(reference, paths, "new content") self._create_package(reference, "0101001", paths, "new lib content") self._create_package(reference, "2222222", paths, "new lib content") output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) conanfile_content = load(os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") package_content = load(os.path.join(paths.package(PackageReference(new_reference, "0101001")), "package.lib")) self.assertEquals(package_content, "new lib content") # Now we are going to answer always NO to override output._stream.truncate(0) # Reset output userio = MockedBooleanUserIO(False, out=output) copier = PackageCopier(paths, userio) self._create_conanfile(reference, paths, "content22") self._create_package(reference, "0101001", paths, "newlib22") self._create_package(reference, "2222222", paths, "newlib22") copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) conanfile_content = load(os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") # Not content22 p_ref = PackageReference(new_reference, "0101001") package_content = load(os.path.join(paths.package(p_ref), "package.lib")) self.assertEquals(package_content, "new lib content") # Not newlib22 # If conanfile is not override it exist self.assertNotIn("Package '2222222' already exist. Override?", output) self.assertNotIn("Package '0101001' already exist. Override?", output) self.assertNotIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertNotIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now override output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=True) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now copy just one package to another user/channel output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001"], "pepe", "mychannel", force=True) self.assertIn("Copied 0101001 to Hello/0.1@pepe/mychannel", output) self.assertNotIn("Copied 2222222 to Hello/0.1@pepe/mychannel", output) new_reference = ConanFileReference.loads("Hello/0.1@pepe/mychannel") self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_doesnt_exists(new_reference, "2222222", paths)
class ManifestManager(object): def __init__(self, folder, user_io, client_cache, verify=False, interactive=False): if verify and not os.path.exists(folder): raise ConanException("Manifest folder does not exist: %s" % folder) self._paths = SimplePaths(folder) self._user_io = user_io self._client_cache = client_cache self._verify = verify self._interactive = interactive self._log = [] def print_log(self): self._user_io.out.success("\nManifests : %s" % (self._paths.store)) for log_entry in self._log: self._user_io.out.info(log_entry) def _handle_add(self, reference, remote, manifest, pkg_folder): # query the user for approval if self._interactive: ok = self._user_io.request_boolean( "Installing %s from %s\n" "Do you trust it?" % (str(reference), remote), True) else: ok = True if ok: manifest.save(pkg_folder) self._log.append("Installed manifest for '%s' from %s" % (str(reference), remote)) else: raise ConanException("Installation of '%s' rejected!" % str(reference)) def _check(self, reference, manifest, remote, pkg_folder): if os.path.exists(pkg_folder): existing_manifest = FileTreeManifest.load(pkg_folder) if existing_manifest == manifest: self._log.append("Manifest for '%s': OK" % str(reference)) return if self._verify: diff = existing_manifest.difference(manifest) error_msg = os.linesep.join( "Mismatched checksum '%s' (manifest: %s, file: %s)" % (fname, h1, h2) for fname, (h1, h2) in diff.items()) raise ConanException( "Modified or new manifest '%s' detected.\n" "Remote: %s\nProject manifest doesn't match installed one\n%s" % (str(reference), remote, error_msg)) self._handle_add(reference, remote, manifest, pkg_folder) def _match_manifests(self, read_manifest, expected_manifest, reference): if read_manifest is None or read_manifest != expected_manifest: raise ConanException("%s local cache package is corrupted: " "some file hash doesn't match manifest" % (str(reference))) def check_recipe(self, conan_reference, remote): manifests = self._client_cache.conan_manifests(conan_reference) read_manifest, expected_manifest = manifests remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url) self._match_manifests(read_manifest, expected_manifest, conan_reference) path = self._paths.export(conan_reference) self._check(conan_reference, read_manifest, remote, path) def check_package(self, package_reference, remote): manifests = self._client_cache.package_manifests(package_reference) read_manifest, expected_manifest = manifests remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url) self._match_manifests(read_manifest, expected_manifest, package_reference) pkg_folder = self._paths.package(package_reference, short_paths=None) self._check(package_reference, read_manifest, remote, pkg_folder)
class ManifestManager(object): def __init__(self, folder, user_io, client_cache, verify=False, interactive=False): if verify and not os.path.exists(folder): raise ConanException("Manifest folder does not exist: %s" % folder) self._paths = SimplePaths(folder) self._user_io = user_io self._client_cache = client_cache self._verify = verify self._interactive = interactive self._log = [] def print_log(self): self._user_io.out.success("\nManifests") for log_entry in self._log: self._user_io.out.info(log_entry) def _handle_add(self, reference, remote, manifest, path): # query the user for approval if self._interactive: ok = self._user_io.request_boolean("Installing %s from %s\n" "Do you trust it?" % (str(reference), remote), True) else: ok = True if ok: save(path, str(manifest)) self._log.append("Installed manifest for '%s' from %s" % (str(reference), remote)) else: raise ConanException("Installation of '%s' rejected!" % str(reference)) def _check(self, reference, manifest, remote, path): if os.path.exists(path): existing_manifest = FileTreeManifest.loads(load(path)) if existing_manifest.file_sums == manifest.file_sums: self._log.append("Manifest for '%s': OK" % str(reference)) return if self._verify: raise ConanException("Modified or new manifest '%s' detected.\n" "Remote: %s\nProject manifest doesn't match installed one" % (str(reference), remote)) self._handle_add(reference, remote, manifest, path) def _match_manifests(self, read_manifest, expected_manifest, reference): if read_manifest is None or read_manifest.file_sums != expected_manifest.file_sums: raise ConanException("%s local cache package is corrupted: " "some file hash doesn't match manifest" % (str(reference))) def check_recipe(self, conan_reference, remote): manifests = self._client_cache.conan_manifests(conan_reference) read_manifest, expected_manifest = manifests remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url) self._match_manifests(read_manifest, expected_manifest, conan_reference) path = self._paths.digestfile_conanfile(conan_reference) self._check(conan_reference, read_manifest, remote, path) def check_package(self, package_reference, remote): manifests = self._client_cache.package_manifests(package_reference) read_manifest, expected_manifest = manifests remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url) self._match_manifests(read_manifest, expected_manifest, package_reference) path = self._paths.digestfile_package(package_reference, short_paths=None) self._check(package_reference, read_manifest, remote, path)
def testCopier(self): output = TestBufferConanOutput() userio = MockedBooleanUserIO(True, out=output) paths = SimplePaths(temp_folder()) copier = PackageCopier(paths, userio) # Create some packages to copy reference = ConanFileReference.loads("Hello/0.1@lasote/testing") self._create_conanfile(reference, paths) self._create_package(reference, "0101001", paths) self._create_package(reference, "2222222", paths) # Copy all to destination copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) new_reference = ConanFileReference.loads("Hello/0.1@lasote/stable") self._assert_conanfile_exists(new_reference, paths) self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_exists(new_reference, "2222222", paths) self.assertIn( "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Copy again, without force and answering yes output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) self.assertIn( "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) self.assertIn("'Hello/0.1@lasote/stable' already exist. Override?", output) self.assertIn("Package '2222222' already exist. Override?", output) self.assertIn("Package '0101001' already exist. Override?", output) # Now alter the origin and copy again to same destination and confirm the copy self._create_conanfile(reference, paths, "new content") self._create_package(reference, "0101001", paths, "new lib content") self._create_package(reference, "2222222", paths, "new lib content") output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) conanfile_content = load( os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") package_content = load( os.path.join( paths.package(PackageReference(new_reference, "0101001")), "package.lib")) self.assertEquals(package_content, "new lib content") # Now we are going to answer always NO to override output._stream.truncate(0) # Reset output userio = MockedBooleanUserIO(False, out=output) copier = PackageCopier(paths, userio) self._create_conanfile(reference, paths, "content22") self._create_package(reference, "0101001", paths, "newlib22") self._create_package(reference, "2222222", paths, "newlib22") copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=False) conanfile_content = load( os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") # Not content22 p_ref = PackageReference(new_reference, "0101001") package_content = load( os.path.join(paths.package(p_ref), "package.lib")) self.assertEquals(package_content, "new lib content") # Not newlib22 # If conanfile is not override it exist self.assertNotIn("Package '2222222' already exist. Override?", output) self.assertNotIn("Package '0101001' already exist. Override?", output) self.assertNotIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertNotIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now override output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001", "2222222"], "lasote", "stable", force=True) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now copy just one package to another user/channel output._stream.truncate(0) # Reset output copier.copy(reference, ["0101001"], "pepe", "mychannel", force=True) self.assertIn("Copied 0101001 to Hello/0.1@pepe/mychannel", output) self.assertNotIn("Copied 2222222 to Hello/0.1@pepe/mychannel", output) new_reference = ConanFileReference.loads("Hello/0.1@pepe/mychannel") self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_doesnt_exists(new_reference, "2222222", paths)
def basic_test2(self): folder = temp_folder() paths = SimplePaths(folder) search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(paths, search_adapter) os.chdir(paths.store) root_folder1 = "opencv/2.4.10/lasote/testing" conan_ref1 = ConanFileReference.loads("opencv/2.4.10@lasote/testing") artif_id1 = "awqfwf44we5f425fw" artif_id2 = "b5wc4q5frg45rgv1g" artif_id3 = "cf838regrg783g453" reg1 = "%s/%s" % (root_folder1, EXPORT_FOLDER) build1 = "%s/%s/%s" % (root_folder1, BUILD_FOLDER, artif_id1) artif1 = "%s/%s/%s" % (root_folder1, PACKAGES_FOLDER, artif_id1) artif2 = "%s/%s/%s" % (root_folder1, PACKAGES_FOLDER, artif_id2) artif3 = "%s/%s/%s" % (root_folder1, PACKAGES_FOLDER, artif_id3) os.makedirs(reg1) os.makedirs(build1) os.makedirs(artif1) os.makedirs(artif2) os.makedirs(artif3) for package_path in [artif1, artif2, artif3]: info = ConanInfo().loads("[settings]\n[options]") save(os.path.join(paths.store, package_path, CONANINFO), info.dumps()) packages = search_manager.search_packages(conan_ref1, "") all_artif = [_artif for _artif in sorted(packages)] self.assertEqual(all_artif, [artif_id1, artif_id2, artif_id3]) root_folder2 = "sdl/1.5/lasote/stable" conan_ref2 = ConanFileReference.loads("sdl/1.5@lasote/stable") os.makedirs("%s/%s" % (root_folder2, EXPORT_FOLDER)) root_folder3 = "assimp/0.14/phil/testing" conan_ref3 = ConanFileReference.loads("assimp/0.14@phil/testing") os.makedirs("%s/%s" % (root_folder3, EXPORT_FOLDER)) root_folder4 = "sdl/2.10/lasote/stable" conan_ref4 = ConanFileReference.loads("sdl/2.10@lasote/stable") os.makedirs("%s/%s" % (root_folder4, EXPORT_FOLDER)) root_folder5 = "SDL_fake/1.10/lasote/testing" conan_ref5 = ConanFileReference.loads("SDL_fake/1.10@lasote/testing") os.makedirs("%s/%s" % (root_folder5, EXPORT_FOLDER)) # Case insensitive searches search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(paths, search_adapter) reg_conans = sorted([str(_reg) for _reg in search_manager.search("*")]) self.assertEqual(reg_conans, [ str(conan_ref5), str(conan_ref3), str(conan_ref1), str(conan_ref2), str(conan_ref4) ]) reg_conans = sorted( [str(_reg) for _reg in search_manager.search(pattern="sdl*")]) self.assertEqual(reg_conans, [str(conan_ref5), str(conan_ref2), str(conan_ref4)]) # Case sensitive search self.assertEqual( str(search_manager.search(pattern="SDL*", ignorecase=False)[0]), str(conan_ref5))
class ManifestManager(object): def __init__(self, folder, user_io, client_cache): self._paths = SimplePaths(folder) self._user_io = user_io self._client_cache = client_cache self._log = [] def check_graph(self, graph, verify, interactive): if verify and not os.path.exists(self._paths.store): raise ConanException("Manifest folder does not exist: %s" % self._paths.store) levels = graph.by_levels() for level in levels: for node in level: ref = node.conan_ref if not ref: continue self._handle_recipe(node, verify, interactive) self._handle_package(node, verify, interactive) def _handle_recipe(self, node, verify, interactive): ref = node.conan_ref export = self._client_cache.export(ref) exports_sources_folder = self._client_cache.export_sources(ref) read_manifest = FileTreeManifest.load(export) expected_manifest = FileTreeManifest.create(export, exports_sources_folder) self._check_not_corrupted(ref, read_manifest, expected_manifest) folder = self._paths.export(ref) self._handle_folder(folder, ref, read_manifest, interactive, node.remote, verify) def _handle_package(self, node, verify, interactive): ref = node.conan_ref ref = PackageReference(ref, node.conanfile.info.package_id()) package_folder = self._client_cache.package(ref) read_manifest = FileTreeManifest.load(package_folder) expected_manifest = FileTreeManifest.create(package_folder) self._check_not_corrupted(ref, read_manifest, expected_manifest) folder = self._paths.package(ref) self._handle_folder(folder, ref, read_manifest, interactive, node.remote, verify) def _handle_folder(self, folder, ref, read_manifest, interactive, remote, verify): remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url) if os.path.exists(folder): self._handle_manifest(ref, folder, read_manifest, interactive, remote, verify) else: if verify: raise ConanException( "New manifest '%s' detected.\n" "Remote: %s\nProject manifest doesn't match installed one" % (str(ref), remote)) else: self._check_accept_install(interactive, ref, remote) self._log.append("Installed manifest for '%s' from %s" % (str(ref), remote)) read_manifest.save(folder) def _check_accept_install(self, interactive, ref, remote): if (interactive and not self._user_io.request_boolean( "Installing %s from %s\n" "Do you trust it?" % (str(ref), remote), True)): raise ConanException("Installation of '%s' rejected!" % str(ref)) @staticmethod def _check_not_corrupted(ref, read_manifest, expected_manifest): if read_manifest != expected_manifest: raise ConanException("%s local cache package is corrupted: " "some file hash doesn't match manifest" % (str(ref))) def _handle_manifest(self, ref, folder, read_manifest, interactive, remote, verify): captured_manifest = FileTreeManifest.load(folder) if captured_manifest == read_manifest: self._log.append("Manifest for '%s': OK" % str(ref)) elif verify: diff = captured_manifest.difference(read_manifest) error_msg = os.linesep.join( "Mismatched checksum '%s' (manifest: %s, file: %s)" % (fname, h1, h2) for fname, (h1, h2) in diff.items()) raise ConanException( "Modified or new manifest '%s' detected.\n" "Remote: %s\nProject manifest doesn't match installed one\n%s" % (str(ref), remote, error_msg)) else: self._check_accept_install(interactive, ref, remote) self._log.append("Installed manifest for '%s' from %s" % (str(ref), remote)) read_manifest.save(folder) def print_log(self): self._user_io.out.success("\nManifests : %s" % (self._paths.store)) for log_entry in self._log: self._user_io.out.info(log_entry)
def __init__(self, folder, user_io, client_cache): self._paths = SimplePaths(folder) self._user_io = user_io self._client_cache = client_cache self._log = []
class ConanServiceTest(unittest.TestCase): def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.tmp_dir = temp_folder() read_perms = [("*/*@*/*", "*")] write_perms = [] authorizer = BasicAuthorizer(read_perms, write_perms) self.fake_url = "http://url" updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200)) adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager) self.paths = SimplePaths(self.tmp_dir) self.file_manager = FileManager(self.paths, adapter) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(self.paths, search_adapter) self.service = ConanService(authorizer, self.file_manager, "lasote") self.search_service = SearchService(authorizer, self.search_manager, "lasote") files = hello_source_files("test") save_files(self.paths.export(self.conan_reference), files) self.conan_digest = FileTreeManifest.create(self.paths.export(self.conan_reference)) conan_digest_path = os.path.join(self.paths.export(self.conan_reference), CONAN_MANIFEST) save(conan_digest_path, str(self.conan_digest)) files = hello_source_files("package") save_files(self.paths.package(self.package_reference), files) def test_get_conanfile_snapshot(self): snap = self.service.get_conanfile_snapshot(self.conan_reference) base_path = self.paths.export(self.conan_reference) snap_expected = {'hello.cpp': md5sum(os.path.join(base_path, "hello.cpp")), 'conanmanifest.txt': md5sum(os.path.join(base_path, "conanmanifest.txt")), 'executable': md5sum(os.path.join(base_path, "executable")), 'main.cpp': md5sum(os.path.join(base_path, "main.cpp")), 'CMakeLists.txt': md5sum(os.path.join(base_path, "CMakeLists.txt")), 'hellotest.h': md5sum(os.path.join(base_path, "hellotest.h"))} self.assertEquals(snap, snap_expected) def test_get_conanfile_download_urls(self): urls = self.service.get_conanfile_download_urls(self.conan_reference) # Remove parameters urls = {name: url.split("?signature")[0] for name, url in urls.items()} def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.conan_reference) + "/export/" + filename expected_urls = {'CMakeLists.txt': fake_url_build('CMakeLists.txt'), 'conanmanifest.txt': fake_url_build('conanmanifest.txt'), 'executable': fake_url_build('executable'), 'hello.cpp': fake_url_build('hello.cpp'), 'hellotest.h': fake_url_build('hellotest.h'), 'main.cpp': fake_url_build('main.cpp')} self.assertEquals(urls, expected_urls) def test_get_package_download_urls(self): urls = self.service.get_package_download_urls(self.package_reference) # Remove parameters urls = {name: url.split("?signature")[0] for name, url in urls.items()} def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.package_reference.conan) \ + "/package/" + self.package_reference.package_id + "/" + filename expected_urls = {'CMakeLists.txt': fake_url_build('CMakeLists.txt'), 'executable': fake_url_build('executable'), 'hello.cpp': fake_url_build('hello.cpp'), 'hellopackage.h': fake_url_build('hellopackage.h'), 'main.cpp': fake_url_build('main.cpp')} self.assertEquals(urls, expected_urls) def test_get_conanfile_upload_urls(self): urls = self.service.get_conanfile_upload_urls(self.conan_reference, {"conanfile.py": 23, "conanmanifest.txt": 24}) # Remove parameters urls = {name: url.split("?signature")[0] for name, url in urls.items()} def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.conan_reference) + "/export/" + filename expected_urls = {'conanfile.py': fake_url_build('conanfile.py'), 'conanmanifest.txt': fake_url_build('conanmanifest.txt')} self.assertEquals(urls, expected_urls) def test_get_package_upload_urls(self): urls = self.service.get_package_upload_urls(self.package_reference, {"uno.lib": 23, "dos.dll": 24}) # Remove parameters urls = {name: url.split("?signature")[0] for name, url in urls.items()} def fake_url_build(filename): return self.fake_url + "/" + "/".join(self.package_reference.conan) \ + "/package/" + self.package_reference.package_id + "/" + filename expected_urls = {'uno.lib': fake_url_build('uno.lib'), 'dos.dll': fake_url_build('dos.dll')} self.assertEquals(urls, expected_urls) def test_search(self): """ check the dict is returned by get_packages_info service """ # Creating and saving conans, packages, and conans.vars conan_ref2 = ConanFileReference("openssl", "3.0", "lasote", "stable") conan_ref3 = ConanFileReference("Assimp", "1.10", "fenix", "stable") conan_ref4 = ConanFileReference("assimpFake", "0.1", "phil", "stable") package_ref2 = PackageReference(conan_ref2, "12345587754") package_ref3 = PackageReference(conan_ref3, "77777777777") conan_vars = """ [options] use_Qt=%s """ conan_vars1 = conan_vars % "True" conan_vars2 = conan_vars % "False" conan_vars3 = conan_vars % "True" save_files(self.paths.package(self.package_reference), {CONANINFO: conan_vars1}) save_files(self.paths.package(package_ref2), {CONANINFO: conan_vars2}) save_files(self.paths.package(package_ref3), {CONANINFO: conan_vars3}) save_files(self.paths.export(conan_ref4), {"dummy.txt": "//"}) info = self.search_service.search() expected = [conan_ref3, conan_ref4, self.conan_reference, conan_ref2] self.assertEqual(expected, info) info = self.search_service.search(pattern="Assimp*", ignorecase=False) self.assertEqual(info, [conan_ref3]) info = self.search_service.search_packages(conan_ref2, None) self.assertEqual(info, {'12345587754': {'full_requires': [], 'options': {'use_Qt': 'False'}, 'settings': {}, 'recipe_hash': None}}) info = self.search_service.search_packages(conan_ref3, None) self.assertEqual(info, {'77777777777': {'full_requires': [], 'options': {'use_Qt': 'True'}, 'settings': {}, 'recipe_hash': None}}) def remove_test(self): conan_ref2 = ConanFileReference("OpenCV", "3.0", "lasote", "stable") conan_ref3 = ConanFileReference("Assimp", "1.10", "lasote", "stable") package_ref2 = PackageReference(conan_ref2, "12345587754") package_ref3 = PackageReference(conan_ref3, "77777777777") save_files(self.paths.export(conan_ref2), {"fake.txt": "//fake"}) save_files(self.paths.package(package_ref2), {"fake.txt": "//fake"}) save_files(self.paths.package(package_ref3), {"fake.txt": "//fake"}) # Delete all the conans folder self.service.remove_conanfile(self.conan_reference) conan_path = self.paths.conan(self.conan_reference) self.assertFalse(os.path.exists(conan_path)) # Delete one package self.service.remove_packages(conan_ref3, ["77777777777"]) package_folder_3 = self.paths.package(PackageReference(conan_ref3, '077777777777')) self.assertFalse(os.path.exists(package_folder_3)) # Raise an exception self.assertRaises(NotFoundException, self.service.remove_conanfile, ConanFileReference("Fake", "1.0", "lasote", "stable"))