Python sys.stdout() Examples
The following are 30
code examples of sys.stdout().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.

Example #1
Source File: multiprocessor.py From svviz with MIT License | 11 votes |
def __init__(self, name=""): self.barsToProgress = {} self.t0 = time.time() self.timeRemaining = "--" self.status = "+" self.name = name self.lastRedraw = time.time() self.isatty = sys.stdout.isatty() try: self.handleResize(None,None) signal.signal(signal.SIGWINCH, self.handleResize) self.signal_set = True except: self.term_width = 79
Example #2
Source File: inst.py From kaldi-python-io with Apache License 2.0 | 11 votes |
def _fopen(fname, mode): """ Extend file open function, to support 1) "-", which means stdin/stdout 2) "$cmd |" which means pipe.stdout """ if mode not in ["w", "r", "wb", "rb"]: raise ValueError("Unknown open mode: {mode}".format(mode=mode)) if not fname: return None fname = fname.rstrip() if fname == "-": if mode in ["w", "wb"]: return sys.stdout.buffer if mode == "wb" else sys.stdout else: return sys.stdin.buffer if mode == "rb" else sys.stdin elif fname[-1] == "|": pin = pipe_fopen(fname[:-1], mode, background=(mode == "rb")) return pin if mode == "rb" else TextIOWrapper(pin) else: if mode in ["r", "rb"] and not os.path.exists(fname): raise FileNotFoundError( "Could not find common file: {}".format(fname)) return open(fname, mode)
Example #3
Source File: inst.py From kaldi-python-io with Apache License 2.0 | 9 votes |
def pipe_fopen(command, mode, background=True): if mode not in ["rb", "r"]: raise RuntimeError("Now only support input from pipe") p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) def background_command_waiter(command, p): p.wait() if p.returncode != 0: warnings.warn("Command \"{0}\" exited with status {1}".format( command, p.returncode)) _thread.interrupt_main() if background: thread = threading.Thread(target=background_command_waiter, args=(command, p)) # exits abnormally if main thread is terminated . thread.daemon = True thread.start() else: background_command_waiter(command, p) return p.stdout
Example #4
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #5
Source File: logServer.py From iSDX with Apache License 2.0 | 7 votes |
def getLogger(fname=None): format='%(asctime)s:%(process)d:%(threadName)s:%(levelname)s:%(name)s:%(pathname)s %(lineno)d:%(message)s' formatter = MyFormatter(format) logger = logging.getLogger('sdx') if fname: fh = logging.FileHandler(fname) fh.setFormatter(formatter) logger.addHandler(fh) ch = logging.StreamHandler(stream=sys.stdout) ch.setFormatter(formatter) logger.addHandler(ch) return logger
Example #6
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #7
Source File: test_gridang.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #8
Source File: utils.py From arm_now with MIT License | 7 votes |
def pcolor(color, *args, **kwargs): """ proxy print arguments """ output = sys.stdout if "file" not in kwargs else kwargs["file"] with contextlib.redirect_stdout(output): print(color, end="") print(*args, end="", **kwargs) print("\x1B[0m")
Example #9
Source File: test_fmarket.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #10
Source File: test_coop.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #11
Source File: __init__.py From supervisor-logging with Apache License 2.0 | 6 votes |
def supervisor_events(stdin, stdout): """ An event stream from Supervisor. """ while True: stdout.write('READY\n') stdout.flush() line = stdin.readline() headers = get_headers(line) payload = stdin.read(int(headers['len'])) event_headers, event_data = eventdata(payload) yield event_headers, event_data stdout.write('RESULT 2\nOK') stdout.flush()
Example #12
Source File: conftest.py From django-click with MIT License | 6 votes |
def call_command(): from django.core.management import call_command class CallCommand(object): def __init__(self): self.io = BytesIO() def __call__(self, *args, **kwargs): self.io = BytesIO() stdout = sys.stdout try: sys.stdout = self.io call_command(*args, **kwargs) finally: sys.stdout = stdout return self @property def stdout(self): return self.io.getvalue() return CallCommand()
Example #13
Source File: test_party.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #14
Source File: test_forestfire.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #15
Source File: test_wolfsheep.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #16
Source File: test_grid.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #17
Source File: client.py From iSDX with Apache License 2.0 | 6 votes |
def _receiver(conn,stdout): while True: try: line = conn.recv() if line == "": continue _write(stdout, line) ''' example: announce route 1.2.3.4 next-hop 5.6.7.8 as-path [ 100 200 ] ''' recvLogger.debug(line) except: pass
Example #18
Source File: test_fashion.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #19
Source File: profiler.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def stats(self, filename, sortby='cumulative'): """:rtype stats(index): output of print_stats() for the given profile. """ sio = io.StringIO() if sys.version_info >= (2, 5): s = pstats.Stats(os.path.join(self.path, filename), stream=sio) s.strip_dirs() s.sort_stats(sortby) s.print_stats() else: # pstats.Stats before Python 2.5 didn't take a 'stream' arg, # but just printed to stdout. So re-route stdout. s = pstats.Stats(os.path.join(self.path, filename)) s.strip_dirs() s.sort_stats(sortby) oldout = sys.stdout try: sys.stdout = sio s.print_stats() finally: sys.stdout = oldout response = sio.getvalue() sio.close() return response
Example #20
Source File: _qemu.py From ALF with Apache License 2.0 | 5 votes |
def _kill_qemu(self): if platform.system() == "Windows": with open(os.devnull, "w") as fp: subprocess.call(["taskkill", "/IM", os.path.basename(self.QEMU_BIN), "/f"], stdout=fp, stderr=fp)
Example #21
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def BOLD(message=None): if message is None: return "\033[1m" if sys.stdout.isatty() else "" else: return BOLD() + message + ENDC()
Example #22
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def ENDC(): return "\033[0m" if sys.stdout.isatty() else ""
Example #23
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def page_output(content, pager=None, file=None): if file is None: file = sys.stdout if not content.endswith("\n"): content += "\n" pager_process = None try: if file != sys.stdout or not file.isatty() or not content.startswith(border("┌")): raise AegeaException() content_lines = content.splitlines() content_rows = len(content_lines) tty_cols, tty_rows = get_terminal_size() naive_content_cols = max(len(i) for i in content_lines) if tty_rows > content_rows and tty_cols > naive_content_cols: raise AegeaException() content_cols = max(len(strip_ansi_codes(i)) for i in content_lines) if tty_rows > content_rows and tty_cols > content_cols: raise AegeaException() pager_process = subprocess.Popen(pager or os.environ.get("PAGER", "less -RS"), shell=True, stdin=subprocess.PIPE, stdout=file) pager_process.stdin.write(content.encode("utf-8")) pager_process.stdin.close() pager_process.wait() if pager_process.returncode != os.EX_OK: raise AegeaException() except Exception as e: if not (isinstance(e, IOError) and e.errno == errno.EPIPE): file.write(content.encode("utf-8") if USING_PYTHON2 else content) finally: try: pager_process.terminate() except BaseException: pass
Example #24
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def UNDERLINE(message=None): if message is None: return "\033[4m" if sys.stdout.isatty() else "" else: return UNDERLINE() + message + ENDC()
Example #25
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def GREEN(message=None): if message is None: return "\033[32m" if sys.stdout.isatty() else "" else: return GREEN() + message + ENDC()
Example #26
Source File: workflow3.py From wechat-alfred-workflow with MIT License | 5 votes |
def send_feedback(self): """Print stored items to console/Alfred as JSON.""" json.dump(self.obj, sys.stdout) sys.stdout.flush()
Example #27
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def YELLOW(message=None): if message is None: return "\033[33m" if sys.stdout.isatty() else "" else: return YELLOW() + message + ENDC()
Example #28
Source File: plugin_loader.py From vt-ida-plugin with Apache License 2.0 | 5 votes |
def __init__(self, cfgfile): self.vt_cfgfile = cfgfile self.file_path = idaapi.get_input_file_path() self.file_name = idc.get_root_filename() logging.getLogger(__name__).addHandler(logging.NullHandler()) if config.DEBUG: logging.basicConfig( stream=sys.stdout, level=logging.DEBUG, format='%(message)s' ) else: logging.basicConfig( stream=sys.stdout, level=logging.INFO, format='%(message)s' ) logging.info( '\n** VT Plugin for IDA Pro v%s (c) Google, 2020', VT_IDA_PLUGIN_VERSION ) logging.info('** VirusTotal integration plugin for Hex-Ray\'s IDA Pro 7') logging.info('\n** Select an area in the Disassembly Window and right') logging.info('** click to search on VirusTotal. You can also select a') logging.info('** string in the Strings Window.\n')
Example #29
Source File: display.py From vergeml with MIT License | 5 votes |
def unhide_cursor(self): if self.is_interactive and self.cursor_hidden: self.cursor_hidden = False self.stdout.write("\033[?25h") self.stdout.flush()
Example #30
Source File: printing.py From aegea with Apache License 2.0 | 5 votes |
def RED(message=None): if message is None: return "\033[31m" if sys.stdout.isatty() else "" else: return RED() + message + ENDC()