Completed
Push — develop ( c9c7a4...e6cfa4 )
by Jace
02:12
created

gdm.launch()   A

Complexity

Conditions 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3
Metric Value
cc 3
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
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 1
def launch(path):
12
    """Open a file with its default program."""
13 1
    name = platform.system()
14 1
    log.info("Opening %s", path)
15 1
    try:
16 1
        function = {
17
            'Windows': _launch_windows,
18
            'Darwin': _launch_mac,
19
            'Linux': _launch_linux,
20
        }[name]
21 1
    except KeyError:
22 1
        raise RuntimeError("Unrecognized platform: {}".format(name)) from None
23
    else:
24 1
        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