diff options
Diffstat (limited to 'tagit/utils')
-rw-r--r-- | tagit/utils/shared.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tagit/utils/shared.py b/tagit/utils/shared.py index 82fe672..0d496ed 100644 --- a/tagit/utils/shared.py +++ b/tagit/utils/shared.py @@ -10,14 +10,17 @@ from collections import namedtuple import logging import os import pkgutil +import platform import re import typing +import warnings # exports __all__: typing.Sequence[str] = ( 'Resolution', 'Struct', 'clamp', + 'fileopen', 'flatten', 'fst', 'import_all', @@ -123,4 +126,18 @@ def is_hex(string): except TypeError: return False +def fileopen(pth): + """Open a file in the preferred application as a subprocess. + This operation is platform dependent. + """ + try: + binopen = { + "Linux" : "xdg-open", # Linux + "darwin" : "open", # MAX OS X + "Windows" : "start", # Windows + }.get(platform.system()) + subprocess.call((binopen, pth)) + except KeyError: + warnings.warn('Unknown platform {}'.format(platform.system())) + ## EOF ## |