summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2020-04-14 11:59:18 -0400
committerJohn Kacur <jkacur@redhat.com>2020-04-14 12:06:19 -0400
commit93408d2b968e2c10b3e79de5f6da644941aac807 (patch)
tree6c20374cc5839eacadc530a9239fd8dd1d8df6cb
parentcba70a4e239ae0bf626e6ccea7ee96d6f48890ff (diff)
downloadpython-linux-procfs-93408d2b968e2c10b3e79de5f6da644941aac807.tar.gz
python-linux-procfs: pflags: Conform to python spacing recommendations
Conform to python spacing recommendations, for easier maintainence - remove tabs, for 4 spaces - remove unnecessary parenthesis - remove unnecessary spacing around return Signed-off-by: John Kacur <jkacur@redhat.com>
-rwxr-xr-xpflags82
1 files changed, 41 insertions, 41 deletions
diff --git a/pflags b/pflags
index 9c45600..3407b6f 100755
--- a/pflags
+++ b/pflags
@@ -23,54 +23,54 @@ from six.moves import map
ps = None
def thread_mapper(s):
- global ps
+ global ps
- try:
- return [ int(s), ]
- except:
- pass
- try:
- return ps.find_by_regex(re.compile(fnmatch.translate(s)))
- except:
- return ps.find_by_name(s)
+ try:
+ return [int(s), ]
+ except:
+ pass
+ try:
+ return ps.find_by_regex(re.compile(fnmatch.translate(s)))
+ except:
+ return ps.find_by_name(s)
def main(argv):
- global ps
- ps = procfs.pidstats()
+ 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()
+ 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 = args.pid
- pids = reduce(lambda i, j: i + j, list(map(thread_mapper, pids)))
- else:
- pids = list(ps.processes.keys())
+ if len(argv) > 1:
+ pids = args.pid
+ pids = reduce(lambda i, j: i + j, list(map(thread_mapper, pids)))
+ else:
+ pids = list(ps.processes.keys())
- pids.sort()
- len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids if pid in ps]
- max_comm_len = max(len_comms, default=0)
- del(len_comms)
+ pids.sort()
+ len_comms = [len(ps[pid]["stat"]["comm"]) for pid in pids if pid in ps]
+ max_comm_len = max(len_comms, default=0)
+ del len_comms
- for pid in pids:
- if pid not in ps:
- continue
- flags = ps[pid].stat.process_flags()
- # Remove flags that were superseeded
- if "PF_THREAD_BOUND" in flags and "PF_NO_SETAFFINITY" in flags:
- flags.remove("PF_THREAD_BOUND")
- if "PF_FLUSHER" in flags and "PF_NPROC_EXCEEDED" in flags:
- flags.remove("PF_FLUSHER")
- if "PF_SWAPOFF" in flags and "PF_MEMALLOC_NOIO" in flags:
- flags.remove("PF_SWAPOFF")
- if "PF_FREEZER_NOSIG" in flags and "PF_SUSPEND_TASK" in flags:
- flags.remove("PF_FREEZER_NOSIG")
- comm = ps[pid].stat["comm"]
- flags.sort()
- sflags = reduce(lambda i, j: "%s|%s" % (i, j), [a[3:] for a in flags])
- print("%6d %*s %s" %(pid, max_comm_len, comm, sflags))
+ for pid in pids:
+ if pid not in ps:
+ continue
+ flags = ps[pid].stat.process_flags()
+ # Remove flags that were superseeded
+ if "PF_THREAD_BOUND" in flags and "PF_NO_SETAFFINITY" in flags:
+ flags.remove("PF_THREAD_BOUND")
+ if "PF_FLUSHER" in flags and "PF_NPROC_EXCEEDED" in flags:
+ flags.remove("PF_FLUSHER")
+ if "PF_SWAPOFF" in flags and "PF_MEMALLOC_NOIO" in flags:
+ flags.remove("PF_SWAPOFF")
+ if "PF_FREEZER_NOSIG" in flags and "PF_SUSPEND_TASK" in flags:
+ flags.remove("PF_FREEZER_NOSIG")
+ comm = ps[pid].stat["comm"]
+ flags.sort()
+ sflags = reduce(lambda i, j: "%s|%s" % (i, j), [a[3:] for a in flags])
+ print("%6d %*s %s" %(pid, max_comm_len, comm, sflags))
if __name__ == '__main__':
- main(sys.argv)
+ main(sys.argv)