Skip to content

Commit

Permalink
Change distutils.spawn.find_executalbe to which
Browse files Browse the repository at this point in the history
  • Loading branch information
amanusk committed Aug 27, 2018
1 parent c9f07ea commit 867e767
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 18 additions & 1 deletion s_tui/HelperFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from collections import OrderedDict
from sys import exit

__version__ = "0.8.0"
__version__ = "0.8.1"


def get_processor_name():
Expand Down Expand Up @@ -172,6 +172,23 @@ def seconds_to_text(secs):
return "%02d:%02d:%02d" % (hours, minutes, seconds)


def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None


DEFAULT_PALETTE = [
('body', 'default', 'default', 'standout'),
('header', 'default', 'dark red',),
Expand Down
13 changes: 7 additions & 6 deletions s_tui/s_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

from sys import exit
from collections import OrderedDict
from distutils.spawn import find_executable
from s_tui.AboutMenu import AboutMenu
from s_tui.HelpMenu import HelpMenu
from s_tui.HelpMenu import HELP_MESSAGE
Expand All @@ -60,6 +59,7 @@
from s_tui.HelperFunctions import user_config_dir_exists
from s_tui.HelperFunctions import user_config_file_exists
from s_tui.HelperFunctions import seconds_to_text
from s_tui.HelperFunctions import which
from s_tui.UiElements import ViListBox
from s_tui.UiElements import radio_button
from s_tui.UiElements import button
Expand Down Expand Up @@ -141,11 +141,12 @@ def __init__(self):
self.modes.append('Stress')

global fire_starter
fire_starter_exe = which('FIRESTARTER')
if os.path.isfile('./FIRESTARTER/FIRESTARTER'):
fire_starter = os.path.join(os.getcwd(), 'FIRESTARTER',
'FIRESTARTER')
elif find_executable('FIRESTARTER') is not None:
fire_starter = 'FIRESTARTER'
elif fire_starter_exe is not None:
fire_starter = fire_starter_exe

if fire_starter is not None:
self.modes.append('FIRESTARTER')
Expand Down Expand Up @@ -762,9 +763,9 @@ def main(self):
logging.error(e, exc_info=True)
print(ERROR_MESSAGE)
except (AttributeError) as e:
logging.error("Catch attribute Error in urwid and restart")
logging.error(e, exc_info=True)
print(ERROR_MESSAGE)
logging.debug("Catch attribute Error in urwid and restart")
logging.debug(e, exc_info=True)
self.main()
except (psutil.NoSuchProcess) as e:
logging.error("No such proccess error")
logging.error(e, exc_info=True)
Expand Down

0 comments on commit 867e767

Please sign in to comment.