Skip to content

Commit

Permalink
- Try to find kreadconfig5 in PATH, otherwise fall back to kreadconfig
Browse files Browse the repository at this point in the history
- Use universal_newlines=True in subprocess calls instead of decoding with UTF-8 always
  • Loading branch information
cryzed committed Jun 12, 2020
1 parent e94d889 commit df3c2b0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions core/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Handles terminal detection on Linux and terminal command lines."""
from __future__ import print_function, unicode_literals, absolute_import

import sys, os, subprocess, tempfile, time
import sys, os, subprocess, tempfile, time, shutil
from .lnp import lnp
from . import log

Expand Down Expand Up @@ -119,10 +119,11 @@ def detect():

@staticmethod
def get_command_line():
s = subprocess.check_output(
['kreadconfig', '--file', 'kdeglobals', '--group', 'General',
'--key', 'TerminalApplication', '--default', 'konsole']).decode('utf-8').replace(
'\n', '')
kreadconfig_path = shutil.which('kreadconfig5') or shutil.which('kreadconfig')
s = subprocess.check_output([
kreadconfig_path, '--file', 'kdeglobals', '--group', 'General',
'--key', 'TerminalApplication', '--default', 'konsole'],
universal_newlines=True).replace('\n', '')
return ['nohup', s, '-e']

class GNOMETerminal(LinuxTerminal):
Expand Down Expand Up @@ -159,23 +160,23 @@ def get_command_line():
term = subprocess.check_output([
'gsettings', 'get',
'org.gnome.desktop.default-applications.terminal', 'exec'
]).decode('utf-8').replace('\n', '').replace("'", '')
], universal_newlines=True).replace('\n', '').replace("'", '')
term_arg = subprocess.check_output([
'gsettings', 'get',
'org.gnome.desktop.default-applications.terminal', 'exec-arg'
]).decode('utf-8').replace('\n', '').replace("'", '')
], universal_newlines=True).replace('\n', '').replace("'", '')
return ['nohup', term, term_arg]
except: #fallback to older gconf
pass
try:
term = subprocess.check_output([
'gconftool-2', '--get',
'/desktop/gnome/applications/terminal/exec'
]).decode('utf-8').replace('\n', '')
], universal_newlines=True).replace('\n', '')
term_arg = subprocess.check_output([
'gconftool-2', '--get',
'/desktop/gnome/applications/terminal/exec_arg'
]).decode('utf-8').replace('\n', '')
], universal_newlines=True).replace('\n', '')
return ['nohup', term, term_arg]
except:
raise Exception("Unable to determine terminal command.")
Expand All @@ -188,7 +189,8 @@ class XfceTerminal(LinuxTerminal):
def detect():
try:
s = subprocess.check_output(
['ps', '-eo', 'comm='], stderr=subprocess.STDOUT).decode('utf-8')
['ps', '-eo', 'comm='], stderr=subprocess.STDOUT,
universal_newlines=True)
return 'xfce' in s
except:
return False
Expand Down

0 comments on commit df3c2b0

Please sign in to comment.