Passed
Push — develop ( 4d6495...2dddb7 )
by Jace
03:19
created

gitman.system   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 39
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 3 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 logging
4 1
import os
5 1
import platform
6 1
import subprocess
7
8 1
9
log = logging.getLogger(__name__)
10
11 1
12
def launch(path):
13 1
    """Open a file with its default program."""
14 1
    name = platform.system()
15 1
    log.info("Opening %s", path)
16 1
    try:
17
        function = {
18
            'Windows': _launch_windows,
19
            'Darwin': _launch_mac,
20
            'Linux': _launch_linux,
21 1
        }[name]
22 1
    except KeyError:
23
        raise RuntimeError("Unrecognized platform: {}".format(name)) from None
24 1
    else:
25
        return function(path)
26
27
28
def _launch_windows(path):  # pragma: no cover (manual test)
29
    os.startfile(path)  # pylint: disable=no-member
30
    return True
31
32
33
def _launch_mac(path):  # pragma: no cover (manual test)
34
    return subprocess.call(['open', path]) == 0
35
36
37
def _launch_linux(path):  # pragma: no cover (manual test)
38
    return subprocess.call(['xdg-open', path]) == 0
39