|
|
1dbcf3 |
From 68e3d6e74f0941c98aaeb82b89c954c76246ba7a Mon Sep 17 00:00:00 2001
|
|
|
1dbcf3 |
From: John Kacur <jkacur@redhat.com>
|
|
|
1dbcf3 |
Date: Wed, 28 Nov 2018 04:28:53 +0100
|
|
|
1dbcf3 |
Subject: [PATCH 2/2] python-linux-procfs: pflags: Use argparse to create a
|
|
|
1dbcf3 |
help option
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
The purpose of this change was to create a -h, or --help option.
|
|
|
1dbcf3 |
The following changes were made.
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
1. pflags is now python3 only, since it uses argparse.
|
|
|
1dbcf3 |
2. The handling of pids or process names is improved, instead of a
|
|
|
1dbcf3 |
command separated list (without spaces), the more standard unix way of
|
|
|
1dbcf3 |
space separated command line arguements are used.
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
This is explained in the help
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
./pflags -h
|
|
|
1dbcf3 |
usage: pflags [-h] [pid [pid ...]]
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
Print process flags
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
positional arguments:
|
|
|
1dbcf3 |
pid a list of pids or names
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
optional arguments:
|
|
|
1dbcf3 |
-h, --help show this help message and exit
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
|
1dbcf3 |
---
|
|
|
1dbcf3 |
pflags | 12 +++++++++---
|
|
|
1dbcf3 |
1 file changed, 9 insertions(+), 3 deletions(-)
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
diff --git a/pflags b/pflags
|
|
|
1dbcf3 |
index abfcfe9e9ec1..a1667fc06131 100755
|
|
|
1dbcf3 |
--- a/pflags
|
|
|
1dbcf3 |
+++ b/pflags
|
|
|
1dbcf3 |
@@ -1,4 +1,4 @@
|
|
|
1dbcf3 |
-#! /usr/bin/python
|
|
|
1dbcf3 |
+#! /usr/bin/python3
|
|
|
1dbcf3 |
# -*- python -*-
|
|
|
1dbcf3 |
# -*- coding: utf-8 -*-
|
|
|
1dbcf3 |
# print process flags
|
|
|
1dbcf3 |
@@ -14,8 +14,9 @@
|
|
|
1dbcf3 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
1dbcf3 |
# General Public License for more details.
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
-from __future__ import print_function
|
|
|
1dbcf3 |
+
|
|
|
1dbcf3 |
import procfs, re, fnmatch, sys
|
|
|
1dbcf3 |
+import argparse
|
|
|
1dbcf3 |
from functools import reduce
|
|
|
1dbcf3 |
from six.moves import map
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
@@ -38,8 +39,13 @@ def main(argv):
|
|
|
1dbcf3 |
global ps
|
|
|
1dbcf3 |
ps = procfs.pidstats()
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
+ parser = argparse.ArgumentParser(description='Print process flags')
|
|
|
1dbcf3 |
+ parser.add_argument('pid', nargs='*', help='a list of pids or names')
|
|
|
1dbcf3 |
+ args = parser.parse_args()
|
|
|
1dbcf3 |
+
|
|
|
1dbcf3 |
if (len(argv) > 1):
|
|
|
1dbcf3 |
- pids = reduce(lambda i, j: i + j, list(map(thread_mapper, argv[1].split(","))))
|
|
|
1dbcf3 |
+ pids = args.pid
|
|
|
1dbcf3 |
+ pids = reduce(lambda i, j: i + j, list(map(thread_mapper, pids)))
|
|
|
1dbcf3 |
else:
|
|
|
1dbcf3 |
pids = list(ps.processes.keys())
|
|
|
1dbcf3 |
|
|
|
1dbcf3 |
--
|
|
|
1dbcf3 |
2.19.1
|
|
|
1dbcf3 |
|