本文整理匯總了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")
示例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
示例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
示例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
示例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)
示例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
示例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 ]
示例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}
示例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))
示例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']
示例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)
示例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)
示例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"
示例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
示例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