From 37f1ac3f456b6677d9ce14274f3987ccda752f03 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sat, 7 Jan 2023 16:26:26 +0100 Subject: browser and misc actions --- tagit/utils/shared.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tagit/utils') 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 ## -- cgit v1.2.3