Пример #1
0
    def test_invalid_flat(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            # Not a single dir containing everything
            file1 = os.path.join(tmp_folder, "subfolder-1.2.3", "folder2",
                                 "file1")
            file2 = os.path.join(tmp_folder, "other-1.2.3", "folder", "file2")

            save(file1, "")
            save(file2, "")

        zip_folder = temp_folder()
        zip_file = os.path.join(zip_folder, "file.zip")
        self._zipdir(tmp_folder, zip_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(
                self, ConanException,
                "The zip file contains more than 1 folder "
                "in the root"):
            unzip(zip_file,
                  destination=extract_folder,
                  strip_root=True,
                  output=Mock())
Пример #2
0
    def build(self):

        download_url = "https://cmake.org/files/v{}/{}".format(
            self.cmake_major_minor, self.cmake_zip_name)
        self.output.warn("Downloading '{}'...".format(download_url))
        tools.download(download_url, self.cmake_zip_name)
        tools.unzip(self.cmake_zip_name)
        os.unlink(self.cmake_zip_name)
Пример #3
0
 def source(self):
     zip_name = f"bzip2-{self.version}.tar.gz"
     url = f"https://bintray.com/conan/Sources/download_file?" \
           f"file_path={zip_name}"
     download(url, zip_name)
     check_md5(zip_name, "00b516f4704d4a7cb50a1d97e6e8e15b")
     unzip(zip_name)
     os.unlink(zip_name)
Пример #4
0
 def source(self):
     zip_name = "zlib-%s.tar.gz" % self.version
     tools.download(
         "http://downloads.sourceforge.net/project/libpng/zlib/%s/%s" %
         (self.version, zip_name), zip_name)
     tools.unzip(zip_name)
     os.unlink(zip_name)
     files.rmdir("%s/contrib" % self.ZIP_FOLDER_NAME)
     if self.settings.os != "Windows":
         self.run("chmod +x ./%s/configure" % self.ZIP_FOLDER_NAME)
Пример #5
0
 def get_version(suffix):
     nasm_zip_name = "%s-%s.zip" % (self.nasm_folder_name, suffix)
     tools.download(
         "http://www.nasm.us/pub/nasm/releasebuilds/"
         "%s/%s/%s" % (self.version, suffix, nasm_zip_name),
         nasm_zip_name)
     self.output.warn("Downloading nasm: "
                      "http://www.nasm.us/pub/nasm/releasebuilds"
                      "/%s/%s/%s" %
                      (self.version, suffix, nasm_zip_name))
     tools.unzip(nasm_zip_name)
     os.unlink(nasm_zip_name)
Пример #6
0
    def test_invalid_flat_single_file(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            save("file1", "contentsfile1")

        zip_folder = temp_folder()
        zip_file = os.path.join(zip_folder, "file.zip")
        self._zipdir(tmp_folder, zip_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(self, ConanException, "The zip file contains a file in the root"):
            unzip(zip_file, destination=extract_folder, strip_root=True)
Пример #7
0
    def test_invalid_flat_single_file(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            save("file1", "contentsfile1")

        zip_folder = temp_folder()
        tgz_file = os.path.join(zip_folder, "file.tar.gz")
        self._compress_folder(tmp_folder, tgz_file)

        # Extract without the subfolder
        extract_folder = temp_folder()
        with six.assertRaisesRegex(self, ConanException, "The tgz file contains a file in the root"):
            unzip(tgz_file, destination=extract_folder, strip_root=True, output=Mock())
Пример #8
0
    def test_plain_zip(self):
        tmp_folder = temp_folder()
        with chdir(tmp_folder):
            ori_files_dir = os.path.join(tmp_folder, "subfolder-1.2.3")
            file1 = os.path.join(ori_files_dir, "file1")
            file2 = os.path.join(ori_files_dir, "folder", "file2")
            file3 = os.path.join(ori_files_dir, "file3")

            save(file1, "")
            save(file2, "")
            save(file3, "")

        zip_file = os.path.join(tmp_folder, "myzip.zip")
        # Zip with a "folder_entry" in the zip (not only for the files)
        self._zipdir(tmp_folder, zip_file, folder_entry="subfolder-1.2.3")

        # ZIP unzipped regularly
        extract_folder = temp_folder()
        output = TestBufferConanOutput()
        unzip(zip_file,
              destination=extract_folder,
              strip_root=False,
              output=output)
        self.assertNotIn("ERROR: Error extract", output)
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "file1")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "folder",
                             "file2")))
        self.assertTrue(
            os.path.exists(
                os.path.join(extract_folder, "subfolder-1.2.3", "file3")))

        # Extract without the subfolder
        extract_folder = temp_folder()
        output = TestBufferConanOutput()
        unzip(zip_file,
              destination=extract_folder,
              strip_root=True,
              output=output)
        self.assertNotIn("ERROR: Error extract", output)
        self.assertFalse(
            os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3")))
        self.assertTrue(os.path.exists(os.path.join(extract_folder, "file1")))
        self.assertTrue(
            os.path.exists(os.path.join(extract_folder, "folder", "file2")))
        self.assertTrue(os.path.exists(os.path.join(extract_folder, "file3")))
Пример #9
0
 def test_untar(self):
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "example.txt")
     save(file_path, "Hello world!")
     tar_path = os.path.join(tmp_dir, "sample.tar")
     try:
         old_path = os.getcwd()
         os.chdir(tmp_dir)
         import tarfile
         tar = tarfile.open(tar_path, "w")
         tar.add("example.txt")
         tar.close()
     finally:
         os.chdir(old_path)
     output_dir = os.path.join(tmp_dir, "output_dir")
     tools.unzip(tar_path, output_dir, output=ConanOutput(stream=sys.stdout))
     content = load(os.path.join(output_dir, "example.txt"))
     self.assertEqual(content, "Hello world!")
Пример #10
0
    def test_short_paths_unzip_output(self):
        if platform.system() != "Windows":
            return
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "src/"*40, "example.txt")
        save(file_path, "Hello world!")

        zip_path = os.path.join(tmp_dir, 'example.zip')
        zipf = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
        for root, _, files in os.walk(tmp_dir):
            for f in files:
                zipf.write(os.path.join(root, f), os.path.join("src/"*20, f))
        zipf.close()

        output_dir = os.path.join(tmp_dir, "dst/"*40, "output_dir")
        new_out = six.StringIO()
        tools.unzip(zip_path, output_dir, output=ConanOutput(new_out))

        output = new_out.getvalue()
        self.assertIn("ERROR: Error extract src/src", output)
Пример #11
0
    def test_unzip_output(self):
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "example.txt")
        save(file_path, "Hello world!")

        zip_path = os.path.join(tmp_dir, 'example.zip')
        zipf = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
        for root, _, files in os.walk(tmp_dir):
            for f in files:
                zipf.write(os.path.join(root, f), f)
        zipf.close()

        output_dir = os.path.join(tmp_dir, "output_dir")
        new_out = six.StringIO()
        tools.unzip(zip_path, output_dir, output=ConanOutput(new_out))

        output = new_out.getvalue()
        six.assertRegex(self, output, "Unzipping [\d]+B")
        content = load(os.path.join(output_dir, "example.txt"))
        self.assertEqual(content, "Hello world!")
Пример #12
0
 def build(self):
     download_url = "http://releases.llvm.org/{}/{}".format(self.version, self.clang_zip_name)
     self.output.warn("Downloading '{}'...".format(download_url))
     tools.download(download_url, self.clang_zip_name)
     tools.unzip(self.clang_zip_name)
     os.unlink(self.clang_zip_name)
Пример #13
0
 def source(self):
     tar_file = f"v{self.version}.tar.gz"
     download(f"{self.url}/archive/{tar_file}", tar_file)
     unzip(tar_file)
     os.unlink(tar_file)
     shutil.move("imgui-{}".format(self.version), "imgui")