]> code.ossystems Code Review - openembedded-core.git/commitdiff
dirsize: python3: fix TypeError: unorderable types
authorEd Bartosh <ed.bartosh@linux.intel.com>
Thu, 2 Jun 2016 10:12:59 +0000 (13:12 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 2 Jun 2016 10:49:10 +0000 (11:49 +0100)
Python 3 ignores the __cmp__() method and doesn't have cmp() builtin
function. This caused sorted() call to raise
    TypeError: unorderable types: Record() < Record()

Removing __cmp__ method and implementing __lt__ should solve the
problem as __lt__ is the only method needed for sort[ed] to work.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/tiny/dirsize.py

index 5329b86f75b7595ec004689771a5e464f41202a0..0b4fbd1fa7ad53009a2aad7a9f567282e4df4b69 100755 (executable)
@@ -52,20 +52,16 @@ class Record:
         self.size = 0
         self.records = []
 
-    def __cmp__(this, that):
+    def __lt__(this, that):
         if that is None:
-            return 1
+            return False
         if not isinstance(that, Record):
             raise TypeError
         if len(this.records) > 0 and len(that.records) == 0:
-            return -1
-        if len(this.records) == 0 and len(that.records) > 0:
-            return 1
-        if this.size < that.size:
-            return -1
+            return False
         if this.size > that.size:
-            return 1
-        return 0
+            return False
+        return True
 
     def show(self, minsize):
         total = 0