Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

"""Interface to the operating system.""" 

 

import os 

import platform 

import subprocess 

import logging 

 

log = logging.getLogger(__name__) 

 

 

def launch(path): 

"""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 RuntimeError("Unrecognized platform: {}".format(name)) from None 

else: 

return function(path) 

 

 

def _launch_windows(path): # pragma: no cover (manual test) 

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