示例#1
0
    def __init__(
        self, basicConfig: BasicConfig,
        basedUponXML: XmlConfigFileAddNewProjectTemplatesRootDirectory
    ) -> None:
        super().__init__()
        self.BasedOn = basedUponXML
        self.Id = basedUponXML.Id
        self.Name = basedUponXML.Name
        self.DynamicName = basedUponXML.Name

        variableProcessor = VariableProcessor(basicConfig)

        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, True)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "Root dirs are expected to contain environment variables '{0}'"
                .format(self.DynamicName))
        remainingPath = remainingPath if remainingPath is not None else ""

        resolvedPath = IOUtil.GetEnvironmentVariableForDirectory(
            env) + remainingPath
        self.BashName = '${0}{1}'.format(env, remainingPath)
        self.DosName = '%{0}%{1}'.format(env, remainingPath)
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)
        self.ResolvedPathEx = "{0}/".format(
            self.ResolvedPath) if len(self.ResolvedPath) > 0 else ""
        self.__EnvironmentVariableName = env
示例#2
0
    def __init__(self,
                 log: Log,
                 basedUponXML: Optional[XmlConfigFileAddRootDirectory],
                 projectId: ProjectId,
                 dynamicSourceRootDir: Union[
                     Optional[XmlConfigFileAddRootDirectory],
                     Optional['ToolConfigRootDirectory']] = None,
                 dynamicRootName: Optional[str] = None,
                 dynamicPath: Optional[str] = None) -> None:
        super().__init__()
        dirMustExist = True
        self.ProjectId = projectId
        if basedUponXML is not None:
            self.BasedOn = basedUponXML  # type: Union[XmlConfigFileAddRootDirectory, 'ToolConfigRootDirectory']
            self.Name = basedUponXML.Name  # type: str
            self.DynamicName = basedUponXML.Name  # type: str
            dirMustExist = not basedUponXML.Create
        else:
            if dynamicSourceRootDir is None:
                raise Exception("dynamicSourceRootDir can not be none")
            if dynamicRootName is None:
                raise Exception("dynamicRootName can not be none")
            if dynamicPath is None:
                raise Exception("dynamicPath can not be none")
            self.BasedOn = dynamicSourceRootDir
            self.Name = dynamicRootName
            self.DynamicName = dynamicPath
        variableProcessor = VariableProcessor(log)
        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, dynamicSourceRootDir != None)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "Root dirs are expected to contain environment variables '{0}'"
                .format(self.DynamicName))
        remainingPath = remainingPath if remainingPath is not None else ""

        resolvedPath = IOUtil.GetEnvironmentVariableForDirectory(
            env, dirMustExist)
        if not IOUtil.Exists(resolvedPath):
            IOUtil.SafeMakeDirs(resolvedPath)
        if not IOUtil.IsDirectory(resolvedPath):
            raise EnvironmentError(
                "The {0} environment variable content '{1}' does not point to a valid directory"
                .format(env, resolvedPath))

        resolvedPath = resolvedPath + remainingPath
        self.BashName = '${0}{1}'.format(env, remainingPath)  # type: str
        self.DosName = '%{0}%{1}'.format(env, remainingPath)  # type: str
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)  # type: str
        self.ResolvedPathEx = "{0}/".format(self.ResolvedPath) if len(
            self.ResolvedPath) > 0 else ""  # type: str
        self.__EnvironmentVariableName = env  # type: str
示例#3
0
    def __init__(self, log: Log, basedUponXML: Optional[
        Union[XmlExperimentalDefaultThirdPartyInstallDirectory,
              XmlExperimentalDefaultThirdPartyInstallReadonlyCacheDirectory]],
                 entryName: str, isReadonlyCache: bool) -> None:
        super(ToolConfigExperimentalDefaultThirdPartyInstallDirectory,
              self).__init__()

        if basedUponXML is None:
            raise Exception(
                "No '{0}' was defined in the xml".format(entryName))

        self.__Log = log  # type: Log
        self.BasedOn = basedUponXML
        self.Name = basedUponXML.Name  # type: str
        self.DynamicName = basedUponXML.Name  # type: str
        self.IsReadonlyCache = isReadonlyCache  # type: bool

        variableProcessor = VariableProcessor(log)

        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, False)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "The {0} is expected to contain a environment variable '{1}'".
                format(entryName, self.DynamicName))

        resolvedPath = self.__GetEnvironmentVariable(env)

        self.__EnvironmentVariableName = env  # type: str
        self.BashName = '${0}{1}'.format(env, remainingPath)  # type: str
        self.DosName = '%{0}%{1}'.format(env, remainingPath)  # type: str
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)  # type: str
        self.ResolvedPathEx = "{0}/".format(self.ResolvedPath) if len(
            self.ResolvedPath) > 0 else ""  # type: str