Пример #1
0
    def resolveFileLocation(aClass, aInputString, aPrefixDirectoryList):
        # validate the input
        if not isinstance(aPrefixDirectoryList, list):
            raise Exception(
                "Parameter aPrefixDirectoryList needs to be a list of strings"
            )

        # is the input string itself a usable absolute path?
        if aInputString.startswith("/") and PathUtils.check_found(
            aInputString
        ):
            return aInputString, True

        # is the input string a relative path meaningful with one of the
        # prefix directories prepended?
        intermed_dir, file_name = PathUtils.split_path(aInputString)
        for directory in aPrefixDirectoryList:
            joined_path, outcome = (
                FileLocator.checkNestedPath(
                    [directory, intermed_dir, file_name]
                )
                if intermed_dir is not None
                else FileLocator.checkNestedPath([directory, file_name])
            )
            if outcome:
                return joined_path, True

        # the input string does not form an existing filepath
        return aInputString, False
Пример #2
0
    def checkNestedPath(aClass, aPathList):
        #validate the input
        if type(aPathList) != list:
            raise Exception(
                "Input to FileLocator.checkNestedPath must be a list")
        if len(aPathList) < 2:
            raise Exception(
                "Input to FileLocator.checkNesterPath needs to be a list more than 1 item long"
            )

        joined_path = str(aPathList[0])

        for path in aPathList[1:]:
            joined_path = PathUtils.real_path(
                PathUtils.append_path(joined_path, path))

        #validate the joined path
        if not PathUtils.check_found(joined_path):
            return joined_path, False
        else:
            return joined_path, True