[bitbake-devel] [PATCH 1/3] hob2: remove the hard-coded images map

Kang Kai kai.kang at windriver.com
Fri Aug 24 09:15:09 UTC 2012


[Yocto #2795]

When a new image type added, because it is not in the hard-coded image
dictionary, then hob crashes.
Use a variable IMAGE_TYPES_MAP to present the image maps in a conf file.
If a new image type added, just update the IMAGE_TYPES_MAP.

Signed-off-by: Kang Kai <kai.kang at windriver.com>
---
 bitbake/lib/bb/ui/crumbs/builder.py         |   33 ++++++++++++++++++++++++--
 bitbake/lib/bb/ui/crumbs/hig.py             |    7 ++++-
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |    3 ++
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py
index 7de4798..dde4214 100755
--- a/bitbake/lib/bb/ui/crumbs/builder.py
+++ b/bitbake/lib/bb/ui/crumbs/builder.py
@@ -451,8 +451,32 @@ class Builder(gtk.Window):
 
         self.handler.set_config_filter(hob_conf_filter)
 
+        self.get_image_types()
+
         self.initiate_new_build_async()
 
+    def get_image_types(self):
+        self.configuration.supported_image_types = {}
+        content = self.handler.get_image_types()
+        if content is None:
+            return
+
+        # format of variable IMAGE_TYPES_MAP should be:
+        # IMAGE_TYPES_MAP = "type1:name1 type2:name2,name3 ..."
+        content = content.strip()
+        content = re.sub("\s+", ' ', content)
+        content = re.sub("\s*:\s*", ':', content)
+        content = re.sub("\s*,\s*", ',', content)
+        items = content.split(' ')
+        for item in items:
+            try:
+                index = item.index(':')
+                typename = item[0:index]
+                realnames = item[index+1:]
+                self.configuration.supported_image_types[typename] = realnames.split(',')
+            except:
+                pass
+
     def create_visual_elements(self):
         self.set_title("Hob")
         self.set_icon_name("applications-development")
@@ -894,7 +918,9 @@ class Builder(gtk.Window):
             else:
                 linkname = selected_image + '-' + self.configuration.curr_mach
             for image_type in self.parameters.image_types:
-                for real_image_type in hcc.SUPPORTED_IMAGE_TYPES[image_type]:
+                if image_type not in self.configuration.supported_image_types:
+                    continue
+                for real_image_type in self.configuration.supported_image_types[image_type]:
                     linkpath = self.parameters.image_addr + '/' + linkname + '.' + real_image_type
                     if os.path.exists(linkpath):
                         self.parameters.image_names.append(os.readlink(linkpath))
@@ -1117,7 +1143,8 @@ class Builder(gtk.Window):
     def show_load_my_images_dialog(self):
         dialog = ImageSelectionDialog(self.parameters.image_addr, self.parameters.image_types,
                                       "Open My Images", self,
-                                       gtk.FILE_CHOOSER_ACTION_SAVE)
+                                       gtk.FILE_CHOOSER_ACTION_SAVE, None,
+                                       self.configuration.supported_image_types)
         button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
         HobAltButton.style_button(button)
         button = dialog.add_button("Open", gtk.RESPONSE_YES)
@@ -1334,4 +1361,4 @@ class Builder(gtk.Window):
             format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
             self.consolelog.setFormatter(format)
 
-            self.logger.addHandler(self.consolelog)
\ No newline at end of file
+            self.logger.addHandler(self.consolelog)
diff --git a/bitbake/lib/bb/ui/crumbs/hig.py b/bitbake/lib/bb/ui/crumbs/hig.py
index 2001ff4..014ea98 100644
--- a/bitbake/lib/bb/ui/crumbs/hig.py
+++ b/bitbake/lib/bb/ui/crumbs/hig.py
@@ -1172,7 +1172,7 @@ class ImageSelectionDialog (CrumbsDialog):
     }]
 
 
-    def __init__(self, image_folder, image_types, title, parent, flags, buttons=None):
+    def __init__(self, image_folder, image_types, title, parent, flags, buttons=None, supported_image_types={}):
         super(ImageSelectionDialog, self).__init__(title, parent, flags, buttons)
         self.connect("response", self.response_cb)
 
@@ -1180,6 +1180,7 @@ class ImageSelectionDialog (CrumbsDialog):
         self.image_types  = image_types
         self.image_list = []
         self.image_names = []
+        self.supported_image_types = supported_image_types
 
         # create visual elements on the dialog
         self.create_visual_elements()
@@ -1265,7 +1266,9 @@ class ImageSelectionDialog (CrumbsDialog):
             dirs[:] = []
             for f in files:
                 for image_type in self.image_types:
-                    for real_image_type in hcc.SUPPORTED_IMAGE_TYPES[image_type]:
+                    if image_type not in self.supported_image_types:
+                        continue
+                    for real_image_type in self.supported_image_types[image_type]:
                         if f.endswith('.' + real_image_type):
                             imageset.add(f.rsplit('.' + real_image_type)[0].rsplit('.rootfs')[0])
                             self.image_list.append(f)
diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
index 540dde0..16ab246 100644
--- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
+++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
@@ -393,6 +393,9 @@ class HobHandler(gobject.GObject):
     def get_logfile(self):
         return self.server.runCommand(["getVariable", "BB_CONSOLELOG"])
 
+    def get_image_types(self):
+        return self.server.runCommand(["getVariable", "IMAGE_TYPES_MAP"])
+
     def _remove_redundant(self, string):
         ret = []
         for i in string.split():
-- 
1.7.5.4





More information about the bitbake-devel mailing list