fix pylint errors and format
Stefan Schuermans

Stefan Schuermans commited on 2020-11-08 14:40:44
Showing 4 changed files, with 22 additions and 12 deletions.

... ...
@@ -24,7 +24,7 @@ from gi.repository import Gdk, Gtk, GLib
24 24
 GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, Gtk.main_quit)
25 25
 
26 26
 # regular expression for an environment variable assignment
27
-re_env_var = re.compile(r'^(?P<name>[A-Za-z_][A-Za-z0-9_]*)=(?P<value>.*)$')
27
+RE_ENV_VAR = re.compile(r'^(?P<name>[A-Za-z_][A-Za-z0-9_]*)=(?P<value>.*)$')
28 28
 
29 29
 
30 30
 def add_none(val_a: int, val_b: int) -> int:
... ...
@@ -45,19 +45,19 @@ def cmdline2str(cmdline: list) -> str:
45 45
     return ' '.join([cmdline_str_escape(s) for s in cmdline])
46 46
 
47 47
 
48
-def cmdline_str_escape(s: str) -> str:
48
+def cmdline_str_escape(string: str) -> str:
49 49
     """
50 50
     Escape a command line string for shell use in a way that also works for
51 51
     environment variables (i.e., not escaping the variable name).
52 52
     """
53
-    m = re_env_var.match(s)
54
-    if not m:
53
+    match = RE_ENV_VAR.match(string)
54
+    if not match:
55 55
         # not a variable assignment -> escape entire string
56
-        return shlex.quote(s)
56
+        return shlex.quote(string)
57 57
     # variable assignment -> escape only value part
58 58
     # (also works if it only looks like a variable assignment)
59
-    name = m.group('name')
60
-    value = shlex.quote(m.group('value'))
59
+    name = match.group('name')
60
+    value = shlex.quote(match.group('value'))
61 61
     return f'{name:s}={value:s}'
62 62
 
63 63
 
... ...
@@ -148,6 +148,8 @@ class UptGui:
148 148
     Graphical user interface of UProcTrace.
149 149
     """
150 150
 
151
+    # pylint: disable=R0902
152
+
151 153
     DETAIL_PROC_ID = 0
152 154
     DETAIL_KEY = 1
153 155
     DETAIL_VALUE = 2
... ...
@@ -280,6 +280,12 @@ class Processes(uproctrace.parse.Visitor):
280 280
         """
281 281
         return self._toplevel_processes.copy()
282 282
 
283
+    def getAllProcesses(self) -> dict:
284
+        """
285
+        Return all processes.
286
+        """
287
+        return self._all_processes.copy()
288
+
283 289
     def getProcess(self, proc_id: int):
284 290
         """
285 291
         Return process with proc_id, or None if not found.
... ...
@@ -34,13 +34,14 @@ def calculate_stats(upt_traces: list) -> dict:
34 34
     for upt_trace in upt_traces:
35 35
 
36 36
         # Load all processes of the trace file
37
-        with open(upt_trace, "rb") as f:
38
-            processes = uproctrace.processes.Processes(f)
37
+        with open(upt_trace, "rb") as upt_f:
38
+            processes = uproctrace.processes.Processes(upt_f)
39 39
 
40
-        for process in processes._all_processes.values():
40
+        for process in processes.getAllProcesses().values():
41 41
 
42 42
             # Ignore processes for which we do not have full information
43
-            if process._begin is None or process._end is None:
43
+            if process.getBeginTimestamp() is None or process.getEndTimestamp(
44
+            ) is None:
44 45
                 continue
45 46
 
46 47
             # Update the values
... ...
@@ -50,7 +51,7 @@ def calculate_stats(upt_traces: list) -> dict:
50 51
     # Calulate the statistics
51 52
     stats = dict()
52 53
     for attr, values in attr_values.items():
53
-        if len(values) == 0:
54
+        if not values:
54 55
             stats[attr] = (0, 0, 0, 0)
55 56
             continue
56 57
 
... ...
@@ -51,6 +51,7 @@ def gui(args):
51 51
         return 1
52 52
     import uproctrace.gui
53 53
     uproctrace.gui.run(args.trace[0])
54
+    return 0
54 55
 
55 56
 
56 57
 def pstree(args):
57 58