Completed
Push — develop ( 20efac...c9c7a4 )
by Jace
8s
created

gdm._launch_windows()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
cc 1
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
1
"""Interface to the operating system."""
2
3 1
import os
4 1
import platform
5 1
import subprocess
6 1
import logging
7
8 1
log = logging.getLogger(__name__)
9
10
11
def launch(path):  # pragma: no cover (manual test)
12
    """Open a file with its default program."""
13
    name = platform.system()
14
    log.info("Opening %s", path)
15
    try:
16
        function = {
17
            'Windows': _launch_windows,
18
            'Darwin': _launch_mac,
19
            'Linux': _launch_linux,
20
        }[name]
21
    except KeyError:
22
        raise AssertionError("Unknown OS: {}".format(name))
23
    else:
24
        return function(path)
25
26
27
def _launch_windows(path):  # pragma: no cover (manual test)
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
28
    os.startfile(path)  # pylint: disable=no-member
29
    return True
30
31
32
def _launch_mac(path):  # pragma: no cover (manual test)
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33
    return subprocess.call(['open', path]) == 0
34
35
36
def _launch_linux(path):  # pragma: no cover (manual test)
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
37
    return subprocess.call(['xdg-open', path]) == 0
38