Patchwork [bitbake-devel] hob: sort alphabetically results in groups of recipes/packages

login
register
mail settings
Submitter Cristiana Voicu
Date April 16, 2013, 12:12 p.m.
Message ID <1366114350-16405-1-git-send-email-cristiana.voicu@intel.com>
Download mbox | patch
Permalink /patch/48331/
State New
Headers show

Comments

Cristiana Voicu - April 16, 2013, 12:12 p.m.
When you search a string, there are 2 groups: recipes/packages starting
with that string, and the rest. These 2 groups are now sorted.

[YOCTO #4111]
Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
---
 bitbake/lib/bb/ui/crumbs/hoblistmodel.py |   38 ++++++++++--------------------
 1 file changed, 12 insertions(+), 26 deletions(-)

Patch

diff --git a/bitbake/lib/bb/ui/crumbs/hoblistmodel.py b/bitbake/lib/bb/ui/crumbs/hoblistmodel.py
index 547c1ca..42fd6ce 100644
--- a/bitbake/lib/bb/ui/crumbs/hoblistmodel.py
+++ b/bitbake/lib/bb/ui/crumbs/hoblistmodel.py
@@ -152,12 +152,7 @@  class PackageListModel(gtk.ListStore):
         if user_data:
             val1 = model.get_value(iter1, PackageListModel.COL_NAME)
             val2 = model.get_value(iter2, PackageListModel.COL_NAME)
-            if val1.startswith(user_data) and not val2.startswith(user_data):
-                return -1
-            elif not val1.startswith(user_data) and val2.startswith(user_data):
-                return 1
-            else:
-                return 0
+            return self.cmp_vals(val1, val2, user_data)
         else:
             val1 = model.get_value(iter1, PackageListModel.COL_FADE_INC)
             val2 = model.get_value(iter2, PackageListModel.COL_INC)
@@ -167,12 +162,7 @@  class PackageListModel(gtk.ListStore):
         if user_data:
             val1 = model.get_value(iter1, PackageListModel.COL_NAME)
             val2 = model.get_value(iter2, PackageListModel.COL_NAME)
-            if val1.startswith(user_data) and not val2.startswith(user_data):
-                return -1
-            elif not val1.startswith(user_data) and val2.startswith(user_data):
-                return 1
-            else:
-                return 0
+            return self.cmp_vals(val1, val2, user_data)
         else:
             val1 = model.get_value(iter1, PackageListModel.COL_INC)
             val2 = model.get_value(iter2, PackageListModel.COL_INC)
@@ -181,12 +171,15 @@  class PackageListModel(gtk.ListStore):
     def sort_func(self, model, iter1, iter2, user_data):
         val1 = model.get_value(iter1, PackageListModel.COL_NAME)
         val2 = model.get_value(iter2, PackageListModel.COL_NAME)
+        return self.cmp_vals(val1, val2, user_data)
+
+    def cmp_vals(self, val1, val2, user_data):
         if val1.startswith(user_data) and not val2.startswith(user_data):
             return -1
         elif not val1.startswith(user_data) and val2.startswith(user_data):
             return 1
         else:
-            return 0
+            return cmp(val1, val2)
 
     def convert_vpath_to_path(self, view_model, view_path):
         # view_model is the model sorted
@@ -533,12 +526,7 @@  class RecipeListModel(gtk.ListStore):
         if user_data:
             val1 = model.get_value(iter1, RecipeListModel.COL_NAME)
             val2 = model.get_value(iter2, RecipeListModel.COL_NAME)
-            if val1.startswith(user_data) and not val2.startswith(user_data):
-                return -1
-            elif not val1.startswith(user_data) and val2.startswith(user_data):
-                return 1
-            else:
-                return 0
+            return self.cmp_vals(val1, val2, user_data)
         else:
             val1 = model.get_value(iter1, RecipeListModel.COL_FADE_INC)
             val2 = model.get_value(iter2, RecipeListModel.COL_INC)
@@ -548,12 +536,7 @@  class RecipeListModel(gtk.ListStore):
         if user_data:
             val1 = model.get_value(iter1, RecipeListModel.COL_NAME)
             val2 = model.get_value(iter2, RecipeListModel.COL_NAME)
-            if val1.startswith(user_data) and not val2.startswith(user_data):
-                return -1
-            elif not val1.startswith(user_data) and val2.startswith(user_data):
-                return 1
-            else:
-                return 0
+            return self.cmp_vals(val1, val2, user_data)
         else:
             val1 = model.get_value(iter1, RecipeListModel.COL_INC)
             val2 = model.get_value(iter2, RecipeListModel.COL_INC)
@@ -562,12 +545,15 @@  class RecipeListModel(gtk.ListStore):
     def sort_func(self, model, iter1, iter2, user_data):
         val1 = model.get_value(iter1, RecipeListModel.COL_NAME)
         val2 = model.get_value(iter2, RecipeListModel.COL_NAME)
+        return self.cmp_vals(val1, val2, user_data)
+
+    def cmp_vals(self, val1, val2, user_data):
         if val1.startswith(user_data) and not val2.startswith(user_data):
             return -1
         elif not val1.startswith(user_data) and val2.startswith(user_data):
             return 1
         else:
-            return 0
+            return cmp(val1, val2)
 
     """
     Create, if required, and return a filtered gtk.TreeModelSort