From 1f901c3183d5d94ed731c0c892a6cf84de474564 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Tue, 9 Aug 2005 11:33:56 +0000 Subject: [PATCH] is_in_path(name_of_command, return_abs_path = False) --- src/common/helpers.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index 50b03ec26..9d57fff37 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -17,9 +17,11 @@ ## GNU General Public License for more details. ## +import sre +import os + from common import i18n _ = i18n._ -import sre def get_uf_show(show): '''returns a userfriendly string for dnd/xa/chat @@ -111,6 +113,31 @@ def get_uf_chatstate(chatstate): elif chatstate == 'composing': return _('is composing a message...') elif chatstate == 'paused': - return _('paused composing a message...') + #paused means he was compoing but has stopped for a while + return _('paused composing a message') elif chatstate == 'gone': return _('has closed the chat window or tab') + +def is_in_path(name_of_command, return_abs_path = False): + # if return_abs_path is True absolute path will be returned + # for name_of_command + # on failures False is returned + is_in_dir = False + found_in_which_dir = None + path = os.getenv('PATH').split(':') + for path_to_directory in path: + try: + contents = os.listdir(path_to_directory) + except OSError: # user can have something in PATH that is not a dir + pass + is_in_dir = name_of_command in contents + if is_in_dir: + if return_abs_path: + found_in_which_dir = path_to_directory + break + + if found_in_which_dir: + abs_path = os.path.join(path_to_directory, name_of_command) + return abs_path + else: + return is_in_dir