Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | """Interface to the operating system.""" |
||
2 | |||
3 | 1 | import os |
|
4 | 1 | import platform |
|
5 | 1 | import subprocess |
|
6 | 1 | ||
7 | import log |
||
8 | 1 | ||
9 | |||
10 | def launch(path): |
||
11 | 1 | """Open a file with its default program.""" |
|
12 | name = platform.system() |
||
13 | 1 | log.info("Opening %s", path) |
|
14 | 1 | try: |
|
15 | 1 | function = { |
|
16 | 1 | 'Windows': _launch_windows, |
|
17 | 'Darwin': _launch_mac, |
||
18 | 'Linux': _launch_linux, |
||
19 | }[name] |
||
20 | except KeyError: |
||
21 | 1 | raise RuntimeError("Unrecognized platform: {}".format(name)) from None |
|
22 | 1 | else: |
|
23 | return function(path) |
||
24 | 1 | ||
25 | |||
26 | def _launch_windows(path): # pragma: no cover (manual test) |
||
27 | # pylint: disable=no-member |
||
28 | os.startfile(path) # type: ignore |
||
29 | return True |
||
30 | |||
31 | |||
32 | def _launch_mac(path): # pragma: no cover (manual test) |
||
33 | return subprocess.call(['open', path]) == 0 |
||
34 | |||
35 | |||
36 | def _launch_linux(path): # pragma: no cover (manual test) |
||
37 | return subprocess.call(['xdg-open', path]) == 0 |
||
38 |