-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcygpath.py
42 lines (32 loc) · 1004 Bytes
/
cygpath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import subprocess
import os
from typing import Literal, Optional, Union
import sys
if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
StrPath: TypeAlias = Union[os.PathLike[str], str]
OutputType: TypeAlias = Literal['dos', 'mixed', 'unix', 'windows']
def pathconv(path: str,
output_type: OutputType,
absolute: bool = False,
long: Optional[bool] = None,
proc: bool = False,
) -> str:
args = ['cygpath', '--type', output_type]
if absolute:
args.append('--absolute')
if long is True:
args.append('--long')
elif long is False:
args.append('--short-name')
if proc:
args.append('--proc-cygdrive')
args.append(path)
p = subprocess.run(args,
capture_output=True,
check=True,
text=True,
)
return p.stdout.rstrip('\n')