1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 02:01:16 +00:00

Added open_file to misc utils.

A function to open a file using an associated launcher in an OS-agnostic
way.
This commit is contained in:
Sergei Trofimov 2015-04-14 14:15:01 +01:00
parent 61b834e52c
commit 8e340e456d

View File

@ -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])