From fac8e0d09233f929b0232fbb6e13401ba2f1c918 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:27:17 +0200 Subject: [PATCH 1/6] added virtual env to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3287e5f..250c36d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,7 @@ nosetests.xml # PyCharm .idea +# Virtual Environment +.venv + pylokit/tests/.~* From 652efc4ce84cdc54e9d945c2db1ee72a63de1c3b Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:27:45 +0200 Subject: [PATCH 2/6] added '-n' option to arguments --- uwsgitop | 1 + 1 file changed, 1 insertion(+) diff --git a/uwsgitop b/uwsgitop index 0d7a899..07714c9 100755 --- a/uwsgitop +++ b/uwsgitop @@ -71,6 +71,7 @@ def merge_worker_with_cores(workers, rps_per_worker, cores, rps_per_core): def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--frequency', type=int, default=1, help='Refresh frequency in seconds') + parser.add_argument('-n', type=int, default=None, help='Number of cycles until uwsgitop quits') parser.add_argument('address', help='uWSGI stats socket or address') return parser.parse_args() From 5d07fb32145681a7ee46c559bcaa04178587afad Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:37:44 +0200 Subject: [PATCH 3/6] added function to capture curses window content --- uwsgitop | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/uwsgitop b/uwsgitop index 07714c9..c5df837 100755 --- a/uwsgitop +++ b/uwsgitop @@ -76,6 +76,14 @@ def parse_args(): return parser.parse_args() + +def capture_curses_content(screen): + rows, cols = screen.getmaxyx() + binary_lines = (screen.instr(i, 0) for i in range(rows)) + text_lines = (bl.decode("utf-8", errors="ignore") for bl in binary_lines) + return "".join(tl for tl in text_lines if tl.strip()) + + def main(): need_reset = True From 2f01a6451fed5c4a29d4cd3b8d2d852295012b76 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:38:32 +0200 Subject: [PATCH 4/6] breaking out of main loop if number of cycles reached --- uwsgitop | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/uwsgitop b/uwsgitop index c5df837..eef9fa1 100755 --- a/uwsgitop +++ b/uwsgitop @@ -155,8 +155,19 @@ def main(): async_mode = 0 fast_screen = 0 + # number of cycles to display + max_cycle = args.n + cycle = itertools.count() + while True: + # break out of loop if number of cycles reached + if max_cycle and max_cycle == next(cycle): + content = capture_curses_content(screen) + game_over() + print(content) + break + if fast_screen == 1: screen.timeout(100) else: From 565e7cb2dc86b7c6ef348ecd2a03bb376ada5578 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:43:08 +0200 Subject: [PATCH 5/6] whitespace error --- uwsgitop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uwsgitop b/uwsgitop index eef9fa1..d01fd3c 100755 --- a/uwsgitop +++ b/uwsgitop @@ -156,8 +156,8 @@ def main(): fast_screen = 0 # number of cycles to display - max_cycle = args.n - cycle = itertools.count() + max_cycle = args.n + cycle = itertools.count() while True: From d965fcd4b81c0ccffe259b0e5f49430345a6bb04 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 17 Sep 2020 16:43:42 +0200 Subject: [PATCH 6/6] added import of itertools --- uwsgitop | 1 + 1 file changed, 1 insertion(+) diff --git a/uwsgitop b/uwsgitop index d01fd3c..77ec31a 100755 --- a/uwsgitop +++ b/uwsgitop @@ -14,6 +14,7 @@ import sys import traceback from collections import defaultdict import errno +import itertools def human_size(n):