Ejemplo n.º 1
0
    def main(self):
        """Execution starts here"""
        exe_path = self.env.get("exe_path", self.env.get("pathname"))
        version_string = self.env.get("version_string", "ProductVersion:")
        version_first = self.verify_value_boolean(
            self.env.get("version_first", False))
        verbosity = self.env.get("verbose", 0)
        ignore_errors = self.env.get("ignore_errors", True)
        extract_flag = "l"

        self.verify_file_exists(exe_path)

        if is_windows():
            sevenzip_path = self.env.get("sevenzip_path",
                                         r"C:\Program Files\7-Zip\7z.exe")
        else:
            sevenzip_path = self.env.get("sevenzip_path", "/usr/local/bin/7z")

        self.verify_file_exists(sevenzip_path)

        self.output("Extracting: %s" % exe_path)
        cmd = [sevenzip_path, extract_flag, "-y", exe_path]

        self.output(f"Command Line: {cmd}", 2)

        try:
            if verbosity > 1:
                Output = subprocess.check_output(cmd)
            else:
                Output = subprocess.check_output(cmd)
        except BaseException:
            if ignore_errors != "True":
                raise

        self.output(f"Output: \n{Output}\n", 6)

        archiveVersion = ""
        # it is possible the encoding should only be treated as utf8
        #   if ascii option throws errors
        # https://stackoverflow.com/a/50627018/861745
        for line in Output.decode(encoding="utf8",
                                  errors="ignore").split("\n"):
            if verbosity > 2:
                print(line)
            if version_string in line:
                archiveVersion = line.split()[-1]
                if version_first:
                    break
                continue

        # for version numbers, this encode as ascii makes sense
        # for text, this might not make sense
        archive_version_ascii_only = archiveVersion.encode("ascii",
                                                           "ignore").decode()
        self.env["version"] = archive_version_ascii_only
        self.output("Found Version: %s" % (self.env["version"]))
Ejemplo n.º 2
0
 def test_is_windows_returns_false_on_not_windows(self, mock_platform):
     """On not-Windows, is_windows() should return False."""
     mock_platform.return_value = "Darwin-somethingsomething"
     result = autopkglib.is_windows()
     self.assertEqual(result, False)
Ejemplo n.º 3
0
 def test_is_windows_returns_true_on_windows(self, mock_platform):
     """On Windows, is_windows() should return True."""
     mock_platform.return_value = "Windows-somethingsomething"
     result = autopkglib.is_windows()
     self.assertEqual(result, True)