def __TryValidateCommandVersion(self, cmd: str, versionCommand: str,
                                    versionRegEx: str,
                                    minVersion: str) -> bool:
        output = ""
        try:
            runCmd = [cmd, versionCommand]
            with subprocess.Popen(runCmd,
                                  stderr=subprocess.STDOUT,
                                  stdout=subprocess.PIPE,
                                  universal_newlines=True) as proc:
                output = proc.stdout.read().strip()
                proc.stdout.close()
                result = proc.wait()
                if result != 0:
                    self.__BasicConfig.LogPrintWarning(
                        "The command '{0}' failed with '{1}'".format(
                            " ".join(runCmd), result))
                    return False
        except FileNotFoundError:
            self.__BasicConfig.DoPrintWarning(
                "The command '{0}' failed with 'file not found'.".format(
                    " ".join(runCmd)))
            return False

        match = re.search(versionRegEx, output)
        if match is None:
            self.__BasicConfig.DoPrintWarning(
                "The regex '{0}' did not capture the version".format(
                    versionRegEx))
            return False
        if len(match.groups()) > 1:
            self.__BasicConfig.DoPrintWarning(
                "The regex '{0}' captured more than one group: {1}".format(
                    versionRegEx, match.groups))
        if len(match.groups()) != 1:
            self.__BasicConfig.DoPrintWarning(
                "The regex '{0}' did not capture a group with version information"
                .format(versionRegEx))
        matchResult = match.group(1)
        try:
            # time to parse the version string
            foundVersionList = Util.ParseVersionString(matchResult,
                                                       maxValues=4)
            minVersionList = Util.ParseVersionString(minVersion, maxValues=4)
            if len(minVersionList) > len(foundVersionList):
                self.__BasicConfig.DoPrintWarning(
                    "The regex '{0}' did not capture the enough version number elements to compare against the min version '{1}'"
                    .format(versionRegEx, minVersion))
                return False
            if not self.__CheckVersion(minVersionList, foundVersionList):
                return False
            self.__BasicConfig.LogPrint(
                "  Found version {0} expected minVersion {1}".format(
                    matchResult, minVersion))
        except Exception as ex:
            self.__BasicConfig.DoPrintWarning(
                "Failed to parse version string: {0}".format(str(ex)))
            return False
        return True
Beispiel #2
0
 def __CheckOnErrorWarning(self, foundVersionList: List[int], versionRegEx: str,
                          warning: XmlRecipeValidateCommandFindExecutableFileInPathAddOnErrorWarning) -> None:
     startVersionList = Util.ParseVersionString(warning.StartVersion, maxValues=4)
     if len(startVersionList) > len(foundVersionList):
         self.__BasicConfig.DoPrintWarning("The regex '{0}' did not capture the enough version number elements to compare against the start version '{1}'".format(versionRegEx, warning.StartVersion))
         return  # Its just a warning hint we can't display, so we log it and skip it for now
     if self.__CheckVersion(startVersionList, foundVersionList):
         # ok we passed the start version check for this warning hint
         if warning.EndVersion is not None:
             endVersionList = Util.ParseVersionString(warning.EndVersion, maxValues=4)
             if len(endVersionList) > len(foundVersionList):
                 self.__BasicConfig.DoPrintWarning("The regex '{0}' did not capture the enough version number elements to compare against the end version '{1}'".format(versionRegEx, warning.EndVersion))
                 return # Its just a warning hint we can't display, so we log it and skip it for now
             if self.__CheckVersion(endVersionList, foundVersionList):
                 return
         self.__ErrorHelpManager.AddOnErrorWarningHint(warning.Help)
 def __ParseCMakeVersionString(self,
                               versionStr: Optional[str]) -> CMakeVersion:
     toolMin = CMakeUtil.GetMinimumVersion()
     if versionStr is None:
         return toolMin
     parsedMinVersion = Util.ParseVersionString(versionStr, maxValues=3)
     while len(parsedMinVersion) < 3:
         parsedMinVersion.append(0)
     projectMin = CMakeVersion(parsedMinVersion[0], parsedMinVersion[1],
                               parsedMinVersion[2])
     return projectMin if projectMin >= toolMin else toolMin
Beispiel #4
0
    def __TryValidateCommandVersion(
        self, cmd: str, versionCommand: str, versionRegEx: str,
        minVersion: Optional[str], addOnErrorWarning: List[
            XmlRecipeValidateCommandFindExecutableFileInPathAddOnErrorWarning]
    ) -> List[int]:
        output = ""
        try:
            runCmd = [cmd, versionCommand]
            with subprocess.Popen(runCmd,
                                  stderr=subprocess.STDOUT,
                                  stdout=subprocess.PIPE,
                                  universal_newlines=True) as proc:
                output = proc.stdout.read().strip(
                ) if proc.stdout is not None else ""
                if proc.stdout is not None:
                    proc.stdout.close()
                result = proc.wait()
                if result != 0:
                    self.__Log.LogPrintWarning(
                        "The command '{0}' failed with '{1}'".format(
                            " ".join(runCmd), result))
                    return []
        except FileNotFoundError:
            self.__Log.DoPrintWarning(
                "The command '{0}' failed with 'file not found'.".format(
                    " ".join(runCmd)))
            return []

        match = re.search(versionRegEx, output)
        if match is None:
            self.__Log.DoPrintWarning(
                "The regex '{0}' did not capture the version".format(
                    versionRegEx))
            return []
        if len(match.groups()) > 1:
            self.__Log.DoPrintWarning(
                "The regex '{0}' captured more than one group: {1}".format(
                    versionRegEx, match.groups))
        if len(match.groups()) != 1:
            self.__Log.DoPrintWarning(
                "The regex '{0}' did not capture a group with version information"
                .format(versionRegEx))
        matchResult = match.group(1)
        try:
            # time to parse the version string
            foundVersionList = Util.ParseVersionString(matchResult,
                                                       maxValues=4)
            if minVersion is not None:
                minVersionList = Util.ParseVersionString(minVersion,
                                                         maxValues=4)
                if len(minVersionList) > len(foundVersionList):
                    self.__Log.DoPrintWarning(
                        "The regex '{0}' did not capture the enough version number elements to compare against the min version '{1}'"
                        .format(versionRegEx, minVersion))
                    return []
                self.__Log.LogPrint(
                    "  Found version {0} expected minVersion {1}".format(
                        matchResult, minVersion))
                if not self.__CheckVersion(minVersionList, foundVersionList):
                    return []
            self.__CheckOnErrorWarnings(foundVersionList, versionRegEx,
                                        addOnErrorWarning)
            return foundVersionList
        except Exception as ex:
            self.__Log.DoPrintWarning(
                "Failed to parse version string: {0}".format(str(ex)))
            return []