summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorint3l <int3l@users.noreply.github.com>2019-06-19 19:01:42 +0300
committerCalum Lind <calumlind+deluge@gmail.com>2019-06-24 11:44:29 +0100
commit833b5a1f306dad600d0f64a5c897407ba1584830 (patch)
tree520da95f553faf44c3ba0acce1c6cd043efcd7b0
parent24b094a04a754ddd6405a274f93c536fa5612105 (diff)
downloaddeluge-833b5a1f306dad600d0f64a5c897407ba1584830.tar.gz
deluge-833b5a1f306dad600d0f64a5c897407ba1584830.tar.bz2
deluge-833b5a1f306dad600d0f64a5c897407ba1584830.zip
[Common] Fix show_file unhandled dbus error
If dbus org.freedesktop.FileManager1 service is missing then show_file raised an unhandled exception. The service is not available on certain desktop environments e.g. i3wm. The solution is to fallback to xdg-open. Fixes: #3272
-rw-r--r--deluge/common.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/deluge/common.py b/deluge/common.py
index 7977e02a7..d50fe5ac2 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -81,6 +81,9 @@ TORRENT_STATE = [
# The output formatting for json.dump
JSON_FORMAT = {'indent': 4, 'sort_keys': True, 'ensure_ascii': False}
+DBUS_FM_ID = 'org.freedesktop.FileManager1'
+DBUS_FM_PATH = '/org/freedesktop/FileManager1'
+
PY2 = sys.version_info.major == 2
@@ -355,20 +358,23 @@ def show_file(path, timestamp=None):
timestamp,
timestamp,
)
+
if dbus:
bus = dbus.SessionBus()
- filemanager1 = bus.get_object(
- 'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1'
- )
- paths = [urljoin('file:', pathname2url(path))]
- filemanager1.ShowItems(
- paths, startup_id, dbus_interface='org.freedesktop.FileManager1'
- )
- else:
- env = os.environ.copy()
- env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
- # No option in xdg to highlight a file so just open parent folder.
- subprocess.Popen(['xdg-open', os.path.dirname(path.rstrip('/'))], env=env)
+ try:
+ filemanager1 = bus.get_object(DBUS_FM_ID, DBUS_FM_PATH)
+ except dbus.exceptions.DBusException as ex:
+ log.debug('Unable to get dbus file manager: %s', ex)
+ # Fallback to xdg-open
+ else:
+ paths = [urljoin('file:', pathname2url(path))]
+ filemanager1.ShowItems(paths, startup_id, dbus_interface=DBUS_FM_ID)
+ return
+
+ env = os.environ.copy()
+ env['DESKTOP_STARTUP_ID'] = startup_id.replace('dbus', 'xdg-open')
+ # No option in xdg to highlight a file so just open parent folder.
+ subprocess.Popen(['xdg-open', os.path.dirname(path.rstrip('/'))], env=env)
def open_url_in_browser(url):