(path_template: str, path_type: PathType = PathType.AUTO)
Replace tags in the given path template and return either Windows or Linux formatted path.
Replace tags in the given path template and return either Windows or Linux formatted path.
Replace tags in the given path template and return either Windows or Linux formatted path .
def get_path_from_template(path_template: str, path_type: PathType = PathType.AUTO) -> str:
    """Replace tags in the given path template and return either Windows or Linux formatted path."""
    # automatically select path type depending on running OS
    if path_type == PathType.AUTO:
        if platform.system() == "Windows":
            path_type = PathType.WINDOWS
        elif platform.system() == "Linux":
            path_type = PathType.LINUX
        else:
            raise RuntimeError("Unknown platform")

    path_template = path_template.replace("<USERNAME>", get_user_name())

    # return correctly formatted path
    if path_type == PathType.WINDOWS:
        return str(pathlib.PureWindowsPath(path_template))
    elif path_type == PathType.LINUX:
        return str(pathlib.PurePosixPath(path_template))
    else:
        raise RuntimeError("Unknown platform")
def get_path_from_template ( path_template : str , path_type : PathType = PathType . AUTO ) -> str : # automatically select path type depending on running OS if path_type == PathType . AUTO : if platform . system ( ) == "Windows" : path_type = PathType . WINDOWS elif platform . system ( ) == "Linux" : path_type = PathType . LINUX else : raise RuntimeError ( "Unknown platform" ) path_template = path_template . replace ( "<USERNAME>" , get_user_name ( ) ) # return correctly formatted path if path_type == PathType . WINDOWS : return str ( pathlib . PureWindowsPath ( path_template ) ) elif path_type == PathType . LINUX : return str ( pathlib . PurePosixPath ( path_template ) ) else : raise RuntimeError ( "Unknown platform" )