forked from cool-RR/python_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_tools.py
More file actions
29 lines (20 loc) · 754 Bytes
/
os_tools.py
File metadata and controls
29 lines (20 loc) · 754 Bytes
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
# Copyright 2009-2017 Ram Rachum.
# This program is distributed under the MIT license.
'''Various os-related tools.'''
import subprocess
import sys
import os.path
def start_file(path):
'''Open a file by launching the program that handles its kind.'''
path = pathlib.Path(path)
assert path.exists()
if sys.platform.startswith('linux'): # Linux:
subprocess.check_call(['xdg-open', str(path)])
elif sys.platform == 'darwin': # Mac:
subprocess.check_call(['open', '--', str(path)])
elif sys.platform in ('win32', 'cygwin'): # Windows:
os.startfile(path)
else:
raise NotImplementedError(
f"Your operating system {sys.platform} isn't supported by "
f"`start_file`.")