diff --git a/CHANGELOG.md b/CHANGELOG.md index 82dc190..d241c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog for Show in File Manager ================================== +1.1.1 (2022-10-31) +------------------ + - Add `allow_conversion` switch to `show_in_file_manager()`. Set to False + if passing non-standard URIs. + - Recognize non-standard URI prefix 'camera:/', used by KDE. + - Added function linux_desktop_humanize(), to make Linux desktop environment + variable name values human friendly. + 1.1.0 (2022-10-29) ------------------ - On WSL2, use a Linux file manager (if set) for WSL paths, and Windows diff --git a/README.md b/README.md index be22064..6934ab3 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,9 @@ def show_in_file_manager( selecting it and displaying it in its parent directory. :param file_manager: executable name to use. If not specified, then valid_file_manager() will determine which file manager to use. + :param allow_conversion: allow this function to automatically convert paths + and URIs to the format needed by the file manager that will be called. Set + to False if passing non-standard URIs. Ignored when running under WSL. :param verbose: if True print command to be executed before launching it :param debug: if True print debugging information to stderr diff --git a/setup.cfg b/setup.cfg index c181d26..7689b4d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = show-in-file-manager -version = 1.1.0 +version = 1.1.1 author = Damon Lynch author_email = damonlynch@gmail.com description = Open the system file manager and select files in it @@ -38,4 +38,4 @@ console_scripts = showinfilemanager = showinfm.showinfm:main [options.packages.find] -where = src \ No newline at end of file +where = src diff --git a/src/showinfm/__init__.py b/src/showinfm/__init__.py index 3711ef2..8538e41 100644 --- a/src/showinfm/__init__.py +++ b/src/showinfm/__init__.py @@ -7,3 +7,5 @@ user_file_manager, stock_file_manager, ) +from showinfm.system.linux import linux_desktop, LinuxDesktop, linux_desktop_humanize +from showinfm.constants import single_file_only, cannot_open_uris diff --git a/src/showinfm/showinfm.py b/src/showinfm/showinfm.py index 5252dda..655dc39 100644 --- a/src/showinfm/showinfm.py +++ b/src/showinfm/showinfm.py @@ -8,7 +8,6 @@ """ import argparse - try: import importlib.metadata as importlib_metadata except ImportError: @@ -117,6 +116,7 @@ def show_in_file_manager( path_or_uri: Optional[Union[str, Sequence[str]]] = None, open_not_select_directory: Optional[bool] = True, file_manager: Optional[str] = None, + allow_conversion: bool = True, verbose: bool = False, debug: bool = False, ) -> None: @@ -163,6 +163,9 @@ def show_in_file_manager( selecting it and displaying it in its parent directory. :param file_manager: executable name to use. If not specified, then valid_file_manager() will determine which file manager to use. + :param allow_conversion: allow this function to automatically convert paths + and URIs to the format needed by the file manager that will be called. Set + to False if passing non-standard URIs. Ignored when running under WSL. :param verbose: if True print command to be executed before launching it :param debug: if True print debugging information to stderr @@ -243,7 +246,10 @@ def show_in_file_manager( uri = Path(wsl_details.linux_path).resolve().as_uri() else: if tools.is_uri(pu): - if tools.filemanager_requires_path(file_manager=file_manager): + if ( + tools.filemanager_requires_path(file_manager=file_manager) + and allow_conversion + ): # Convert URI to regular path uri = None path = Path(path or tools.file_uri_to_path(pu)) @@ -251,7 +257,10 @@ def show_in_file_manager( uri = pu path = None else: - if tools.filemanager_requires_path(file_manager=file_manager): + if ( + tools.filemanager_requires_path(file_manager=file_manager) + or not allow_conversion + ): path = Path(pu) uri = None else: diff --git a/src/showinfm/system/linux.py b/src/showinfm/system/linux.py index 68c7453..e69510d 100644 --- a/src/showinfm/system/linux.py +++ b/src/showinfm/system/linux.py @@ -3,6 +3,7 @@ from enum import Enum +import functools import os from pathlib import Path, PureWindowsPath import re @@ -10,7 +11,7 @@ import shutil import subprocess from typing import Optional, Tuple, NamedTuple -from urllib.parse import urlparse, unquote, quote +from urllib.parse import urlparse, unquote import urllib.request import packaging.version @@ -659,6 +660,30 @@ class LinuxDesktop(Enum): unknown = 20 +LinuxDesktopHumanize = dict( + gnome="Gnome", + unity="Unity", + cinnamon="Cinnamon", + kde="KDE", + xfce="XFCE", + mate="Mate", + lxde="LXDE", + lxqt="LxQt", + ubuntugnome="Ubuntu Gnome", + popgnome="Pop Gnome", + deepin="Deepin", + zorin="Zorin", + ukui="UKUI", + pantheon="Pantheon", + enlightenment="Enlightenment", + wsl="WSL1", + wsl2="WSL2", + cutefish="Cutefish", + lumina="Lumina", + unknown="Unknown", +) + + LinuxDesktopFamily = dict( ubuntugnome="gnome", popgnome="gnome", @@ -723,6 +748,7 @@ def detect_wsl() -> bool: return p.lower().find("microsoft") > 0 +@functools.lru_cache(maxsize=None) def linux_desktop() -> LinuxDesktop: """ Determine Linux desktop environment @@ -758,3 +784,12 @@ def linux_desktop() -> LinuxDesktop: return LinuxDesktop[env] except KeyError: raise Exception("The desktop environment {} is unknown".format(env)) + + +def linux_desktop_humanize(desktop: LinuxDesktop) -> str: + """ + Make LinuxDesktop name human readable. + :return: desktop name spelled out + """ + + return LinuxDesktopHumanize[desktop.name] diff --git a/src/showinfm/system/tools.py b/src/showinfm/system/tools.py index b4a3a94..5f27f6b 100644 --- a/src/showinfm/system/tools.py +++ b/src/showinfm/system/tools.py @@ -29,6 +29,8 @@ def is_uri(path_uri: str) -> bool: :return: True if probably a URI, else False """ + if path_uri and path_uri.startswith('camera:/'): + return True return re.match("^%s$" % urivalidate.URI, path_uri, re.VERBOSE) is not None