Esempio n. 1
0
    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(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)))

        # 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)
Esempio n. 2
0
    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)))
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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 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)))
Esempio n. 7
0
 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"))
Esempio n. 8
0
 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"))
Esempio n. 9
0
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)
    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)
Esempio n. 11
0
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)
Esempio n. 12
0
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"))
Esempio n. 13
0
    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)
Esempio n. 14
0
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"))