當前位置: 首頁>>代碼示例>>Python>>正文


Python pathlib.PureWindowsPath方法代碼示例

本文整理匯總了Python中pathlib.PureWindowsPath方法的典型用法代碼示例。如果您正苦於以下問題:Python pathlib.PureWindowsPath方法的具體用法?Python pathlib.PureWindowsPath怎麽用?Python pathlib.PureWindowsPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pathlib的用法示例。


在下文中一共展示了pathlib.PureWindowsPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_path_from_template

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
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") 
開發者ID:produvia,項目名稱:ai-platform,代碼行數:22,代碼來源:submit.py

示例2: filter_extension_skip_current

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def filter_extension_skip_current(self, event, src_check=False, dest_check=False):
        #src_path
        if src_check:
            if not self.extension_filter is None:
                extension = pathlib.PureWindowsPath(event.src_path).suffix.lower().lstrip('.')
                if not extension in self.extension_filter:
                    return True

        #dest_path
        if dest_check:
            if not self.extension_filter is None:
                extension = pathlib.PureWindowsPath(event.dest_path).suffix.lower().lstrip('.')
                if not extension in self.extension_filter:
                    return True

        return False 
開發者ID:yarox24,項目名稱:attack_monitor,代碼行數:18,代碼來源:feeder_dirwatcher_notifier.py

示例3: test_different_flavours_unordered

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def test_different_flavours_unordered(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        with self.assertRaises(TypeError):
            p < q
        with self.assertRaises(TypeError):
            p <= q
        with self.assertRaises(TypeError):
            p > q
        with self.assertRaises(TypeError):
            p >= q


#
# Tests for the concrete classes
#

# Make sure any symbolic links in the base test path are resolved 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:test_pathlib.py

示例4: to_posix_path

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def to_posix_path(code_path):
    """
    Change the code_path to be of unix-style if running on windows when supplied with an absolute windows path.

    Parameters
    ----------
    code_path : str
        Directory in the host operating system that should be mounted within the container.
    Returns
    -------
    str
        Posix equivalent of absolute windows style path.
    Examples
    --------
    >>> to_posix_path('/Users/UserName/app')
    >>> to_posix_path('C:\\\\Users\\\\UserName\\\\AppData\\\\Local\\\\Temp\\\\mydir')
    """

    return re.sub("^([A-Za-z])+:",
                  lambda match: posixpath.sep + match.group().replace(":", "").lower(),
                  pathlib.PureWindowsPath(code_path).as_posix()) if os.name == "nt" else code_path 
開發者ID:tencentyun,項目名稱:scfcli,代碼行數:23,代碼來源:utils.py

示例5: check_url

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def check_url(self, url, expected):
        url_parts = urlsplit(url)
        if urlsplit(expected).scheme not in uses_relative:
            expected = add_leading_slash(expected)

        expected_parts = urlsplit(expected, scheme='file')

        self.assertEqual(url_parts.scheme, expected_parts.scheme,
                         "%r: Schemes differ." % url)
        self.assertEqual(url_parts.netloc, expected_parts.netloc,
                         "%r: Netloc parts differ." % url)
        self.assertEqual(url_parts.query, expected_parts.query,
                         "%r: Query parts differ." % url)
        self.assertEqual(url_parts.fragment, expected_parts.fragment,
                         "%r: Fragment parts differ." % url)

        if is_windows_path(url_parts.path) or is_windows_path(expected_parts.path):
            path = PureWindowsPath(filter_windows_path(url_parts.path))
            expected_path = PureWindowsPath(filter_windows_path(expected_parts.path))
        else:
            path = PurePath(url_parts.path)
            expected_path = PurePath(expected_parts.path)
        self.assertEqual(path, expected_path, "%r: Paths differ." % url) 
開發者ID:sissaschool,項目名稱:xmlschema,代碼行數:25,代碼來源:test_resources.py

示例6: get_probabilityLeft

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def get_probabilityLeft(session_path, save=False, data=False, settings=False):
    if not data:
        data = raw.load_data(session_path)
    if not settings:
        settings = raw.load_settings(session_path)
    if settings is None:
        settings = {"IBLRIG_VERSION_TAG": "100.0.0"}
    elif settings["IBLRIG_VERSION_TAG"] == "":
        settings.update({"IBLRIG_VERSION_TAG": "100.0.0"})
    num = settings.get("PRELOADED_SESSION_NUM", None)
    if num is None:
        num = settings.get("PREGENERATED_SESSION_NUM", None)
    if num is None:
        fn = settings.get('SESSION_LOADED_FILE_PATH', None)
        fn = PureWindowsPath(fn).name
        num = ''.join([d for d in fn if d.isdigit()])
        if num == '':
            raise ValueError("Can't extract left probability behaviour.")
    # Load the pregenerated file
    sessions_folder = Path(raw.__file__).parent.joinpath('extractors', 'ephys_sessions')
    fname = f"session_{num}_ephys_pcqs.npy"
    pcqsp = np.load(sessions_folder.joinpath(fname))
    pLeft = pcqsp[:, 4]
    pLeft = pLeft[: len(data)]

    if raw.save_bool(save, "_ibl_trials.probabilityLeft.npy"):
        lpath = Path(session_path).joinpath("alf", "_ibl_trials.probabilityLeft.npy")
        np.save(lpath, pLeft)
    return pLeft 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:31,代碼來源:ephys_trials.py

示例7: __init__

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def __init__(self, recipesRoot, uuid, scan):
        self.uuid = uuid
        self.isRoot = scan.isRoot
        self.packagePath = scan.stack
        self.workspacePath = recipesRoot.joinpath(PureWindowsPath(scan.workspacePath))
        self.headers =   [ recipesRoot.joinpath(PureWindowsPath(i)) for i in scan.headers   ]
        self.sources =   [ recipesRoot.joinpath(PureWindowsPath(i)) for i in scan.sources   ]
        self.resources = [ recipesRoot.joinpath(PureWindowsPath(i)) for i in scan.resources ]
        self.incPaths =  [ recipesRoot.joinpath(PureWindowsPath(i)) for i in scan.incPaths  ]
        self.dependencies = scan.dependencies
        self.runTargets = [ recipesRoot.joinpath(PureWindowsPath(i)) for i in scan.runTargets ] 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:13,代碼來源:VisualStudio.py

示例8: test_encode_model_with_path

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def test_encode_model_with_path(model_with_path):
    if isinstance(model_with_path.path, PureWindowsPath):
        expected = "\\foo\\bar"
    else:
        expected = "/foo/bar"
    assert jsonable_encoder(model_with_path) == {"path": expected} 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:8,代碼來源:test_jsonable_encoder.py

示例9: converted_path

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def converted_path(self, path):
        if self.props.is_windows():
            return str(PureWindowsPath(path))
        else:
            return str(PosixPath(path)) 
開發者ID:mlsmithjr,項目名稱:transcoder,代碼行數:7,代碼來源:cluster.py

示例10: __init__

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def __init__(self, platform: str = sys.platform, *args, **kwargs) -> None:
        """Initialize attributes.

        Supported platforms: 'linux', 'darwin', 'win32', 'win64'.

        :param platform: Required platform type.
        """
        super().__init__(*args, **kwargs)
        self.platform = platform
        self._pathlib_home = PureWindowsPath() if 'win' in platform \
                             else PurePosixPath()
        self._pathlib_home /= PLATFORMS[platform]['home'] 
開發者ID:lk-geimfari,項目名稱:mimesis,代碼行數:14,代碼來源:path.py

示例11: test_concrete_class

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def test_concrete_class(self):
        p = self.cls('a')
        self.assertIs(type(p),
            pathlib.PureWindowsPath if os.name == 'nt' else pathlib.PurePosixPath) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_pathlib.py

示例12: test_different_flavours_unequal

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def test_different_flavours_unequal(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        self.assertNotEqual(p, q) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_pathlib.py

示例13: test_load_from_file

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def test_load_from_file():
    cfg = config.from_file(Path("test") / Path("data") / Path("config.json"))

    # Check unchanged defaults are the same
    assert not cfg["app_mode"]
    assert not cfg["debug"]
    assert cfg["pPort"] == 55851
    assert cfg["xPort"] == 55852
    assert cfg["gPort"] == 55853
    assert len(cfg["dataHashSecret"]) == 64 and not cfg["dataHashSecret"].isspace()
    assert PureWindowsPath(cfg["data"]) == PureWindowsPath("C:/User/SCope data")

    # Check new values
    assert cfg["extra setting"] == "value" 
開發者ID:aertslab,項目名稱:SCope,代碼行數:16,代碼來源:test_config.py

示例14: findStimulusWaveformFile

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def findStimulusWaveformFile(abf, channel=0):
    """
    Look for the stimulus waveform file in several places. Return the path
    where it can be found. Return None if it cannot be found.

    The original path is an absolute windows filename stored in the ABF header.
    """

    # first try looking at the path stored in the header
    pathInHeader = Path(abf._stringsIndexed.lDACFilePath[channel])
    if pathInHeader.is_file():
        return str(pathInHeader)

    # try the current working directory of the Python interpreter
    stimBasename = PureWindowsPath(pathInHeader).name
    pathCurrent = Path(stimBasename).resolve().absolute()
    if pathCurrent.is_file():
        return str(pathCurrent)

    # try path defined by the stimulusFileFolder argument of the ABF constructor
    pathUserDefined = Path(str(abf.stimulusFileFolder)).joinpath(stimBasename).resolve()
    if pathUserDefined.is_file():
        return str(pathUserDefined)

    # try the same folder that houses the ABF file
    pathSameFolderAsABF = Path(abf.abfFilePath).parent.joinpath(stimBasename).resolve()
    if pathSameFolderAsABF.is_file():
        return str(pathSameFolderAsABF)

    # warn if stimulus file was never found
    warnings.warn(
            f"Could not locate stimulus file for channel {channel}.\n"
            f"ABF file path: {abf.abfFilePath}.\n"
            f"The following paths were searched:\n"
            f"* Path in the ABF header: {pathInHeader}\n"
            f"* Current working directory: {pathCurrent}\n"
            f"* User-defined stimulus folder: {pathUserDefined}\n"
            f"* Same folder as ABF: {(pathSameFolderAsABF)}\n"
        )

    return None 
開發者ID:swharden,項目名稱:pyABF,代碼行數:43,代碼來源:stimulus.py

示例15: targetPath

# 需要導入模塊: import pathlib [as 別名]
# 或者: from pathlib import PureWindowsPath [as 別名]
def targetPath(self):
        """
        Args:
            woAnchor (bool): remove the anchor (\\server\path or drive:) from returned path.

        Returns:
            a libpath PureWindowsPath object for combined workingDir/relative path
            or the envTarget

        Raises:
            ShortCutError when no target path found in Shortcut
        """
        target = None
        if self.workingDir:
            target = PureWindowsPath(self.workingDir)
            if self.relativePath:
                target = target / PureWindowsPath(self.relativePath)
            else: target = None

        if not target and self.envTarget:
            target = PureWindowsPath(self.envTarget)

        if not target:
            raise ShortCutError("Unable to retrieve target path from MS Shortcut: shortcut = {}"
                               .format(str(self.scPath)))

        return target 
開發者ID:pelednoam,項目名稱:mmvt,代碼行數:29,代碼來源:windows_utils.py


注:本文中的pathlib.PureWindowsPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。