gitman.system   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Functions

Rating   Name   Duplication   Size   Complexity  
A _launch_windows() 0 4 1
A launch() 0 14 3
A _launch_mac() 0 2 1
A _launch_linux() 0 2 1
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