for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
"""Interface to the operating system."""
import os
import platform
import subprocess
import logging
log = logging.getLogger(__name__)
def launch(path): # pragma: no cover (manual test)
"""Open a file with its default program."""
name = platform.system()
log.info("Opening %s", path)
try:
function = {
'Windows': _launch_windows,
'Darwin': _launch_mac,
'Linux': _launch_linux,
}[name]
except KeyError:
raise AssertionError("Unknown OS: {}".format(name))
else:
return function(path)
def _launch_windows(path): # pragma: no cover (manual test)
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.
os.startfile(path) # pylint: disable=no-member
return True
def _launch_mac(path): # pragma: no cover (manual test)
return subprocess.call(['open', path]) == 0
def _launch_linux(path): # pragma: no cover (manual test)
return subprocess.call(['xdg-open', path]) == 0
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.