From 61bf53f5d035303b5f6f6f6a0c649529e3dfbdd0 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Mon, 19 Sep 2016 11:11:05 +0200 Subject: [PATCH] Fix Debian-specific checking for dmenu. The old check uses ``which``, which is a Debian-specific tool. The new one invokes ``dmenu -v`` straight away, so it doesn't depend on external tools. It's compatible with both Python 3 and Python 2. It also fixes opening ``/dev/null`` in write mode instead of read-only, plus it uses ``with`` to ensure that the file is closed. --- quickswitch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/quickswitch.py b/quickswitch.py index ca9b45f..925225a 100755 --- a/quickswitch.py +++ b/quickswitch.py @@ -37,11 +37,14 @@ def check_dmenu(): '''Check if dmenu is available.''' - devnull = open(os.devnull) - retcode = subprocess.call(["which", "dmenu"], - stdout=devnull, - stderr=devnull) - return True if retcode == 0 else False + with open(os.devnull, 'w') as devnull: + try: + retcode = subprocess.call(["dmenu", "-v"], + stdout=devnull, + stderr=devnull) + return retcode == 0 + except OSError: + return False def dmenu(options, dmenu):