import logging from functools import cmp_to_key from tea.utils import cmp from tea.system import platform if platform.is_a(platform.DOTNET): from tea.process.dotnet_process import DotnetProcess as Process from tea.process.dotnet_process import _list_processes, kill elif platform.is_a(platform.WINDOWS): from tea.process.win_process import WinProcess as Process from tea.process.win_process import _list_processes, kill elif platform.is_a(platform.POSIX): from tea.process.posix_process import PosixProcess as Process from tea.process.posix_process import _list_processes, kill else: raise platform.not_supported("tea.process") logger = logging.getLogger(__name__) def get_processes(sort_by_name=True): """Retrieve a list of processes sorted by name. Args: sort_by_name (bool): Sort the list by name or by process ID's. Returns: list of (int, str) or list of (int, str, str): List of process id, process name and optional cmdline tuples. """
args.add(COLORS['bg'][bg]) if underlined: args.add(4) # White and gray are special cases if fg == Color.white: args.add(1) if fg == Color.gray: if fg_dark: args.update([1, 30]) args.remove(37) else: args.remove(1) sys.stdout.write('\33[%sm' % ';'.join(map(str, args))) else: raise platform.not_supported('tea.console.color') def set_color(fg=Color.normal, bg=Color.normal, fg_dark=False, bg_dark=False, underlined=False): """Set the console color. >>> set_color(Color.red, Color.blue) >>> set_color('red', 'blue') >>> set_color() # returns back to normal """ _set_color(fg, bg, fg_dark, bg_dark, underlined) def strip_colors(text): """Helper function used to strip out the color tags so other function can
import os import logging from functools import cmp_to_key from tea.utils import cmp from tea.system import platform if platform.is_a(platform.DOTNET): from .dotnet_process import DotnetProcess as Process from .dotnet_process import _list_processes, kill elif platform.is_a(platform.WINDOWS): from .win_process import WinProcess as Process from .win_process import _list_processes, kill elif platform.is_a(platform.POSIX): from .posix_process import PosixProcess as Process from .posix_process import _list_processes, kill else: raise platform.not_supported('tea.process') logger = logging.getLogger(__name__) def get_processes(sort_by_name=True): """Retrieves a list of processes sorted by name. :param bool sort_by_name: Sort the list by name or by process ID's :rtype: list[(int, str)] or list[(int, str, str)] :return: List of process id, process name and optional cmdline tuples """ if sort_by_name: return sorted(_list_processes(), key=cmp_to_key( lambda p1, p2: (cmp(p1.name, p2.name) or cmp(p1.pid, p2.pid))
def _clear_screen(numlines): os.system('clear') def _getch(): import tty import termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch else: raise platform.not_supported('tea.console.utils') def clear_screen(numlines=100): """Clear the console. :param int numlines: This is an optional argument used only as a fall-back if the operating system console doesn't have clear screen function. :rtype: None """ _clear_screen(numlines) def getch(): """Cross-platform getch() function.
if underlined: args.add(4) # White and gray are special cases if fg == Color.white: args.add(1) if fg == Color.gray: if fg_dark: args.update([1, 30]) args.remove(37) else: args.remove(1) sys.stdout.write("\33[%sm" % ";".join(map(str, args))) else: raise platform.not_supported("tea.console.color") def set_color( fg=Color.normal, bg=Color.normal, fg_dark=False, bg_dark=False, underlined=False, ): """Set the console color. >>> set_color(Color.red, Color.blue) >>> set_color('red', 'blue') >>> set_color() # returns back to normal """