summaryrefslogtreecommitdiffstats
path: root/ngxtop/utils.py
diff options
context:
space:
mode:
authorBinh Le <lebinh.it@gmail.com>2014-03-31 00:23:23 +0700
committerBinh Le <lebinh.it@gmail.com>2014-03-31 00:23:23 +0700
commite210ef67a35d17031527088244dc3954f9d97294 (patch)
tree0905783cd503597a6b37b0ff7a034352616c7539 /ngxtop/utils.py
parent5d15a6a3a19072e8f38213809f5d7694e317bb99 (diff)
Better parsing of nginx config file for access_log and log_format directives with pyparsing. Properly handle multiple access logs.
Diffstat (limited to 'ngxtop/utils.py')
-rw-r--r--ngxtop/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/ngxtop/utils.py b/ngxtop/utils.py
new file mode 100644
index 0000000..ef61072
--- /dev/null
+++ b/ngxtop/utils.py
@@ -0,0 +1,19 @@
+import sys
+
+
+def choose_one(choices, prompt):
+ for idx, choice in enumerate(choices):
+ print('%d. %s' % (idx + 1, choice))
+ selected = None
+ while not selected or selected <= 0 or selected > len(choices):
+ selected = raw_input(prompt)
+ try:
+ selected = int(selected)
+ except ValueError:
+ selected = None
+ return choices[selected - 1]
+
+
+def error_exit(msg, status=1):
+ sys.stderr.write('Error: %s\n' % msg)
+ sys.exit(status) \ No newline at end of file