From 8e340e456d33819dd4ed757ba1fe741814122445 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 14 Apr 2015 14:15:01 +0100 Subject: [PATCH] Added open_file to misc utils. A function to open a file using an associated launcher in an OS-agnostic way. --- wlauto/utils/misc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wlauto/utils/misc.py b/wlauto/utils/misc.py index 279667ca..af9b7e5e 100644 --- a/wlauto/utils/misc.py +++ b/wlauto/utils/misc.py @@ -701,3 +701,16 @@ def unique(alist): if item not in result: result.append(item) return result + + +def open_file(filepath): + """ + Open the specified file path with the associated launcher in an OS-agnostic way. + + """ + if os.name == 'nt': # Windows + return os.startfile(filepath) # pylint: disable=no-member + elif sys.platform == 'darwin': # Mac OSX + return subprocess.call(['open', filepath]) + else: # assume Linux or similar running a freedesktop-compliant GUI + return subprocess.call(['xdg-open', filepath])