def draw_startup(self): GUIElement.draw_startup(self) self._old_resize_handler = signal.signal( signal.SIGWINCH, self._on_size_change) # resize handler GCStreamHandler.push_std_stream( self._std_stream, self._std_stream) # hide all logging output self._on_size_change() # initial setup of element size self._element.draw_startup()
def draw_finish(self): signal.signal(signal.SIGWINCH, self._old_resize_handler) # restore old resize handler try: self._element.draw_finish() finally: GCStreamHandler.pop_std_stream() if self._dump_stream: # display logging output sys.stderr.write(self._std_stream.getvalue()) self._stream.write('\n')
def script_parse(self, arg_keys=None, verbose_short='v'): self.add_bool(None, None, 'parseable', default=False, help='Output tabular data in parseable format') self.add_bool(None, None, 'pivot', default=False, help='Output pivoted tabular data') self.add_text(None, None, 'textwidth', default=100, help='Output tabular data with selected width') self.add_accu(None, verbose_short, 'verbose', default=0, help='Increase verbosity') self.add_list(None, None, 'logging', help='Increase verbosity') (opts, args, config_dict) = self.parse(arg_keys=arg_keys) logging.getLogger().setLevel(logging.DEFAULT - opts.verbose) for (logger_name, logger_level) in parse_logging_args(opts.logging): logging.getLogger(logger_name).setLevel(LogLevelEnum.str2enum(logger_level)) if opts.parseable: ConsoleTable.table_mode = 'ParseableTable' GCStreamHandler.pop_std_stream() elif opts.pivot: ConsoleTable.table_mode = 'Pivot' ConsoleTable.wraplen = int(opts.textwidth) return Result(opts=opts, args=args, config_dict=config_dict, parser=self)
def handle_debug_interrupt(sig=None, frame=None): buffer = StringBuffer() GCStreamHandler.push_std_stream(buffer, buffer) DebugInterface(frame, interrupt_fun=_trigger_debug_signal).start_console( env_dict={'output': buffer.getvalue}) GCStreamHandler.pop_std_stream()
def start_interface(self): GCStreamHandler.set_global_lock(self._console_lock) with_lock(self._console_lock, self._element.draw_startup) self._redraw_shutdown = False # start redraw thread self._redraw_thread = start_daemon('GUI draw thread', self._redraw)
def _end_interface(): try: self._finish_drawing() finally: GCStreamHandler.set_global_lock() Console.reset_console()
def draw_startup(self): GCStreamHandler.push_std_stream(self, self) BufferGUIElement.draw_startup(self)
def draw_finish(self): BufferGUIElement.draw_finish(self) GCStreamHandler.pop_std_stream() if self._log_dump: self._stream.write('\n' + ANSI.erase_down + '-' * 20 + ' LOG HISTORY ' + '-' * 20 + '-\n') self._stream.write(self._buffer.getvalue())
def install_activity_monitor(): config = gc_create_config(config_dict={'global': {'activity max length': 1000}}) GCStreamHandler.push_std_stream( ActivityMonitor.create_instance('DefaultActivityMonitor', config, sys.stdout, True), ActivityMonitor.create_instance('DefaultActivityMonitor', config, sys.stderr))