diff options
author | John Kacur <jkacur@redhat.com> | 2018-11-28 04:28:53 +0100 |
---|---|---|
committer | Jiri Kastner <jkastner@redhat.com> | 2019-01-11 16:51:26 +0100 |
commit | d6cd44df068ee51a75e3ef63ef428ae431a0ef46 (patch) | |
tree | bbb5f4658baaa02a593e0137f3c27d65654613d8 | |
parent | eae67c261b996b6c10ca7d29aa5a7742b2679633 (diff) | |
download | python-linux-procfs-d6cd44df068ee51a75e3ef63ef428ae431a0ef46.tar.gz |
python-linux-procfs: pflags: Use argparse to create a help option
The purpose of this change was to create a -h, or --help option.
The following changes were made.
1. pflags is now python3 only, since it uses argparse.
2. 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 arguements 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>
Signed-off-by: Jiri Kastner <jkastner@redhat.com>
-rwxr-xr-x | pflags | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/python3 # -*- python -*- # -*- coding: utf-8 -*- # print process flags @@ -14,8 +14,9 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -from __future__ import print_function + import procfs, re, fnmatch, sys +import argparse from functools import reduce from six.moves import map @@ -38,8 +39,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, list(map(thread_mapper, argv[1].split(",")))) + pids = args.pid + pids = reduce(lambda i, j: i + j, list(map(thread_mapper, pids))) else: pids = list(ps.processes.keys()) |