Coverage for /home/deng/Projects/ete4/hackathon/ete4/ete4/tools/utils.py: 26%

19 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-03-21 09:19 +0100

1import os 

2 

3# CONVERT shell colors to the same curses palette 

4COLORS = { 

5 "wr": '\033[1;37;41m', # white on red 

6 "wo": '\033[1;37;43m', # white on orange 

7 "wm": '\033[1;37;45m', # white on magenta 

8 "wb": '\033[1;37;46m', # white on blue 

9 "bw": '\033[1;37;40m', # black on white 

10 "lblue": '\033[1;34m', # light blue 

11 "lred": '\033[1;31m', # light red 

12 "lgreen": '\033[1;32m', # light green 

13 "yellow": '\033[1;33m', # yellow 

14 "cyan": '\033[36m', # cyan 

15 "blue": '\033[34m', # blue 

16 "green": '\033[32m', # green 

17 "orange": '\033[33m', # orange 

18 "red": '\033[31m', # red 

19 "magenta": "\033[35m", # magenta 

20 "white": "\033[0m", # white 

21 None: "\033[0m", # end 

22} 

23 

24def colorify(string, color): 

25 return "%s%s%s" %(COLORS[color], string, COLORS[None]) 

26 

27def clear_color(string): 

28 return re.sub("\\033\[[^m]+m", "", string) 

29 

30def which(program): 

31 def is_exe(fpath): 

32 return os.path.isfile(fpath) and os.access(fpath, os.X_OK) 

33 

34 fpath, fname = os.path.split(program) 

35 if fpath: 

36 if is_exe(program): 

37 return program 

38 else: 

39 for path in os.environ["PATH"].split(os.pathsep): 

40 path = path.strip('"') 

41 exe_file = os.path.join(path, program) 

42 if is_exe(exe_file): 

43 return exe_file 

44 return ""