Skip to content

Commit 8e32fd8

Browse files
committed
1.1.1 release
1 parent bbcb459 commit 8e32fd8

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog for Show in File Manager
22
==================================
33

4+
1.1.1 (2022-10-31)
5+
------------------
6+
- Add `allow_conversion` switch to `show_in_file_manager()`. Set to False
7+
if passing non-standard URIs.
8+
- Recognize non-standard URI prefix 'camera:/', used by KDE.
9+
- Added function linux_desktop_humanize(), to make Linux desktop environment
10+
variable name values human friendly.
11+
412
1.1.0 (2022-10-29)
513
------------------
614
- On WSL2, use a Linux file manager (if set) for WSL paths, and Windows

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ def show_in_file_manager(
179179
selecting it and displaying it in its parent directory.
180180
:param file_manager: executable name to use. If not specified, then
181181
valid_file_manager() will determine which file manager to use.
182+
:param allow_conversion: allow this function to automatically convert paths
183+
and URIs to the format needed by the file manager that will be called. Set
184+
to False if passing non-standard URIs. Ignored when running under WSL.
182185
:param verbose: if True print command to be executed before launching
183186
it
184187
:param debug: if True print debugging information to stderr

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = show-in-file-manager
3-
version = 1.1.0
3+
version = 1.1.1
44
author = Damon Lynch
55
author_email = damonlynch@gmail.com
66
description = Open the system file manager and select files in it
@@ -38,4 +38,4 @@ console_scripts =
3838
showinfilemanager = showinfm.showinfm:main
3939

4040
[options.packages.find]
41-
where = src
41+
where = src

src/showinfm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
user_file_manager,
88
stock_file_manager,
99
)
10+
from showinfm.system.linux import linux_desktop, LinuxDesktop, linux_desktop_humanize
11+
from showinfm.constants import single_file_only, cannot_open_uris

src/showinfm/showinfm.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
import argparse
11-
1211
try:
1312
import importlib.metadata as importlib_metadata
1413
except ImportError:
@@ -117,6 +116,7 @@ def show_in_file_manager(
117116
path_or_uri: Optional[Union[str, Sequence[str]]] = None,
118117
open_not_select_directory: Optional[bool] = True,
119118
file_manager: Optional[str] = None,
119+
allow_conversion: bool = True,
120120
verbose: bool = False,
121121
debug: bool = False,
122122
) -> None:
@@ -163,6 +163,9 @@ def show_in_file_manager(
163163
selecting it and displaying it in its parent directory.
164164
:param file_manager: executable name to use. If not specified, then
165165
valid_file_manager() will determine which file manager to use.
166+
:param allow_conversion: allow this function to automatically convert paths
167+
and URIs to the format needed by the file manager that will be called. Set
168+
to False if passing non-standard URIs. Ignored when running under WSL.
166169
:param verbose: if True print command to be executed before launching
167170
it
168171
:param debug: if True print debugging information to stderr
@@ -243,15 +246,21 @@ def show_in_file_manager(
243246
uri = Path(wsl_details.linux_path).resolve().as_uri()
244247
else:
245248
if tools.is_uri(pu):
246-
if tools.filemanager_requires_path(file_manager=file_manager):
249+
if (
250+
tools.filemanager_requires_path(file_manager=file_manager)
251+
and allow_conversion
252+
):
247253
# Convert URI to regular path
248254
uri = None
249255
path = Path(path or tools.file_uri_to_path(pu))
250256
else:
251257
uri = pu
252258
path = None
253259
else:
254-
if tools.filemanager_requires_path(file_manager=file_manager):
260+
if (
261+
tools.filemanager_requires_path(file_manager=file_manager)
262+
or not allow_conversion
263+
):
255264
path = Path(pu)
256265
uri = None
257266
else:

src/showinfm/system/linux.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44

55
from enum import Enum
6+
import functools
67
import os
78
from pathlib import Path, PureWindowsPath
89
import re
910
import shlex
1011
import shutil
1112
import subprocess
1213
from typing import Optional, Tuple, NamedTuple
13-
from urllib.parse import urlparse, unquote, quote
14+
from urllib.parse import urlparse, unquote
1415
import urllib.request
1516

1617
import packaging.version
@@ -659,6 +660,30 @@ class LinuxDesktop(Enum):
659660
unknown = 20
660661

661662

663+
LinuxDesktopHumanize = dict(
664+
gnome="Gnome",
665+
unity="Unity",
666+
cinnamon="Cinnamon",
667+
kde="KDE",
668+
xfce="XFCE",
669+
mate="Mate",
670+
lxde="LXDE",
671+
lxqt="LxQt",
672+
ubuntugnome="Ubuntu Gnome",
673+
popgnome="Pop Gnome",
674+
deepin="Deepin",
675+
zorin="Zorin",
676+
ukui="UKUI",
677+
pantheon="Pantheon",
678+
enlightenment="Enlightenment",
679+
wsl="WSL1",
680+
wsl2="WSL2",
681+
cutefish="Cutefish",
682+
lumina="Lumina",
683+
unknown="Unknown",
684+
)
685+
686+
662687
LinuxDesktopFamily = dict(
663688
ubuntugnome="gnome",
664689
popgnome="gnome",
@@ -723,6 +748,7 @@ def detect_wsl() -> bool:
723748
return p.lower().find("microsoft") > 0
724749

725750

751+
@functools.lru_cache(maxsize=None)
726752
def linux_desktop() -> LinuxDesktop:
727753
"""
728754
Determine Linux desktop environment
@@ -758,3 +784,12 @@ def linux_desktop() -> LinuxDesktop:
758784
return LinuxDesktop[env]
759785
except KeyError:
760786
raise Exception("The desktop environment {} is unknown".format(env))
787+
788+
789+
def linux_desktop_humanize(desktop: LinuxDesktop) -> str:
790+
"""
791+
Make LinuxDesktop name human readable.
792+
:return: desktop name spelled out
793+
"""
794+
795+
return LinuxDesktopHumanize[desktop.name]

src/showinfm/system/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def is_uri(path_uri: str) -> bool:
2929
:return: True if probably a URI, else False
3030
"""
3131

32+
if path_uri and path_uri.startswith('camera:/'):
33+
return True
3234
return re.match("^%s$" % urivalidate.URI, path_uri, re.VERBOSE) is not None
3335

3436

0 commit comments

Comments
 (0)