Beispiel #1
0
    def __GetDirAndFilePaths(self,
                             directory: str) -> Tuple[List[str], List[str]]:
        """
        This function will generate the file names in a directory
        tree by walking the tree either top-down or bottom-up. For each
        directory in the tree rooted at directory top (including top itself),
        it yields a 3-tuple (dirpath, dirnames, filenames).
        """
        filePaths = [
        ]  # type: List[str]   # List which will store all of the full filepaths.
        dirPaths = [
        ]  # type: List[str]   # List which will store all of the full dirpaths.

        # Walk the tree (skipping hidden files and directories).
        for root, directories, files in os.walk(directory):
            files = [f for f in files if not f[0] == '.']
            directories[:] = [d for d in directories if not d[0] == '.']
            for dirname in directories:
                dirpath = IOUtil.Join(root, dirname)
                dirPaths.append(
                    IOUtil.ToUnixStylePath(dirpath))  # Add it to the list.
            for filename in files:
                filepath = IOUtil.Join(root, filename)
                filePaths.append(
                    IOUtil.ToUnixStylePath(filepath))  # Add it to the list.
        return (dirPaths, filePaths)
    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
Beispiel #3
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
Beispiel #4
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