aboutsummaryrefslogtreecommitdiffstats
path: root/tagit/utils
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-01-07 16:26:26 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-01-07 16:26:26 +0100
commit37f1ac3f456b6677d9ce14274f3987ccda752f03 (patch)
tree23b93bcb1eb04300ffce2e73d8017937d95ffdca /tagit/utils
parent3aebfcba6afd5a882f02e55e442580fe0290c776 (diff)
downloadtagit-37f1ac3f456b6677d9ce14274f3987ccda752f03.tar.gz
tagit-37f1ac3f456b6677d9ce14274f3987ccda752f03.tar.bz2
tagit-37f1ac3f456b6677d9ce14274f3987ccda752f03.zip
browser and misc actions
Diffstat (limited to 'tagit/utils')
-rw-r--r--tagit/utils/shared.py17
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 ##