Skip to content

Commit

Permalink
1.1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
damonlynch committed Oct 31, 2021
1 parent bbcb459 commit 8e32fd8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = show-in-file-manager
version = 1.1.0
version = 1.1.1
author = Damon Lynch
author_email = [email protected]
description = Open the system file manager and select files in it
Expand Down Expand Up @@ -38,4 +38,4 @@ console_scripts =
showinfilemanager = showinfm.showinfm:main

[options.packages.find]
where = src
where = src
2 changes: 2 additions & 0 deletions src/showinfm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions src/showinfm/showinfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import argparse

try:
import importlib.metadata as importlib_metadata
except ImportError:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -243,15 +246,21 @@ 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))
else:
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:
Expand Down
37 changes: 36 additions & 1 deletion src/showinfm/system/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@


from enum import Enum
import functools
import os
from pathlib import Path, PureWindowsPath
import re
import shlex
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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
2 changes: 2 additions & 0 deletions src/showinfm/system/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 8e32fd8

Please sign in to comment.