You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.6 KiB

From 1694ab2ab3628cead18ba7aa59e134e80675c601 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Fri, 30 Nov 2018 11:50:34 -0500
Subject: [PATCH 1/2] python-linux-procfs: pflags: Use argparse to create a
help option
The purpose of this change is to create a -h or --help option.
In addition the handling of pids or process names is improved. Instead of a
command separated list (without spaces), the more standard unix way of
space separated command line arguments are used.
This is explained in the help.
./pflags -h
usage: pflags [-h] [pid [pid ...]]
Print process flags
positional arguments:
pid a list of pids or names
optional arguments:
-h, --help show this help message and exit
Signed-off-by: John Kacur <jkacur@redhat.com>
---
pflags-cmd.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/pflags-cmd.py b/pflags-cmd.py
index 9228c688e7a2..f180ed505977 100755
--- a/pflags-cmd.py
+++ b/pflags-cmd.py
@@ -15,6 +15,7 @@
# General Public License for more details.
import procfs, re, fnmatch, sys
+import argparse
ps = None
@@ -35,8 +36,13 @@ def main(argv):
global ps
ps = procfs.pidstats()
+ parser = argparse.ArgumentParser(description='Print process flags')
+ parser.add_argument('pid', nargs='*', help='a list of pids or names')
+ args = parser.parse_args()
+
if (len(argv) > 1):
- pids = reduce(lambda i, j: i + j, map(thread_mapper, argv[1].split(",")))
+ pids = args.pid
+ pids = reduce(lambda i, j: i + j, list(map(thread_mapper, pids)))
else:
pids = ps.processes.keys()
--
2.19.2