-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathunfuck-path.py
executable file
·54 lines (38 loc) · 1.16 KB
/
unfuck-path.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
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
from taiseilib.common import (
run_main,
)
from pathlib import Path, PureWindowsPath, PurePosixPath
import sys
def main(args):
import argparse
parser = argparse.ArgumentParser(description='Because Windows is the worst.', prog=args[0])
parser.add_argument('path',
help='the path to operate on'
)
parser.add_argument('--from-windows',
action='store_true',
help='interpret source as a Windows path (default: POSIX path)'
)
parser.add_argument('--to-windows',
action='store_true',
help='output a Windows path (default: POSIX path)'
)
parser.add_argument('--escape-backslashes',
action='store_true',
help='escape any backslashes in the output'
)
args = parser.parse_args(args[1:])
if args.from_windows:
path = PureWindowsPath(args.path)
else:
path = PurePosixPath(args.path)
if args.to_windows:
out = str(PureWindowsPath(path))
else:
out = path.as_posix()
if args.escape_backslashes:
out = out.replace('\\', '\\\\')
sys.stdout.write(out)
if __name__ == '__main__':
run_main(main)