aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-22 12:28:33 +0000
committerNils Gillmann <ng0@n0.is>2018-05-22 12:28:33 +0000
commit922a08fc69525cca89463d2ed524e68b1a3abc3a (patch)
treea70388fbdbedaff87da877e015cc61fb149a2cad
parent749d5d9eed4d4e0346a4fbe854f66da4894240b3 (diff)
downloadgnunet-922a08fc69525cca89463d2ed524e68b1a3abc3a.tar.gz
gnunet-922a08fc69525cca89463d2ed524e68b1a3abc3a.zip
janitor: flake8ism
Signed-off-by: Nils Gillmann <ng0@n0.is>
-rw-r--r--contrib/scripts/gnunet_janitor.py.in83
1 files changed, 43 insertions, 40 deletions
diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in
index 74fc70886..c4bd00687 100644
--- a/contrib/scripts/gnunet_janitor.py.in
+++ b/contrib/scripts/gnunet_janitor.py.in
@@ -1,6 +1,6 @@
1#!@PYTHON@ 1#!@PYTHON@
2# This file is part of GNUnet. 2# This file is part of GNUnet.
3# (C) 2011 Christian Grothoff (and other contributing authors) 3# (C) 2011, 2018 Christian Grothoff (and other contributing authors)
4# 4#
5# GNUnet is free software; you can redistribute it and/or modify 5# GNUnet is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published 6# it under the terms of the GNU General Public License as published
@@ -33,46 +33,49 @@ import signal
33import terminate 33import terminate
34 34
35if os.name == 'nt': 35if os.name == 'nt':
36 from win32com.client import GetObject 36 from win32com.client import GetObject
37 WMI = GetObject('winmgmts:') 37 WMI = GetObject('winmgmts:')
38 38
39def get_process_list ():
40 result = []
41 if os.name == 'nt':
42 processes = WMI.InstancesOf('Win32_Process')
43 for p in processes:
44 result.append ((p.Properties_('ProcessId').Value, re.sub (r'(.+)\.exe', r'\1', p.Properties_('Name').Value)))
45 else:
46 pids = [pid for pid in os.listdir('/proc') if pid.isdigit ()]
47 for pid in pids:
48 with open (os.path.join ('/proc', pid, 'cmdline'), 'rb') as p:
49 cmdline = p.read ().split ('\x00')
50 if len (cmdline) > 0:
51 result.append ((pid, cmdline[0]))
52 return result
53 39
54def main (): 40def get_process_list():
55 procs = get_process_list () 41 result = []
56 gnunet_procs = [] 42 if os.name == 'nt':
57 for p in procs: 43 processes = WMI.InstancesOf('Win32_Process')
58 if re.match (r'gnunet-.+', p[1]): 44 for p in processes:
59 gnunet_procs.append (p) 45 result.append((p.Properties_('ProcessId').Value, re.sub(r'(.+)\.exe', r'\1', p.Properties_('Name').Value)))
60 for p in gnunet_procs: 46 else:
61 if re.match (r'gnunet-service-arm', p[1]): 47 pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
62 print ("killing arm process {0:5} {1}".format (p[0], p[1])) 48 for pid in pids:
63 try: 49 with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as p:
64 terminate.safe_terminate_process_by_pid (int (p[0]), 1) 50 cmdline = p.read().split('\x00')
65 except OSError as e: 51 if len(cmdline) > 0:
66 print ("failed: {0}".format (e)) 52 result.append((pid, cmdline[0]))
67 pass 53 return result
68 for p in gnunet_procs: 54
69 if not re.match (r'gnunet-service-arm', p[1]): 55
70 print ("killing non-arm process {0:5} {1}".format (p[0], p[1])) 56def main():
71 try: 57 procs = get_process_list()
72 terminate.safe_terminate_process_by_pid (int (p[0]), 1) 58 gnunet_procs = []
73 except OSError as e: 59 for p in procs:
74 print ("failed: {0}".format (e)) 60 if re.match(r'gnunet-.+', p[1]):
75 pass 61 gnunet_procs.append(p)
62 for p in gnunet_procs:
63 if re.match(r'gnunet-service-arm', p[1]):
64 print("killing arm process {0:5} {1}".format(p[0], p[1]))
65 try:
66 terminate.safe_terminate_process_by_pid(int(p[0]), 1)
67 except OSError as e:
68 print("failed: {0}".format(e))
69 pass
70 for p in gnunet_procs:
71 if not re.match(r'gnunet-service-arm', p[1]):
72 print("killing non-arm process {0:5} {1}".format(p[0], p[1]))
73 try:
74 terminate.safe_terminate_process_by_pid(int(p[0]), 1)
75 except OSError as e:
76 print("failed: {0}".format(e))
77 pass
78
76 79
77if __name__ == '__main__': 80if __name__ == '__main__':
78 sys.exit (main ()) 81 sys.exit(main())