gdb: make the code PEP-8 compliant
authorMichael Olbrich <m.olbrich@pengutronix.de>
Sat, 29 Dec 2018 15:20:54 +0000 (16:20 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 31 Dec 2018 16:19:05 +0000 (16:19 +0000)
libs/gst/helpers/gst_gdb.py

index fc3b48e..126680b 100644 (file)
@@ -7,8 +7,9 @@ from glib_gobject_helper import g_type_to_name, g_type_name_from_instance
 if sys.version_info[0] >= 3:
     long = int
 
-def is_gst_type (val, klass):
-    def _is_gst_type (type):
+
+def is_gst_type(val, klass):
+    def _is_gst_type(type):
         if str(type) == klass:
             return True
 
@@ -19,61 +20,63 @@ def is_gst_type (val, klass):
             return False
 
         fields = type.fields()
-        if len (fields) < 1:
+        if len(fields) < 1:
             return False
 
         first_field = fields[0]
-        return _is_gst_type (first_field.type)
-
+        return _is_gst_type(first_field.type)
 
     type = val.type
     if type.code != gdb.TYPE_CODE_PTR:
         return False
     type = type.target()
-    return _is_gst_type (type)
+    return _is_gst_type(type)
+
 
 class GstMiniObjectPrettyPrinter:
     "Prints a GstMiniObject instance pointer"
 
-    def __init__ (self, val):
+    def __init__(self, val):
         self.val = val
 
-    def to_string (self):
+    def to_string(self):
         try:
-            inst = self.val.cast (gdb.lookup_type("GstMiniObject").pointer())
+            inst = self.val.cast(gdb.lookup_type("GstMiniObject").pointer())
             gtype = inst["type"]
-            name = g_type_to_name (gtype)
+            name = g_type_to_name(gtype)
             return "0x%x [%s]" % (long(self.val), name)
         except RuntimeError:
-            return  "0x%x" % long(self.val)
+            return "0x%x" % long(self.val)
+
 
 class GstObjectPrettyPrinter:
     "Prints a GstObject instance"
 
-    def __init__ (self, val):
+    def __init__(self, val):
         self.val = val
 
-    def to_string (self):
+    def to_string(self):
         try:
-            name = g_type_name_from_instance (self.val)
+            name = g_type_name_from_instance(self.val)
             if not name:
                 name = str(self.val.type.target())
             if long(self.val) != 0:
-                inst = self.val.cast (gdb.lookup_type("GstObject").pointer())
+                inst = self.val.cast(gdb.lookup_type("GstObject").pointer())
                 inst_name = inst["name"].string()
                 if inst_name:
                     name += "|" + inst_name
-            return  ("0x%x [%s]") % (long(self.val), name)
+            return ("0x%x [%s]") % (long(self.val), name)
         except RuntimeError:
-            return  "0x%x" % long(self.val)
+            return "0x%x" % long(self.val)
+
 
 class GstClockTimePrinter:
     "Prints a GstClockTime / GstClockTimeDiff"
 
-    def __init__ (self, val):
+    def __init__(self, val):
         self.val = val
 
-    def to_string (self):
+    def to_string(self):
         GST_SECOND = 1000000000
         GST_CLOCK_TIME_NONE = 2**64-1
         GST_CLOCK_STIME_NONE = -2**63
@@ -92,23 +95,26 @@ class GstClockTimePrinter:
         if invalid:
             return str(n) + " [99:99:99.999999999]"
 
-        return str(n) + " [%s%u:%02u:%02u.%09u]" % ( prefix,
-             n / (GST_SECOND * 60 * 60),
+        return str(n) + " [%s%u:%02u:%02u.%09u]" % (
+            prefix,
+            n / (GST_SECOND * 60 * 60),
             (n / (GST_SECOND * 60)) % 60,
             (n / GST_SECOND) % 60,
-             n % GST_SECOND )
+            n % GST_SECOND)
+
 
-def gst_pretty_printer_lookup (val):
-    if is_gst_type (val, "GstMiniObject"):
-        return GstMiniObjectPrettyPrinter (val)
-    if is_gst_type (val, "GstObject"):
-        return GstObjectPrettyPrinter (val)
+def gst_pretty_printer_lookup(val):
+    if is_gst_type(val, "GstMiniObject"):
+        return GstMiniObjectPrettyPrinter(val)
+    if is_gst_type(val, "GstObject"):
+        return GstObjectPrettyPrinter(val)
     if str(val.type) == "GstClockTime" or str(val.type) == "GstClockTimeDiff":
-        return GstClockTimePrinter (val)
+        return GstClockTimePrinter(val)
     return None
 
-def register (obj):
-    if obj == None:
+
+def register(obj):
+    if obj is None:
         obj = gdb
 
     # Make sure this is always used befor the glib lookup function.