summaryrefslogtreecommitdiff
path: root/raphodo/storage.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-01-03 18:32:15 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-01-03 18:32:15 +0100
commitb71beaf0d22f182ab0b95b1b35da7e786585c4e7 (patch)
tree1e95d573c09bee1dec63d909cc59ef57222a7710 /raphodo/storage.py
parentdeb736d38beac3863c04d4c0f285c28557fe07c6 (diff)
parent8351a36cbcbe8529ec1c0bb60d77bf65fb59fe12 (diff)
Update upstream source from tag 'upstream/0.9.7'
Update to upstream version '0.9.7' with Debian dir 9c39d3b734403d3ae14a7bfdb1f76e371acb4e78
Diffstat (limited to 'raphodo/storage.py')
-rw-r--r--raphodo/storage.py63
1 files changed, 49 insertions, 14 deletions
diff --git a/raphodo/storage.py b/raphodo/storage.py
index 6856c38..f4ef551 100644
--- a/raphodo/storage.py
+++ b/raphodo/storage.py
@@ -75,7 +75,7 @@ from gi.repository import GUdev, UDisks, GLib
from gettext import gettext as _
-from raphodo.constants import Desktop, Distro
+from raphodo.constants import Desktop, Distro, FileManagerType
from raphodo.utilities import (
process_running, log_os_release, remove_topmost_directory_from_path, find_mount_point
)
@@ -170,6 +170,24 @@ def get_media_dir() -> str:
raise ("Mounts.setValidMountPoints() not implemented on %s", sys.platform())
+_gvfs_gphoto2 = re.compile('gvfs.*gphoto2.*host')
+
+
+def gvfs_gphoto2_path(path: str) -> bool:
+ """
+ :return: True if the path appears to be a GVFS gphoto2 path
+
+ >>> p = "/run/user/1000/gvfs/gphoto2:host=%5Busb%3A002%2C013%5D"
+ >>> gvfs_gphoto2_path(p)
+ True
+ >>> p = '/home/damon'
+ >>> gvfs_gphoto2_path(p)
+ False
+ """
+
+ return _gvfs_gphoto2.search(path) is not None
+
+
class ValidMounts():
r"""
Operations to find 'valid' mount points, i.e. the places in which
@@ -359,6 +377,8 @@ def get_desktop() -> Desktop:
env = 'cinnamon'
elif env == 'ubuntu:gnome':
env = 'ubuntugnome'
+ elif env == 'pop:gnome':
+ env = 'popgnome'
try:
return Desktop[env]
except KeyError:
@@ -546,7 +566,8 @@ def get_fdo_cache_thumb_base_directory() -> str:
return os.path.join(BaseDirectory.xdg_cache_home, 'thumbnails')
-def get_default_file_manager(remove_args: bool = True) -> Optional[str]:
+def get_default_file_manager(remove_args: bool = True) -> Tuple[
+ Optional[str], Optional[FileManagerType]]:
"""
Attempt to determine the default file manager for the system
:param remove_args: if True, remove any arguments such as %U from
@@ -558,7 +579,7 @@ def get_default_file_manager(remove_args: bool = True) -> Optional[str]:
try:
desktop_file = subprocess.check_output(cmd, universal_newlines=True) # type: str
except:
- return None
+ return None, None
# Remove new line character from output
desktop_file = desktop_file[:-1]
if desktop_file.endswith(';'):
@@ -570,21 +591,40 @@ def get_default_file_manager(remove_args: bool = True) -> Optional[str]:
try:
desktop_entry = DesktopEntry(path)
except xdg.Exceptions.ParsingError:
- return None
+ return None, None
try:
desktop_entry.parse(path)
except:
- return None
+ return None, None
fm = desktop_entry.getExec()
+ if fm.startswith('dolphin'):
+ file_manager_type = FileManagerType.select
+ else:
+ file_manager_type = FileManagerType.regular
if remove_args:
- return fm.split()[0]
+ return fm.split()[0], file_manager_type
else:
- return fm
+ return fm, file_manager_type
# Special case: LXQt
if get_desktop() == Desktop.lxqt:
if shutil.which('pcmanfm-qt'):
- return 'pcmanfm-qt'
+ return 'pcmanfm-qt', FileManagerType.regular
+
+ return None, None
+
+def open_in_file_manager(file_manager: str,
+ file_manager_type: FileManagerType,
+ uri: str) -> None:
+ if file_manager_type == FileManagerType.regular:
+ arg = ''
+ else:
+ arg = '--select '
+
+ cmd = '{} {}"{}"'.format(file_manager, arg, uri)
+ logging.debug("Launching: %s", cmd)
+ args = shlex.split(cmd)
+ subprocess.Popen(args)
_desktop = get_desktop()
@@ -612,7 +652,7 @@ def get_uri(full_file_name: Optional[str]=None,
prefix = 'file://'
if desktop_environment:
desktop = get_desktop()
- if full_file_name and desktop in (Desktop.mate, Desktop.kde):
+ if full_file_name and desktop == Desktop.mate:
full_file_name = os.path.dirname(full_file_name)
else:
if not desktop_environment:
@@ -637,11 +677,6 @@ def get_uri(full_file_name: Optional[str]=None,
prefix = 'mtp:/' + pathname2url(
'{}/{}'.format(camera_details.display_name, camera_details.storage_desc)
)
- # Dolphin doesn't highlight the file if it's passed.
- # Instead it tries to open it, but fails.
- # So don't pass the file, just the directory it's in.
- if full_file_name:
- full_file_name = os.path.dirname(full_file_name)
else:
logging.error("Don't know how to generate MTP prefix for %s", _desktop.name)
else: