def gen_proxy_entry_widget(self,
                               protocol,
                               parent,
                               need_button=True,
                               line=0):
        label = gtk.Label(protocol.upper() + " proxy")
        self.proxy_table.attach(label, 0, 1, line, line + 1, xpadding=24)

        proxy_entry = gtk.Entry()
        proxy_entry.set_size_request(300, -1)
        self.proxy_table.attach(proxy_entry, 1, 2, line, line + 1, ypadding=4)

        self.proxy_table.attach(gtk.Label(":"),
                                2,
                                3,
                                line,
                                line + 1,
                                xpadding=12,
                                ypadding=4)

        port_entry = gtk.Entry()
        port_entry.set_size_request(60, -1)
        self.proxy_table.attach(port_entry, 3, 4, line, line + 1, ypadding=4)

        details_button = HobAltButton("Details")
        details_button.connect("clicked", self.details_cb, parent, protocol)
        self.proxy_table.attach(details_button,
                                4,
                                5,
                                line,
                                line + 1,
                                xpadding=4,
                                yoptions=gtk.EXPAND)

        return proxy_entry, port_entry, details_button
Exemple #2
0
    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup(
            "<span size='medium'>Check the \"Issues\" information for more details</span>"
        )
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked',
                              self.failure_primary_action_button_clicked_cb,
                              primary_action)
        build_fail_tab.attach(action_button, 4, 13, 9, 12)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked',
                                    self.failure_open_log_button_clicked_cb,
                                    log_file)
            build_fail_tab.attach(open_log_button, 14, 23, 9, 12)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text(
            "Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked',
                                self.failure_activate_file_bug_link_cb)
        build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9,
                              12)

        return build_fail_top
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        created = False
        packed = False
        self.button_ids = {}
        is_runnable = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            #deploy_button.set_size_request(205, 49)
            deploy_button.set_tooltip_text("Burn a live image to a USB drive or flash memory")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked", self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button, expand=False, fill=False)
            created = True
            packed = True

        name = "Run image"
        if name in buttonlist and self.test_type_runnable(image_name) and self.test_mach_runnable(image_name):
            if created == True:
                # separator
                #label = gtk.Label(" or ")
                #self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

                # create button "Run image"
                run_button = HobAltButton("Run image")
            else:
                # create button "Run image" as the primary button
                run_button = HobButton("Run image")
                #run_button.set_size_request(205, 49)
                run_button.set_flags(gtk.CAN_DEFAULT)
                packed = True
            run_button.set_tooltip_text("Start up an image with qemu emulator")
            button_id = run_button.connect("clicked", self.run_button_clicked_cb)
            self.button_ids[button_id] = run_button
            self.details_bottom_buttons.pack_end(run_button, expand=False, fill=False)
            created = True
            is_runnable = True

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            if packed:
                build_new_button = HobAltButton("Build new image")
            else:
                build_new_button = HobButton("Build new image")
                build_new_button.set_flags(gtk.CAN_DEFAULT)
            #build_new_button.set_size_request(205, 49)
            self.details_bottom_buttons.pack_end(build_new_button, expand=False, fill=False)
            build_new_button.set_tooltip_text("Create a new image from scratch")
            button_id = build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button

        return is_runnable
Exemple #4
0
    def add_build_fail_top_bar(self, actions):
        mainly_action = "Edit %s" % actions
        if 'image' in actions:
            next_action   = ""
        else:
            next_action   = "Create new image"

        #set to issue page
        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        build_fail_top.set_size_request(-1, 260)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(7, 40, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 3)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'>%s</span>" % self.title)
        build_fail_tab.attach(label, 4, 20, 0, 3)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        num_of_fails = self.update_failures_sum_display()
        current_fail, recipe_task_status = self.task_status.get_text().split('\n')
        label.set_markup(" %d tasks failed,  %s, %s" % (num_of_fails, current_fail, recipe_task_status))
        build_fail_tab.attach(label, 4, 40, 2, 4)

        # create button 'Edit packages'
        action_button = HobButton(mainly_action)
        action_button.set_size_request(-1, 49)
        action_button.connect('clicked', self.failure_main_action_button_clicked_cb, mainly_action)
        build_fail_tab.attach(action_button, 4, 16, 4, 6)

        if next_action:
            next_button = HobAltButton(next_action)
            next_button.set_alignment(0.0, 0.5)
            next_button.connect('clicked', self.failure_next_action_button_clicked_cb, next_action)
            build_fail_tab.attach(next_button, 17, 24, 4, 5)

        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_alignment(0.0, 0.5)
        file_bug_button.connect('clicked', self.failure_file_bug_activate_link_cb)
        build_fail_tab.attach(file_bug_button, 17, 24, 4 + abs(next_action != ""), 6)

        return build_fail_top
 def show_page(self, log_file):
     children = self.button_box.get_children() or []
     for child in children:
         self.button_box.remove(child)
     # re-packed the buttons as request, add the 'open log' button if build success
     self.button_box.pack_end(self.build_image_button, expand=False, fill=False)
     if log_file:
         open_log_button = HobAltButton("Open log")
         open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
         open_log_button.set_tooltip_text("Open the build's log file")
         self.button_box.pack_end(open_log_button, expand=False, fill=False)
     self.button_box.pack_end(self.back_button, expand=False, fill=False)
     self.show_all()
Exemple #6
0
 def show_page(self, log_file):
     children = self.button_box.get_children() or []
     for child in children:
         self.button_box.remove(child)
     # re-packed the buttons as request, add the 'open log' button if build success
     self.button_box.pack_end(self.build_image_button, expand=False, fill=False)
     if log_file:
         open_log_button = HobAltButton("Open log")
         open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
         open_log_button.set_tooltip_text("Open the build's log file")
         self.button_box.pack_end(open_log_button, expand=False, fill=False)
     self.button_box.pack_end(self.back_button, expand=False, fill=False)
     self.show_all()
    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        #build_stop_top.set_size_request(-1, 200)
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 26, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked',
                              self.stop_primary_action_button_clicked_cb,
                              action)
        build_stop_tab.attach(action_button, 4, 13, 6, 9)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb,
                                    log_file)
            build_stop_tab.attach(open_log_button, 14, 23, 6, 9)

        attach_pos = (24 if log_file else 14)
        build_button = HobAltButton("Build new image")
        #build_button.set_size_request(-1, 40)
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, attach_pos, attach_pos + 9, 6, 9)

        return build_stop_top, action_button
Exemple #8
0
    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='medium'>Check the \"Issues\" information for more details</span>")
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked', self.failure_primary_action_button_clicked_cb, primary_action)
        build_fail_tab.attach(action_button, 4, 13, 9, 12)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb, log_file)
            build_fail_tab.attach(open_log_button, 14, 23, 9, 12)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text("Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked', self.failure_activate_file_bug_link_cb)
        build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9, 12)

        return build_fail_top
Exemple #9
0
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        self.button_ids = {}
        is_runnable = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist:  # and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            tooltip = "Burn your image to an external storage device"
            deploy_button.set_tooltip_text(tooltip)
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked",
                                              self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button,
                                                 expand=False,
                                                 fill=False)

        name = "Edit packages"
        if name in buttonlist:
            # create button "Edit packages"
            edit_packages_button = HobAltButton("Edit packages")
            tooltip = "Edit the list of packages included in your image"
            edit_packages_button.set_tooltip_text(tooltip)
            edit_packages_button.connect("clicked",
                                         self.edit_packages_button_clicked_cb)

            self.details_bottom_buttons.pack_end(edit_packages_button,
                                                 expand=False,
                                                 fill=False)
            button_id = edit_packages_button.connect(
                "clicked", self.edit_packages_button_clicked_cb)
            self.button_ids[button_id] = edit_packages_button

        name = "New image"
        if name in buttonlist:
            build_new_button = HobAltButton("New image")
            self.details_bottom_buttons.pack_end(build_new_button,
                                                 expand=False,
                                                 fill=False)
            build_new_button.set_tooltip_text(
                "Create a new image from scratch")
            button_id = build_new_button.connect(
                "clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button

        return is_runnable
    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        #build_stop_top.set_size_request(-1, 200)
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 26, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked', self.stop_primary_action_button_clicked_cb, action)
        build_stop_tab.attach(action_button, 4, 13, 6, 9)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb, log_file)
            build_stop_tab.attach(open_log_button, 14, 23, 6, 9)

        attach_pos = (24 if log_file else 14)
        build_button = HobAltButton("Build new image")
        #build_button.set_size_request(-1, 40)
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, attach_pos, attach_pos + 9, 6, 9)

        return build_stop_top, action_button
    def gen_proxy_entry_widget(self, protocol, parent, need_button=True, line=0):
        label = gtk.Label(protocol.upper() + " proxy")
        self.proxy_table.attach(label, 0, 1, line, line+1, xpadding=24)

        proxy_entry = gtk.Entry()
        proxy_entry.set_size_request(300, -1)
        self.proxy_table.attach(proxy_entry, 1, 2, line, line+1, ypadding=4)

        self.proxy_table.attach(gtk.Label(":"), 2, 3, line, line+1, xpadding=12, ypadding=4)

        port_entry = gtk.Entry()
        port_entry.set_size_request(60, -1)
        self.proxy_table.attach(port_entry, 3, 4, line, line+1, ypadding=4)

        details_button = HobAltButton("Details")
        details_button.connect("clicked", self.details_cb, parent, protocol)
        self.proxy_table.attach(details_button, 4, 5, line, line+1, xpadding=4, yoptions=gtk.EXPAND)

        return proxy_entry, port_entry, details_button
    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        just_bake_button = HobButton("Build image")
        just_bake_button.set_size_request(205, 49)
        just_bake_button.set_tooltip_text("Build target image")
        just_bake_button.connect("clicked", self.just_bake_button_clicked_cb)
        button_box.pack_end(just_bake_button, expand=False, fill=False)

        label = gtk.Label(" or ")
        button_box.pack_end(label, expand=False, fill=False)

        # create button "Build Packages"
        build_packages_button = HobAltButton("Build packages")
        build_packages_button.connect("clicked", self.build_packages_button_clicked_cb)
        build_packages_button.set_tooltip_text("Build recipes into packages")
        button_box.pack_end(build_packages_button, expand=False, fill=False)

        return button_box
    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        just_bake_button = HobButton("Build image")
        just_bake_button.set_size_request(205, 49)
        just_bake_button.set_tooltip_text("Build target image")
        just_bake_button.connect("clicked", self.just_bake_button_clicked_cb)
        button_box.pack_end(just_bake_button, expand=False, fill=False)

        label = gtk.Label(" or ")
        button_box.pack_end(label, expand=False, fill=False)

        # create button "Build Packages"
        build_packages_button = HobAltButton("Build packages")
        build_packages_button.connect("clicked", self.build_packages_button_clicked_cb)
        build_packages_button.set_tooltip_text("Build recipes into packages")
        button_box.pack_end(build_packages_button, expand=False, fill=False)

        return button_box
Exemple #14
0
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        self.button_ids = {}
        is_runnable = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist:  # and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            tooltip = "Burn your image to an external storage device"
            deploy_button.set_tooltip_text(tooltip)
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked", self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button, expand=False, fill=False)

        name = "Edit packages"
        if name in buttonlist:
            # create button "Edit packages"
            edit_packages_button = HobAltButton("Edit packages")
            tooltip = "Edit the list of packages included in your image"
            edit_packages_button.set_tooltip_text(tooltip)
            edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)

            self.details_bottom_buttons.pack_end(edit_packages_button, expand=False, fill=False)
            button_id = edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)
            self.button_ids[button_id] = edit_packages_button

        name = "New image"
        if name in buttonlist:
            build_new_button = HobAltButton("New image")
            self.details_bottom_buttons.pack_end(build_new_button, expand=False, fill=False)
            build_new_button.set_tooltip_text("Create a new image from scratch")
            button_id = build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button

        return is_runnable
class SimpleSettingsDialog (CrumbsDialog, SettingsUIHelper):

    (BUILD_ENV_PAGE_ID,
     SHARED_STATE_PAGE_ID,
     PROXIES_PAGE_ID,
     OTHERS_PAGE_ID) = range(4)

    (TEST_NETWORK_NONE,
     TEST_NETWORK_INITIAL,
     TEST_NETWORK_RUNNING,
     TEST_NETWORK_PASSED,
     TEST_NETWORK_FAILED,
     TEST_NETWORK_CANCELED) = range(6)

    def __init__(self, title, configuration, all_image_types,
            all_package_formats, all_distros, all_sdk_machines,
            max_threads, parent, flags, handler, buttons=None):
        super(SimpleSettingsDialog, self).__init__(title, parent, flags, buttons)

        # class members from other objects
        # bitbake settings from Builder.Configuration
        self.configuration = configuration
        self.image_types = all_image_types
        self.all_package_formats = all_package_formats
        self.all_distros = all_distros
        self.all_sdk_machines = all_sdk_machines
        self.max_threads = max_threads

        # class members for internal use
        self.dldir_text = None
        self.sstatedir_text = None
        self.sstatemirrors_list = []
        self.sstatemirrors_changed = 0
        self.bb_spinner = None
        self.pmake_spinner = None
        self.rootfs_size_spinner = None
        self.extra_size_spinner = None
        self.gplv3_checkbox = None
        self.toolchain_checkbox = None
        self.setting_store = None
        self.image_types_checkbuttons = {}

        self.md5 = self.config_md5()
        self.proxy_md5 = self.config_proxy_md5()
        self.settings_changed = False
        self.proxy_settings_changed = False
        self.handler = handler
        self.proxy_test_ran = False

        # create visual elements on the dialog
        self.create_visual_elements()
        self.connect("response", self.response_cb)

    def _get_sorted_value(self, var):
        return " ".join(sorted(str(var).split())) + "\n"

    def config_proxy_md5(self):
        data = ("ENABLE_PROXY: "         + self._get_sorted_value(self.configuration.enable_proxy))
        if self.configuration.enable_proxy:
            for protocol in self.configuration.proxies.keys():
                data += (protocol + ": " + self._get_sorted_value(self.configuration.combine_proxy(protocol)))
        return hashlib.md5(data).hexdigest()

    def config_md5(self):
        data = ""
        for key in self.configuration.extra_setting.keys():
            data += (key + ": " + self._get_sorted_value(self.configuration.extra_setting[key]))
        return hashlib.md5(data).hexdigest()

    def gen_proxy_entry_widget(self, protocol, parent, need_button=True, line=0):
        label = gtk.Label(protocol.upper() + " proxy")
        self.proxy_table.attach(label, 0, 1, line, line+1, xpadding=24)

        proxy_entry = gtk.Entry()
        proxy_entry.set_size_request(300, -1)
        self.proxy_table.attach(proxy_entry, 1, 2, line, line+1, ypadding=4)

        self.proxy_table.attach(gtk.Label(":"), 2, 3, line, line+1, xpadding=12, ypadding=4)

        port_entry = gtk.Entry()
        port_entry.set_size_request(60, -1)
        self.proxy_table.attach(port_entry, 3, 4, line, line+1, ypadding=4)

        details_button = HobAltButton("Details")
        details_button.connect("clicked", self.details_cb, parent, protocol)
        self.proxy_table.attach(details_button, 4, 5, line, line+1, xpadding=4, yoptions=gtk.EXPAND)

        return proxy_entry, port_entry, details_button

    def refresh_proxy_components(self):
        self.same_checkbox.set_sensitive(self.configuration.enable_proxy)

        self.http_proxy.set_text(self.configuration.combine_host_only("http"))
        self.http_proxy.set_editable(self.configuration.enable_proxy)
        self.http_proxy.set_sensitive(self.configuration.enable_proxy)
        self.http_proxy_port.set_text(self.configuration.combine_port_only("http"))
        self.http_proxy_port.set_editable(self.configuration.enable_proxy)
        self.http_proxy_port.set_sensitive(self.configuration.enable_proxy)
        self.http_proxy_details.set_sensitive(self.configuration.enable_proxy)

        self.https_proxy.set_text(self.configuration.combine_host_only("https"))
        self.https_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_port.set_text(self.configuration.combine_port_only("https"))
        self.https_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.ftp_proxy.set_text(self.configuration.combine_host_only("ftp"))
        self.ftp_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_port.set_text(self.configuration.combine_port_only("ftp"))
        self.ftp_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.git_proxy.set_text(self.configuration.combine_host_only("git"))
        self.git_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.git_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.git_proxy_port.set_text(self.configuration.combine_port_only("git"))
        self.git_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.git_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.git_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.cvs_proxy.set_text(self.configuration.combine_host_only("cvs"))
        self.cvs_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_port.set_text(self.configuration.combine_port_only("cvs"))
        self.cvs_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        if self.configuration.same_proxy:
            if self.http_proxy.get_text():
                [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses]
            if self.http_proxy_port.get_text():
                [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports]

    def proxy_checkbox_toggled_cb(self, button):
        self.configuration.enable_proxy = self.proxy_checkbox.get_active()
        if not self.configuration.enable_proxy:
            self.configuration.same_proxy = False
            self.same_checkbox.set_active(self.configuration.same_proxy)
        self.save_proxy_data()
        self.refresh_proxy_components()

    def same_checkbox_toggled_cb(self, button):
        self.configuration.same_proxy = self.same_checkbox.get_active()
        self.save_proxy_data()
        self.refresh_proxy_components()

    def save_proxy_data(self):
        self.configuration.split_proxy("http", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
        if self.configuration.same_proxy:
            self.configuration.split_proxy("https", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("ftp", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("git", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("cvs", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
        else:
            self.configuration.split_proxy("https", self.https_proxy.get_text() + ":" + self.https_proxy_port.get_text())
            self.configuration.split_proxy("ftp", self.ftp_proxy.get_text() + ":" + self.ftp_proxy_port.get_text())
            self.configuration.split_proxy("git", self.git_proxy.get_text() + ":" + self.git_proxy_port.get_text())
            self.configuration.split_proxy("cvs", self.cvs_proxy.get_text() + ":" + self.cvs_proxy_port.get_text())       

    def response_cb(self, dialog, response_id):
        if response_id == gtk.RESPONSE_YES:
            # Check that all proxy entries have a corresponding port
            for proxy, port in zip(self.all_proxy_addresses, self.all_proxy_ports):
                if proxy.get_text() and not port.get_text():
                    lbl = "<b>Enter all port numbers</b>\n\n"
                    msg = "Proxy servers require a port number. Please make sure you have entered a port number for each proxy server."
                    dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_WARNING, msg)
                    button = dialog.add_button("Close", gtk.RESPONSE_OK)
                    HobButton.style_button(button)
                    response = dialog.run()
                    dialog.destroy()
                    self.emit_stop_by_name("response")
                    return

        self.configuration.dldir = self.dldir_text.get_text()
        self.configuration.sstatedir = self.sstatedir_text.get_text()
        self.configuration.sstatemirror = ""
        for mirror in self.sstatemirrors_list:
            if mirror[1] != "":
                if mirror[1].endswith("\\1"):
                    smirror = mirror[2] + " " + mirror[1] + " \\n "
                else:
                    smirror = mirror[2] + " " + mirror[1] + "\\1 \\n "
                self.configuration.sstatemirror += smirror
        self.configuration.bbthread = self.bb_spinner.get_value_as_int()
        self.configuration.pmake = self.pmake_spinner.get_value_as_int()
        self.save_proxy_data()
        self.configuration.extra_setting = {}
        it = self.setting_store.get_iter_first()
        while it:
            key = self.setting_store.get_value(it, 0)
            value = self.setting_store.get_value(it, 1)
            self.configuration.extra_setting[key] = value
            it = self.setting_store.iter_next(it)

        md5 = self.config_md5()
        self.settings_changed = (self.md5 != md5)
        self.proxy_settings_changed = (self.proxy_md5 != self.config_proxy_md5())

    def create_build_environment_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)

        advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Parallel threads</span>'), expand=False, fill=False)
        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("BitBake parallel threads")
        tooltip = "Sets the number of threads that BitBake tasks can simultaneously run. See the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#var-BB_NUMBER_THREADS\">Poky reference manual</a> for information"
        bbthread_widget, self.bb_spinner = self.gen_spinner_widget(self.configuration.bbthread, 1, self.max_threads, tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(bbthread_widget, expand=False, fill=False)

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("Make parallel threads")
        tooltip = "Sets the maximum number of threads the host can use during the build. See the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#var-PARALLEL_MAKE\">Poky reference manual</a> for information"
        pmake_widget, self.pmake_spinner = self.gen_spinner_widget(self.configuration.pmake, 1, self.max_threads, tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(pmake_widget, expand=False, fill=False)

        advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Downloaded source code</span>'), expand=False, fill=False)
        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("Downloads directory")
        tooltip = "Select a folder that caches the upstream project source code"
        dldir_widget, self.dldir_text = self.gen_entry_widget(self.configuration.dldir, self, tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(dldir_widget, expand=False, fill=False)

        return advanced_vbox

    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content, tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=12)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content, tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False)

        sub_vbox = gtk.VBox(False)
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        scroll.add_with_viewport(sub_vbox)
        scroll.connect('size-allocate', self.scroll_changed)
        advanced_vbox.pack_start(scroll, gtk.TRUE, gtk.TRUE, 0)
        searched_string = "file://"

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = [ 0, "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                while sstatemirrors.find(searched_string) != -1:
                    if sstatemirrors.find(searched_string,1) != -1:
                        sstatemirror = sstatemirrors[:sstatemirrors.find(searched_string,1)]
                        sstatemirrors = sstatemirrors[sstatemirrors.find(searched_string,1):]
                    else:
                        sstatemirror = sstatemirrors
                        sstatemirrors = sstatemirrors[1:]

                    sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()]
                    if sstatemirror_fields[0] == "file://(.*)":
                        sm_list = [ 0, sstatemirror_fields[1], "file://(.*)"]
                    else:
                        sm_list = [ 1, sstatemirror_fields[1], sstatemirror_fields[0]]
                    self.sstatemirrors_list.append(sm_list)

        index = 0
        for mirror in self.sstatemirrors_list:
            if mirror[0] == 0:
                sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index)
            else:
                sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index, mirror[2])
            sub_vbox.pack_start(sstatemirror_widget, expand=False, fill=False, padding=9)
            index += 1

        table = gtk.Table(1, 1, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add another mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(150,30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=9)

        return advanced_vbox

    def refresh_shared_state_page(self):
        page_num = self.nb.get_current_page()
        self.nb.remove_page(page_num);
        self.nb.insert_page(self.create_shared_state_page(), gtk.Label("Shared state"),page_num)
        self.show_all()
        self.nb.set_current_page(page_num)

    def test_proxy_ended(self, passed):
        self.proxy_test_running = False
        self.set_test_proxy_state(self.TEST_NETWORK_PASSED if passed else self.TEST_NETWORK_FAILED)
        self.set_sensitive(True)
        self.refresh_proxy_components()

    def timer_func(self):
        self.test_proxy_progress.pulse()
        return self.proxy_test_running

    def test_network_button_cb(self, b):
        self.set_test_proxy_state(self.TEST_NETWORK_RUNNING)
        self.set_sensitive(False)
        self.save_proxy_data()
        if self.configuration.enable_proxy == True:
            self.handler.set_http_proxy(self.configuration.combine_proxy("http"))
            self.handler.set_https_proxy(self.configuration.combine_proxy("https"))
            self.handler.set_ftp_proxy(self.configuration.combine_proxy("ftp"))
            self.handler.set_git_proxy(self.configuration.combine_host_only("git"), self.configuration.combine_port_only("git"))
            self.handler.set_cvs_proxy(self.configuration.combine_host_only("cvs"), self.configuration.combine_port_only("cvs"))
        elif self.configuration.enable_proxy == False:
            self.handler.set_http_proxy("")
            self.handler.set_https_proxy("")
            self.handler.set_ftp_proxy("")
            self.handler.set_git_proxy("", "")
            self.handler.set_cvs_proxy("", "")
        self.proxy_test_ran = True
        self.proxy_test_running = True
        gobject.timeout_add(100, self.timer_func)
        self.handler.trigger_network_test()

    def test_proxy_focus_event(self, w, direction):
        if self.test_proxy_state in [self.TEST_NETWORK_PASSED, self.TEST_NETWORK_FAILED]:
            self.set_test_proxy_state(self.TEST_NETWORK_INITIAL)
        return False

    def http_proxy_changed(self, e):
        if not self.configuration.same_proxy:
            return
        if e == self.http_proxy:
            [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses]
        else:
            [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports]

    def proxy_address_focus_out_event(self, w, direction):
        text = w.get_text()
        if not text:
            return False
        if text.find("//") == -1:
            w.set_text("http://" + text)
        return False

    def set_test_proxy_state(self, state):
        if self.test_proxy_state == state:
            return
        [self.proxy_table.remove(w) for w in self.test_gui_elements]
        if state == self.TEST_NETWORK_INITIAL:
            self.proxy_table.attach(self.test_network_button, 1, 2, 5, 6)
            self.test_network_button.show()
        elif state == self.TEST_NETWORK_RUNNING:
            self.test_proxy_progress.set_rcstyle("running")
            self.test_proxy_progress.set_text("Testing network configuration")
            self.proxy_table.attach(self.test_proxy_progress, 0, 5, 5, 6, xpadding=4)
            self.test_proxy_progress.show()
        else: # passed or failed
            self.dummy_progress.update(1.0)
            if state == self.TEST_NETWORK_PASSED:
                self.dummy_progress.set_text("Your network is properly configured")
                self.dummy_progress.set_rcstyle("running")
            else:
                self.dummy_progress.set_text("Network test failed")
                self.dummy_progress.set_rcstyle("fail")
            self.proxy_table.attach(self.dummy_progress, 0, 4, 5, 6)
            self.proxy_table.attach(self.retest_network_button, 4, 5, 5, 6, xpadding=4)
            self.dummy_progress.show()
            self.retest_network_button.show()
        self.test_proxy_state = state

    def create_network_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)
        self.same_proxy_addresses = []
        self.same_proxy_ports = []
        self.all_proxy_ports = []
        self.all_proxy_addresses = []

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("<span weight=\"bold\">Set the proxies used when fetching source code</span>")
        tooltip = "Set the proxies used when fetching source code.  A blank field uses a direct internet connection."
        info = HobInfoButton(tooltip, self)
        hbox = gtk.HBox(False, 12)
        hbox.pack_start(label, expand=True, fill=True)
        hbox.pack_start(info, expand=False, fill=False)
        sub_vbox.pack_start(hbox, expand=False, fill=False)

        proxy_test_focus = []
        self.direct_checkbox = gtk.RadioButton(None, "Direct network connection")
        proxy_test_focus.append(self.direct_checkbox)
        self.direct_checkbox.set_tooltip_text("Check this box to use a direct internet connection with no proxy")
        self.direct_checkbox.set_active(not self.configuration.enable_proxy)
        sub_vbox.pack_start(self.direct_checkbox, expand=False, fill=False)

        self.proxy_checkbox = gtk.RadioButton(self.direct_checkbox, "Manual proxy configuration")
        proxy_test_focus.append(self.proxy_checkbox)
        self.proxy_checkbox.set_tooltip_text("Check this box to manually set up a specific proxy")
        self.proxy_checkbox.set_active(self.configuration.enable_proxy)
        sub_vbox.pack_start(self.proxy_checkbox, expand=False, fill=False)

        self.same_checkbox = gtk.CheckButton("Use the HTTP proxy for all protocols")
        proxy_test_focus.append(self.same_checkbox)
        self.same_checkbox.set_tooltip_text("Check this box to use the HTTP proxy for all five proxies")
        self.same_checkbox.set_active(self.configuration.same_proxy)
        hbox = gtk.HBox(False, 12)
        hbox.pack_start(self.same_checkbox, expand=False, fill=False, padding=24)
        sub_vbox.pack_start(hbox, expand=False, fill=False)

        self.proxy_table = gtk.Table(6, 5, False)
        self.http_proxy, self.http_proxy_port, self.http_proxy_details = self.gen_proxy_entry_widget(
            "http", self, True, 0)
        proxy_test_focus +=[self.http_proxy, self.http_proxy_port]
        self.http_proxy.connect("changed", self.http_proxy_changed)
        self.http_proxy_port.connect("changed", self.http_proxy_changed)

        self.https_proxy, self.https_proxy_port, self.https_proxy_details = self.gen_proxy_entry_widget(
            "https", self, True, 1)
        proxy_test_focus += [self.https_proxy, self.https_proxy_port]
        self.same_proxy_addresses.append(self.https_proxy)
        self.same_proxy_ports.append(self.https_proxy_port)

        self.ftp_proxy, self.ftp_proxy_port, self.ftp_proxy_details = self.gen_proxy_entry_widget(
            "ftp", self, True, 2)
        proxy_test_focus += [self.ftp_proxy, self.ftp_proxy_port]
        self.same_proxy_addresses.append(self.ftp_proxy)
        self.same_proxy_ports.append(self.ftp_proxy_port)

        self.git_proxy, self.git_proxy_port, self.git_proxy_details = self.gen_proxy_entry_widget(
            "git", self, True, 3)
        proxy_test_focus += [self.git_proxy, self.git_proxy_port]
        self.same_proxy_addresses.append(self.git_proxy)
        self.same_proxy_ports.append(self.git_proxy_port)

        self.cvs_proxy, self.cvs_proxy_port, self.cvs_proxy_details = self.gen_proxy_entry_widget(
            "cvs", self, True, 4)
        proxy_test_focus += [self.cvs_proxy, self.cvs_proxy_port]
        self.same_proxy_addresses.append(self.cvs_proxy)
        self.same_proxy_ports.append(self.cvs_proxy_port)
        self.all_proxy_ports = self.same_proxy_ports + [self.http_proxy_port]
        self.all_proxy_addresses = self.same_proxy_addresses + [self.http_proxy]
        sub_vbox.pack_start(self.proxy_table, expand=False, fill=False)
        self.proxy_table.show_all()

        # Create the graphical elements for the network test feature, but don't display them yet
        self.test_network_button = HobAltButton("Test network configuration")
        self.test_network_button.connect("clicked", self.test_network_button_cb)
        self.test_proxy_progress = HobProgressBar()
        self.dummy_progress = HobProgressBar()
        self.retest_network_button = HobAltButton("Retest")
        self.retest_network_button.connect("clicked", self.test_network_button_cb)
        self.test_gui_elements = [self.test_network_button, self.test_proxy_progress, self.dummy_progress, self.retest_network_button]
        # Initialize the network tester
        self.test_proxy_state = self.TEST_NETWORK_NONE
        self.set_test_proxy_state(self.TEST_NETWORK_INITIAL)
        self.proxy_test_passed_id = self.handler.connect("network-passed", lambda h:self.test_proxy_ended(True))
        self.proxy_test_failed_id = self.handler.connect("network-failed", lambda h:self.test_proxy_ended(False))
        [w.connect("focus-in-event", self.test_proxy_focus_event) for w in proxy_test_focus]
        [w.connect("focus-out-event", self.proxy_address_focus_out_event) for w in self.all_proxy_addresses]

        self.direct_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb)
        self.proxy_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb)
        self.same_checkbox.connect("toggled", self.same_checkbox_toggled_cb)

        self.refresh_proxy_components()
        return advanced_vbox

    def switch_to_page(self, page_id):
        self.nb.set_current_page(page_id)

    def details_cb(self, button, parent, protocol):
        self.save_proxy_data()
        dialog = ProxyDetailsDialog(title = protocol.upper() + " Proxy Details",
            user = self.configuration.proxies[protocol][1],
            passwd = self.configuration.proxies[protocol][2],
            parent = parent,
            flags = gtk.DIALOG_MODAL
                    | gtk.DIALOG_DESTROY_WITH_PARENT
                    | gtk.DIALOG_NO_SEPARATOR)
        dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_OK)
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.configuration.proxies[protocol][1] = dialog.user
            self.configuration.proxies[protocol][2] = dialog.passwd
            self.refresh_proxy_components()
        dialog.destroy()    

    def rootfs_combo_changed_cb(self, rootfs_combo, all_package_format, check_hbox):
        combo_item = self.rootfs_combo.get_active_text()
        for child in check_hbox.get_children():
            if isinstance(child, gtk.CheckButton):
                check_hbox.remove(child)
        for format in all_package_format:
            if format != combo_item:
                check_button = gtk.CheckButton(format)
                check_hbox.pack_start(check_button, expand=False, fill=False)
        check_hbox.show_all()

    def gen_pkgfmt_widget(self, curr_package_format, all_package_format, tooltip_combo="", tooltip_extra=""):
        pkgfmt_hbox = gtk.HBox(False, 24)

        rootfs_vbox = gtk.VBox(False, 6)
        pkgfmt_hbox.pack_start(rootfs_vbox, expand=False, fill=False)

        label = self.gen_label_widget("Root file system package format")
        rootfs_vbox.pack_start(label, expand=False, fill=False)

        rootfs_format = ""
        if curr_package_format:
            rootfs_format = curr_package_format.split()[0]

        rootfs_format_widget, rootfs_combo = self.gen_combo_widget(rootfs_format, all_package_format, tooltip_combo)
        rootfs_vbox.pack_start(rootfs_format_widget, expand=False, fill=False)

        extra_vbox = gtk.VBox(False, 6)
        pkgfmt_hbox.pack_start(extra_vbox, expand=False, fill=False)

        label = self.gen_label_widget("Additional package formats")
        extra_vbox.pack_start(label, expand=False, fill=False)

        check_hbox = gtk.HBox(False, 12)
        extra_vbox.pack_start(check_hbox, expand=False, fill=False)
        for format in all_package_format:
            if format != rootfs_format:
                check_button = gtk.CheckButton(format)
                is_active = (format in curr_package_format.split())
                check_button.set_active(is_active)
                check_hbox.pack_start(check_button, expand=False, fill=False)

        info = HobInfoButton(tooltip_extra, self)
        check_hbox.pack_end(info, expand=False, fill=False)

        rootfs_combo.connect("changed", self.rootfs_combo_changed_cb, all_package_format, check_hbox)

        pkgfmt_hbox.show_all()

        return pkgfmt_hbox, rootfs_combo, check_hbox

    def editable_settings_cell_edited(self, cell, path_string, new_text, model):
        it = model.get_iter_from_string(path_string)
        column = cell.get_data("column")
        model.set(it, column, new_text)

    def editable_settings_add_item_clicked(self, button, model):
        new_item = ["##KEY##", "##VALUE##"]

        iter = model.append()
        model.set (iter,
            0, new_item[0],
            1, new_item[1],
       )

    def editable_settings_remove_item_clicked(self, button, treeview):
        selection = treeview.get_selection()
        model, iter = selection.get_selected()

        if iter:
            path = model.get_path(iter)[0]
            model.remove(iter)
 
    def gen_editable_settings(self, setting, tooltip=""):
        setting_hbox = gtk.HBox(False, 12)

        vbox = gtk.VBox(False, 12)
        setting_hbox.pack_start(vbox, expand=True, fill=True)

        setting_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        for key in setting.keys():
            setting_store.set(setting_store.append(), 0, key, 1, setting[key])

        setting_tree = gtk.TreeView(setting_store)
        setting_tree.set_headers_visible(True)
        setting_tree.set_size_request(300, 100)

        col = gtk.TreeViewColumn('Key')
        col.set_min_width(100)
        col.set_max_width(150)
        col.set_resizable(True)
        col1 = gtk.TreeViewColumn('Value')
        col1.set_min_width(100)
        col1.set_max_width(150)
        col1.set_resizable(True)
        setting_tree.append_column(col)
        setting_tree.append_column(col1)
        cell = gtk.CellRendererText()
        cell.set_property('width-chars', 10)
        cell.set_property('editable', True)
        cell.set_data("column", 0)
        cell.connect("edited", self.editable_settings_cell_edited, setting_store)
        cell1 = gtk.CellRendererText()
        cell1.set_property('width-chars', 10)
        cell1.set_property('editable', True)
        cell1.set_data("column", 1)
        cell1.connect("edited", self.editable_settings_cell_edited, setting_store)
        col.pack_start(cell, True)
        col1.pack_end(cell1, True)
        col.set_attributes(cell, text=0)
        col1.set_attributes(cell1, text=1)

        scroll = gtk.ScrolledWindow()
        scroll.set_shadow_type(gtk.SHADOW_IN)
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll.add(setting_tree)
        vbox.pack_start(scroll, expand=True, fill=True)

        # some buttons
        hbox = gtk.HBox(True, 6)
        vbox.pack_start(hbox, False, False)

        button = gtk.Button(stock=gtk.STOCK_ADD)
        button.connect("clicked", self.editable_settings_add_item_clicked, setting_store)
        hbox.pack_start(button)

        button = gtk.Button(stock=gtk.STOCK_REMOVE)
        button.connect("clicked", self.editable_settings_remove_item_clicked, setting_tree)
        hbox.pack_start(button)

        info = HobInfoButton(tooltip, self)
        setting_hbox.pack_start(info, expand=False, fill=False)

        return setting_hbox, setting_store

    def create_others_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=True, fill=True)
        label = self.gen_label_widget("<span weight=\"bold\">Add your own variables:</span>")
        tooltip = "These are key/value pairs for your extra settings. Click \'Add\' and then directly edit the key and the value"
        setting_widget, self.setting_store = self.gen_editable_settings(self.configuration.extra_setting, tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(setting_widget, expand=True, fill=True)

        return advanced_vbox

    def create_visual_elements(self):
        self.nb = gtk.Notebook()
        self.nb.set_show_tabs(True)        
        self.nb.append_page(self.create_build_environment_page(), gtk.Label("Build environment"))
        self.nb.append_page(self.create_shared_state_page(), gtk.Label("Shared state"))
        self.nb.append_page(self.create_network_page(), gtk.Label("Network"))        
        self.nb.append_page(self.create_others_page(), gtk.Label("Others"))
        self.nb.set_current_page(0)
        self.vbox.pack_start(self.nb, expand=True, fill=True)
        self.vbox.pack_end(gtk.HSeparator(), expand=True, fill=True)

        self.show_all()

    def destroy(self):
        self.handler.disconnect(self.proxy_test_passed_id)
        self.handler.disconnect(self.proxy_test_failed_id)
        super(SimpleSettingsDialog, self).destroy()

    def scroll_changed(self, widget, event, data=None):
        adj = widget.get_vadjustment()
        adj.set_value(adj.upper - adj.page_size)
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        created = False
        packed = False
        self.button_ids = {}

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            deploy_button.set_size_request(205, 49)
            deploy_button.set_tooltip_text("Burn a live image to a USB drive or flash memory")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked", self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button, expand=False, fill=False)
            created = True
            packed = True

        name = "Run image"
        if name in buttonlist and self.test_type_runnable(image_name) and self.test_mach_runnable(image_name):
            if created == True:
                # separator
                label = gtk.Label(" or ")
                self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

                # create button "Run image"
                run_button = HobAltButton("Run image")
            else:
                # create button "Run image" as the primary button
                run_button = HobButton("Run image")
                run_button.set_size_request(205, 49)
                run_button.set_flags(gtk.CAN_DEFAULT)
                packed = True
            run_button.set_tooltip_text("Start up an image with qemu emulator")
            button_id = run_button.connect("clicked", self.run_button_clicked_cb)
            self.button_ids[button_id] = run_button
            self.details_bottom_buttons.pack_end(run_button, expand=False, fill=False)
            created = True

        if not packed:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.details_bottom_buttons.pack_end(box, False, False)

        name = "Save as template"
        if name in buttonlist:
            if created == True:
                # separator
                label = gtk.Label(" or ")
                self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

            # create button "Save as template"
            save_button = HobAltButton("Save as template")
            save_button.set_tooltip_text("Save the image configuration for reuse")
            button_id = save_button.connect("clicked", self.save_button_clicked_cb)
            self.button_ids[button_id] = save_button
            self.details_bottom_buttons.pack_end(save_button, expand=False, fill=False)
            create = True

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            build_new_button = HobAltButton("Build new image")
            build_new_button.set_tooltip_text("Create a new image from scratch")
            button_id = build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button
            self.details_bottom_buttons.pack_start(build_new_button, expand=False, fill=False)
Exemple #17
0
class BuildDetailsPage(HobPage):
    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0, )
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n")  # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status,
                                     expand=False,
                                     fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar,
                                      expand=True,
                                      fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER,
                                             gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config,
                                  "Build configuration")

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER,
                                              gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, "Issues")

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER,
                                            gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, "Log")

        self.builder.handler.build.model.connect_after(
            "row-changed", self.scroll_to_present_row,
            self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('<< Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (
            current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n")  # to ensure layout is correct
        self.endpath = (0, )

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup(
            "<span size='medium'>Check the \"Issues\" information for more details</span>"
        )
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked',
                              self.failure_primary_action_button_clicked_cb,
                              primary_action)
        build_fail_tab.attach(action_button, 4, 13, 9, 12)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked',
                                    self.failure_open_log_button_clicked_cb,
                                    log_file)
            build_fail_tab.attach(open_log_button, 14, 23, 9, 12)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text(
            "Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked',
                                self.failure_activate_file_bug_link_cb)
        build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9,
                              12)

        return build_fail_top

    def show_fail_page(self, title, action_names):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(
            action_names, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar,
                                       expand=False,
                                       fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[
                    0]:  # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value
                                                        == v_adj.upper -
                                                        v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages()
        elif "Edit image configuration" in action:
            self.builder.show_configuration()

    def failure_open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            os.system("xdg-open /%s" % log_file)

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
Exemple #18
0
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        created = False
        packed = False
        self.button_ids = {}
        is_runnable = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            #deploy_button.set_size_request(205, 49)
            deploy_button.set_tooltip_text("Burn a live image to a USB drive or flash memory")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked", self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button, expand=False, fill=False)
            created = True
            packed = True

        name = "Run image"
        if name in buttonlist:
            name = "Run qemu image"
            is_runnable = True
            if not (self.test_type_runnable(image_name) and self.test_mach_runnable(image_name)):
                name = "Run custom image"
                is_runnable = False
            if created == True:
                # separator
                #label = gtk.Label(" or ")
                #self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

                # create button "Run image"
                run_button = HobAltButton(name)
            else:
                # create button "Run image" as the primary button
                run_button = HobButton(name)
                #run_button.set_size_request(205, 49)
                run_button.set_flags(gtk.CAN_DEFAULT)
                packed = True
            if is_runnable:
                run_button.set_tooltip_text("Start up an image with qemu emulator")
            else:
                run_button.set_tooltip_text("Start up an image with custom simulator")
            button_id = run_button.connect("clicked", self.run_button_clicked_cb)
            self.button_ids[button_id] = run_button
            self.details_bottom_buttons.pack_end(run_button, expand=False, fill=False)
            created = True

        name = "Save image recipe"
        if name in buttonlist and self.builder.recipe_model.is_custom_image():
            save_button = HobAltButton("Save image recipe")
            save_button.set_tooltip_text("Keep your changes saving them as an image recipe")
            save_button.set_sensitive(not self.image_saved)
            button_id = save_button.connect("clicked", self.save_button_clicked_cb)
            self.button_ids[button_id] = save_button
            self.details_bottom_buttons.pack_end(save_button, expand=False, fill=False)

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            if packed:
                build_new_button = HobAltButton("Build new image")
            else:
                build_new_button = HobButton("Build new image")
                build_new_button.set_flags(gtk.CAN_DEFAULT)
            #build_new_button.set_size_request(205, 49)
            self.details_bottom_buttons.pack_end(build_new_button, expand=False, fill=False)
            build_new_button.set_tooltip_text("Create a new image from scratch")
            button_id = build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button

        return is_runnable
    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content,"<b>Shared state directory</b>" + "*" + tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=6)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content,"<b>Shared state mirrors</b>" + "*" + tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, gtk.TRUE, gtk.TRUE, 0)

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = ["Standard", "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                sstatemirrors = [x for x in sstatemirrors.split('\\n')]
                for sstatemirror in sstatemirrors:
                    sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()]
                    if len(sstatemirror_fields) == 2:
                        if sstatemirror_fields[0] == "file://(.*)" or sstatemirror_fields[0] == "file://.*":
                            sm_list = ["Standard", sstatemirror_fields[1], sstatemirror_fields[0]]
                        else:
                            sm_list = ["Custom", sstatemirror_fields[1], sstatemirror_fields[0]]
                        self.sstatemirrors_list.append(sm_list)

        sstatemirrors_widget, sstatemirrors_store = self.gen_shared_sstate_widget(self.sstatemirrors_list, self)
        sub_vbox.pack_start(sstatemirrors_widget, expand=True, fill=True)

        table = gtk.Table(1, 10, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(120,30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)

        self.delete_button = HobAltButton("Delete mirror")
        self.delete_button.connect("clicked", self.delete_cb)
        self.delete_button.set_size_request(120, 30)
        table.attach(self.delete_button, 3, 4, 0, 1, xoptions=gtk.SHRINK)

        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        return advanced_vbox
class BuildDetailsPage(HobPage):
    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0, )
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n")  # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status,
                                     expand=False,
                                     fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar,
                                      expand=True,
                                      fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER,
                                             gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config,
                                  gtk.Label("Build configuration"))

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER,
                                              gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure,
                                  gtk.Label("Issues"))

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER,
                                            gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, gtk.Label("Log"))

        self.builder.handler.build.model.connect_after(
            "row-changed", self.scroll_to_present_row,
            self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (
            current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n")  # to ensure layout is correct
        self.endpath = (0, )

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[
                    0]:  # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value
                                                        == v_adj.upper -
                                                        v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)
class ImageConfigurationPage (HobPage):

    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder, "Image configuration")

        self.image_combo_id = None
        self.custom_image_selected = None
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button = False):
        self._remove_all_widget()
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button, expand=False, fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_text(title)
        self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button = False)
        self.set_config_distro_layout(show_progress_bar = True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = True)
        self.set_config_distro_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = True)
        self.set_config_distro_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()

    def create_config_machine(self):
        self.progress_bar = HobProgressBar()

    def set_config_distro_layout(self, show_progress_bar = False):
        if show_progress_bar:
            self.gtable.attach(self.progress_bar, 0, 40, 12, 15)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 0)
        mark = "<span %s>Select an image to build</span>" % self.span_tag('x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo.set_row_separator_func(self.combo_separator_func, None)
        self.image_combo.set_tooltip_text("Select an image to see a description of it")
        self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0, 0)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        self.toolchain_checkbox = gtk.CheckButton("Build a matching toolchain")
        self.toolchain_checkbox.set_active(self.builder.configuration.toolchain_build)
        tooltip = "Check this box to generate a toolchain installer "
        tooltip += "that contains a sysroot for your selected image"
        self.toolchain_checkbox.set_tooltip_text(tooltip)

    def combo_separator_func(self, model, iter, user_data):
        name = model.get_value(iter, 0)
        if name == "--Separator--":
            return True

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 8, 11)
        self.gtable.attach(self.image_combo, 0, 20, 12, 15)
        self.gtable.attach(self.image_desc, 0, 40, 16, 20)
        self.gtable.attach(self.toolchain_checkbox, 0, 40, 21, 24)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        tooltip = "Build your selected image"
        self.just_bake_button.set_tooltip_text(tooltip)
        self.just_bake_button.connect("clicked", self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit packages"
        self.edit_image_button = HobAltButton("Edit packages")
        tooltip = "Customize the list of packages to be included in your image"
        self.edit_image_button.set_tooltip_text(tooltip)
        self.edit_image_button.connect("clicked", self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys():
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes, selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        if not self.builder.request_pkg_info:
            self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if selected_image:
            self.builder.customized = False

            selected_recipes = []

            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)

            distro = self.builder.parameters.image_list[selected_image]
            self.builder.set_distro_packages(distro)

            selected_packages = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_INSTALL).split()
            self.update_image_desc()

            self.builder.recipe_model.reset()
            self.builder.package_model.reset()

            self.show_baseimg_selected()

            glib.idle_add(self.image_combo_changed_idle_cb, selected_image, selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, selected_image):
        model = self.image_combo.get_model()
        model.clear()

        active = 0
        cnt = 0
        for image_name in self.builder.parameters.image_list.keys():
            self.image_combo.append_text(image_name)
            if image_name == selected_image:
                active = cnt
            cnt = cnt + 1
        self.image_combo.set_active(active)

    def update_conf(self):
        self.builder.configuration.toolchain_build = self.toolchain_checkbox.get_active()

    def just_bake_button_clicked_cb(self, button):
        self.update_conf()
        self.builder.build_image()

    def edit_image_button_clicked_cb(self, button):
        self.update_conf()
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_packages(ask=False)
Exemple #22
0
class PackageSelectionPage(HobPage):

    pages = [{
        'name':
        'Included',
        'filter': {
            PackageListModel.COL_INC: [True]
        },
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by',
            'col_id': PackageListModel.COL_BINB,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'binb',
            'col_min': 100,
            'col_max': 350,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'check toggle',
            'col_group': 'tree store group',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'All packages',
        'filter': {},
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_t_id': PackageListModel.COL_FONT,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 500,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_group': 'tree store group',
            'col_min': 100,
            'col_max': 100
        }]
    }]

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Packages")

        # set invisiable members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(0)

    def create_visual_elements(self):
        self.label = gtk.Label(
            "Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need to modify table when the dialog is shown
        # append the tab
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            filter = page['filter']
            tab.set_model(self.package_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            tab.connect_group_selection(self.table_selected_cb)
            if page['name'] == "Included":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page['name'])
            self.tables.append(tab)

        self.ins.set_entry("Search packages:")
        # set the search entry for each table
        for tab in self.tables:
            tab.set_search_entry(0, self.ins.search)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(button_box, expand=False, fill=False)

        self.build_image_button = HobButton('Build image')
        self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        button_box.pack_end(self.build_image_button, expand=False, fill=False)

        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_start(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path:  # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path),
                                        PackageListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def build_image_clicked_cb(self, button):
        self.builder.build_image()

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def _expand_all(self):
        for tab in self.tables:
            tab.table_tree.expand_all()

    def refresh_selection(self):
        self._expand_all()

        self.builder.configuration.selected_packages = self.package_model.get_selected_packages(
        )
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages(
        )
        selected_packages_num = len(
            self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(
            selected_packages_size)

        image_overhead_factor = self.builder.configuration.image_overhead_factor
        image_rootfs_size = self.builder.configuration.image_rootfs_size * 1024  # image_rootfs_size is KB
        image_extra_size = self.builder.configuration.image_extra_size * 1024  # image_extra_size is KB
        base_size = image_overhead_factor * selected_packages_size
        image_total_size = max(base_size, image_rootfs_size) + image_extra_size
        if "zypper" in self.builder.configuration.selected_packages:
            image_total_size += (51200 * 1024)
        image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_label(
            "Packages included: %s\nSelected packages size: %s\nTotal image size: %s"
            % (selected_packages_num, selected_packages_size_str,
               image_total_size_str))
        self.ins.show_indicator_icon("Included", selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path,
                                            binb="User Selected")
        else:
            if pagename == "Included":
                self.pre_fadeout_checkout_include(view_tree)
                self.package_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.package_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        self.package_model.resync_fadeout_column(
            self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {PackageListModel.COL_FADE_INC: [True]}
        new_model = self.package_model.tree_model(filter)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(
                it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model,
                                       model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model,
                               view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.package_model.tree_model(self.pages[0]['filter']))
        tree.expand_all()

    def foreach_cell_change_font(self, model, path, iter, paths=None):
        # Changed the font for a group cells
        if path and iter and path[0] == paths[0]:
            self.package_model.set(iter, self.package_model.COL_FONT, "bold")
        else:
            if iter and model.iter_parent(iter) == None:
                self.package_model.set(iter, self.package_model.COL_FONT, '11')
            else:
                self.package_model.set(iter, self.package_model.COL_FONT, '10')

    def table_selected_cb(self, selection):
        model, paths = selection.get_selected_rows()
        if paths:
            child_path = self.package_model.convert_vpath_to_path(
                model, paths[0])
            self.package_model.foreach(self.foreach_cell_change_font,
                                       child_path)
class BuildDetailsPage (HobPage):

    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0,)
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n") # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status, expand=False, fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow ()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config, gtk.Label("Build configuration"))

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow ()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, gtk.Label("Issues"))

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow ()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, gtk.Label("Log"))

        self.builder.handler.build.model.connect_after("row-changed", self.scroll_to_present_row, self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n") # to ensure layout is correct
        self.endpath = (0,)

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[0]: # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value == v_adj.upper - v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)
Exemple #24
0
class BuildDetailsPage(HobPage):
    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0, )
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar,
                                      expand=True,
                                      fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        tooltip = "Cancel build in progress"
        self.stop_button.set_tooltip_text(tooltip)
        self.stop_button.set_sensitive(True)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER,
                                            gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)

        self.builder.handler.build.model.connect_after(
            "row-changed", self.scroll_to_present_row,
            self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('&lt;&lt; Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def reset_build_status(self):
        self.endpath = (0, )

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 40, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build."
            label.set_markup(markup)
            build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked',
                              self.failure_primary_action_button_clicked_cb,
                              primary_action)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 19, 9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked',
                                  self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)

        self.builder.disk_full = False
        return build_fail_top

    def show_fail_page(self, title):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(
            title, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar,
                                       expand=False,
                                       fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()

    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 40, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked',
                              self.stop_primary_action_button_clicked_cb,
                              action)
        build_stop_tab.attach(action_button, 4, 20, 6, 9)

        build_button = HobAltButton("Build new image")
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, 21, 40, 6, 9)

        return build_stop_top, action_button

    def show_stop_page(self, action):
        self._remove_all_widget()
        self.title = "Build stopped"
        self.build_stop_bar, action_button = self.add_build_stop_top_bar(
            action, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_stop_bar,
                                       expand=False,
                                       fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()
        return action_button

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None, padding=15)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def new_image_button_clicked_cb(self, button):
        self.builder.populate_recipe_package_info_async()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[
                    0]:  # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value
                                                        == v_adj.upper -
                                                        v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages(ask=False)
        elif "Edit image" in action:
            self.builder.show_configuration()

    def restart_build_button_clicked_cb(self, button):
        self.builder.just_bake()

    def stop_primary_action_button_clicked_cb(self, button, action):
        if "recipes" in action:
            self.builder.show_recipes()
        elif "packages" in action:
            self.builder.show_packages(ask=False)
        elif "image" in action:
            self.builder.show_configuration()

    def open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
Exemple #25
0
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        created = False
        packed = False
        self.button_ids = {}
        is_runnable = False

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            #deploy_button.set_size_request(205, 49)
            deploy_button.set_tooltip_text(
                "Burn a live image to a USB drive or flash memory")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked",
                                              self.deploy_button_clicked_cb)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button,
                                                 expand=False,
                                                 fill=False)
            created = True
            packed = True

        name = "Run image"
        if name in buttonlist and self.test_type_runnable(
                image_name) and self.test_mach_runnable(image_name):
            if created == True:
                # separator
                #label = gtk.Label(" or ")
                #self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

                # create button "Run image"
                run_button = HobAltButton("Run image")
            else:
                # create button "Run image" as the primary button
                run_button = HobButton("Run image")
                #run_button.set_size_request(205, 49)
                run_button.set_flags(gtk.CAN_DEFAULT)
                packed = True
            run_button.set_tooltip_text("Start up an image with qemu emulator")
            button_id = run_button.connect("clicked",
                                           self.run_button_clicked_cb)
            self.button_ids[button_id] = run_button
            self.details_bottom_buttons.pack_end(run_button,
                                                 expand=False,
                                                 fill=False)
            created = True
            is_runnable = True

        name = "Save image recipe"
        if name in buttonlist and self.builder.recipe_model.is_custom_image():
            save_button = HobAltButton("Save image recipe")
            save_button.set_tooltip_text(
                "Keep your changes saving them as an image recipe")
            save_button.set_sensitive(not self.image_saved)
            button_id = save_button.connect("clicked",
                                            self.save_button_clicked_cb)
            self.button_ids[button_id] = save_button
            self.details_bottom_buttons.pack_end(save_button,
                                                 expand=False,
                                                 fill=False)

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            if packed:
                build_new_button = HobAltButton("Build new image")
            else:
                build_new_button = HobButton("Build new image")
                build_new_button.set_flags(gtk.CAN_DEFAULT)
            #build_new_button.set_size_request(205, 49)
            self.details_bottom_buttons.pack_end(build_new_button,
                                                 expand=False,
                                                 fill=False)
            build_new_button.set_tooltip_text(
                "Create a new image from scratch")
            button_id = build_new_button.connect(
                "clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button

        return is_runnable
class PackageSelectionPage(HobPage):

    pages = [
        {
            "name": "Included packages",
            "tooltip": "The packages currently included for your image",
            "filter": {PackageListModel.COL_INC: [True]},
            "columns": [
                {
                    "col_name": "Package name",
                    "col_id": PackageListModel.COL_NAME,
                    "col_style": "text",
                    "col_min": 100,
                    "col_max": 300,
                    "expand": "True",
                },
                {
                    "col_name": "Size",
                    "col_id": PackageListModel.COL_SIZE,
                    "col_style": "text",
                    "col_min": 100,
                    "col_max": 300,
                    "expand": "True",
                },
                {
                    "col_name": "Brought in by (+others)",
                    "col_id": PackageListModel.COL_BINB,
                    "col_style": "binb",
                    "col_min": 100,
                    "col_max": 350,
                    "expand": "True",
                },
                {
                    "col_name": "Included",
                    "col_id": PackageListModel.COL_INC,
                    "col_style": "check toggle",
                    "col_min": 100,
                    "col_max": 100,
                },
            ],
        },
        {
            "name": "All packages",
            "tooltip": "All packages that have been built",
            "filter": {},
            "columns": [
                {
                    "col_name": "Package name",
                    "col_id": PackageListModel.COL_NAME,
                    "col_style": "text",
                    "col_min": 100,
                    "col_max": 400,
                    "expand": "True",
                },
                {
                    "col_name": "Size",
                    "col_id": PackageListModel.COL_SIZE,
                    "col_style": "text",
                    "col_min": 100,
                    "col_max": 500,
                    "expand": "True",
                },
                {
                    "col_name": "Included",
                    "col_id": PackageListModel.COL_INC,
                    "col_style": "check toggle",
                    "col_min": 100,
                    "col_max": 100,
                },
            ],
        },
    ]

    (INCLUDED, ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisiable members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.label = gtk.Label("Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need to modify table when the dialog is shown
        # append the tab
        for page in self.pages:
            columns = page["columns"]
            tab = HobViewTable(columns)
            filter = page["filter"]
            tab.set_model(self.package_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page["name"])
            if page["name"] == "Included packages":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page["name"], page["tooltip"])
            self.tables.append(tab)

        self.ins.set_entry("Search packages:")
        # set the search entry for each table
        for tab in self.tables:
            search_tip = "Enter a package name to find it"
            self.ins.search.set_tooltip_text(search_tip)
            self.ins.search.props.has_tooltip = True
            tab.set_search_entry(0, self.ins.search)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box, expand=False, fill=False)

        self.build_image_button = HobButton("Build image")
        # self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)

        self.back_button = HobAltButton("Cancel")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path:  # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            self.stop = False
            dialog = OpeningLogDialog(
                title="Opening Log",
                parent=None,
                flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
            )
            # create a thread to open log file
            background = OpeningLogThread(dialog, log_file, self)
            background.start()
            response = dialog.run()
            self.stop = True
            background.join()

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        self.builder.build_image()

    def back_button_clicked_cb(self, button):
        if self.builder.previous_step == self.builder.IMAGE_GENERATED:
            self.builder.restore_initial_selected_packages()
            self.refresh_selection()
            self.builder.show_image_details()
        else:
            self.builder.show_configuration()

    def _expand_all(self):
        for tab in self.tables:
            tab.table_tree.expand_all()

    def refresh_selection(self):
        self._expand_all()

        self.builder.configuration.selected_packages = self.package_model.get_selected_packages()
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages()
        selected_packages_num = len(self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(selected_packages_size)

        image_overhead_factor = self.builder.configuration.image_overhead_factor
        image_rootfs_size = self.builder.configuration.image_rootfs_size / 1024  # image_rootfs_size is KB
        image_extra_size = self.builder.configuration.image_extra_size / 1024  # image_extra_size is KB
        base_size = image_overhead_factor * selected_packages_size
        image_total_size = max(base_size, image_rootfs_size) + image_extra_size
        if "zypper" in self.builder.configuration.selected_packages:
            image_total_size += 51200 * 1024
        image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_label(
            "Packages included: %s\nSelected packages size: %s\nTotal image size: %s"
            % (selected_packages_num, selected_packages_size_str, image_total_size_str)
        )
        self.ins.show_indicator_icon("Included packages", selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path, binb="User Selected")
        else:
            if pagename == "Included packages":
                self.pre_fadeout_checkout_include(view_tree)
                self.package_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.package_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree):
        self.package_model.resync_fadeout_column(self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {PackageListModel.COL_FADE_INC: [True]}
        new_model = self.package_model.tree_model(filter)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model, model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model, view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.package_model.tree_model(self.pages[0]["filter"]))
        tree.expand_all()

    def set_packages_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
class RecipeSelectionPage(HobPage):
    pages = [{
        'name':
        'Included',
        'tooltip':
        'The recipes currently included for your image',
        'filter': {
            RecipeListModel.COL_INC: [True],
            RecipeListModel.COL_TYPE: ['recipe', 'task']
        },
        'columns': [{
            'col_name': 'Recipe name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by',
            'col_id': RecipeListModel.COL_BINB,
            'col_style': 'binb',
            'col_min': 100,
            'col_max': 500,
            'expand': 'True'
        }, {
            'col_name': 'Group',
            'col_id': RecipeListModel.COL_GROUP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'All recipes',
        'tooltip':
        'All recipes available in the Yocto Project',
        'filter': {
            RecipeListModel.COL_TYPE: ['recipe']
        },
        'columns': [{
            'col_name': 'Recipe name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'License',
            'col_id': RecipeListModel.COL_LIC,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Group',
            'col_id': RecipeListModel.COL_GROUP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'Tasks',
        'tooltip':
        'All tasks available in the Yocto Project',
        'filter': {
            RecipeListModel.COL_TYPE: ['task']
        },
        'columns': [{
            'col_name': 'Task name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Description',
            'col_id': RecipeListModel.COL_DESC,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }]

    def __init__(self, builder=None):
        super(RecipeSelectionPage, self).__init__(builder, "Recipes")

        # set invisiable members
        self.recipe_model = self.builder.recipe_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(0)

    def create_visual_elements(self):
        self.eventbox = self.add_onto_top_bar(None, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need modify table when the dialog is shown
        # append the tabs in order
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            filter = page['filter']
            tab.set_model(self.recipe_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            if page['name'] == "Included":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry("Search recipes:")
        # set the search entry for each table
        for tab in self.tables:
            search_tip = "Enter a recipe's or task's name to find it"
            self.ins.search.set_tooltip_text(search_tip)
            self.ins.search.props.has_tooltip = True
            tab.set_search_entry(0, self.ins.search)

        # add all into the window
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_end(button_box, expand=False, fill=False)

        self.build_packages_button = HobButton('Build packages')
        self.build_packages_button.set_size_request(205, 49)
        self.build_packages_button.set_tooltip_text(
            "Build selected recipes into packages")
        self.build_packages_button.set_flags(gtk.CAN_DEFAULT)
        self.build_packages_button.grab_default()
        self.build_packages_button.connect("clicked",
                                           self.build_packages_clicked_cb)
        button_box.pack_end(self.build_packages_button,
                            expand=False,
                            fill=False)

        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_start(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path:  # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path),
                                        RecipeListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def build_packages_clicked_cb(self, button):
        self.builder.build_packages()

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def refresh_selection(self):
        self.builder.configuration.selected_image = self.recipe_model.get_selected_image(
        )
        _, self.builder.configuration.selected_recipes = self.recipe_model.get_selected_recipes(
        )
        self.ins.show_indicator_icon(
            "Included", len(self.builder.configuration.selected_recipes))

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.recipe_model.path_included(path):
            self.recipe_model.include_item(item_path=path,
                                           binb="User Selected",
                                           image_contents=False)
        else:
            if pagename == "Included":
                self.pre_fadeout_checkout_include(view_tree)
                self.recipe_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.recipe_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a recipe
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.recipe_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        #resync the included items to a backup fade include column
        it = self.recipe_model.get_iter_first()
        while it:
            active = self.recipe_model.get_value(it, self.recipe_model.COL_INC)
            self.recipe_model.set(it, self.recipe_model.COL_FADE_INC, active)
            it = self.recipe_model.iter_next(it)
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {
            RecipeListModel.COL_FADE_INC: [True],
            RecipeListModel.COL_TYPE: ['recipe', 'task']
        }
        new_model = self.recipe_model.tree_model(filter,
                                                 excluded_items_ahead=True)
        tree.set_model(new_model)

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        model = tree.get_model()
        it = model.get_iter_first()
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it,
                                                  RecipeListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, RecipeListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            it = model.iter_next(it)

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.recipe_model.tree_model(self.pages[0]['filter']))
class BuildDetailsPage(HobPage):
    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0, )
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n")  # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status,
                                     expand=False,
                                     fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar,
                                      expand=True,
                                      fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER,
                                             gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config,
                                  "Build configuration")

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER,
                                              gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, "Issues")

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER,
                                            gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, "Log")

        self.builder.handler.build.model.connect_after(
            "row-changed", self.scroll_to_present_row,
            self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('&lt;&lt; Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (
            current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n")  # to ensure layout is correct
        self.endpath = (0, )

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build. Check the \"Issues\" tab for more details</span>"
            label.set_markup(markup)
        else:
            label.set_markup(
                "<span size='medium'>Check the \"Issues\" information for more details</span>"
            )
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked',
                              self.failure_primary_action_button_clicked_cb,
                              primary_action)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb,
                                    log_file)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text(
            "Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked',
                                self.failure_activate_file_bug_link_cb)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 13, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, 14, 23, 9, 12)
            build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9,
                                  9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked',
                                  self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, attach_pos,
                                      attach_pos + 9, 9, 12)

        self.builder.disk_full = False
        return build_fail_top

    def show_fail_page(self, title):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(
            title, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar,
                                       expand=False,
                                       fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)
        self.show_all()
        self.notebook.set_page("Issues")
        self.back_button.hide()

    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        #build_stop_top.set_size_request(-1, 200)
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 26, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked',
                              self.stop_primary_action_button_clicked_cb,
                              action)
        build_stop_tab.attach(action_button, 4, 13, 6, 9)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb,
                                    log_file)
            build_stop_tab.attach(open_log_button, 14, 23, 6, 9)

        attach_pos = (24 if log_file else 14)
        build_button = HobAltButton("Build new image")
        #build_button.set_size_request(-1, 40)
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, attach_pos, attach_pos + 9, 6, 9)

        return build_stop_top, action_button

    def show_stop_page(self, action):
        self._remove_all_widget()
        self.title = "Build stopped"
        self.build_stop_bar, action_button = self.add_build_stop_top_bar(
            action, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_stop_bar,
                                       expand=False,
                                       fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()
        return action_button

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.notebook.set_page("Log")
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def new_image_button_clicked_cb(self, button):
        self.builder.reset()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[
                    0]:  # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value
                                                        == v_adj.upper -
                                                        v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages()
        elif "Edit image" in action:
            self.builder.show_configuration()

    def restart_build_button_clicked_cb(self, button):
        self.builder.just_bake()

    def stop_primary_action_button_clicked_cb(self, button, action):
        if "recipes" in action:
            self.builder.show_recipes()
        elif "packages" in action:
            self.builder.show_packages(ask=False)
        elif "image" in action:
            self.builder.show_configuration()

    def open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            self.stop = False
            dialog = OpeningLogDialog(title="Opening Log",
                                      parent=None,
                                      flags=gtk.DIALOG_MODAL
                                      | gtk.DIALOG_DESTROY_WITH_PARENT
                                      | gtk.DIALOG_NO_SEPARATOR)
            #create a thread to open log file
            background = OpeningLogThread(dialog, log_file, self)
            background.start()
            response = dialog.run()
            self.stop = True
            background.join()

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
Exemple #29
0
    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox,
                                 expand=False,
                                 fill=False,
                                 padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content, tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(
            self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget,
                            expand=False,
                            fill=False,
                            padding=12)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content, tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False)

        sub_vbox = gtk.VBox(False)
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        scroll.add_with_viewport(sub_vbox)
        scroll.connect('size-allocate', self.scroll_changed)
        advanced_vbox.pack_start(scroll, gtk.TRUE, gtk.TRUE, 0)
        searched_string = "file://"

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = [0, "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                while sstatemirrors.find(searched_string) != -1:
                    if sstatemirrors.find(searched_string, 1) != -1:
                        sstatemirror = sstatemirrors[:sstatemirrors.
                                                     find(searched_string, 1)]
                        sstatemirrors = sstatemirrors[
                            sstatemirrors.find(searched_string, 1):]
                    else:
                        sstatemirror = sstatemirrors
                        sstatemirrors = sstatemirrors[1:]

                    sstatemirror_fields = [
                        x for x in sstatemirror.split(' ') if x.strip()
                    ]
                    if sstatemirror_fields[0] == "file://(.*)":
                        sm_list = [0, sstatemirror_fields[1], "file://(.*)"]
                    else:
                        sm_list = [
                            1, sstatemirror_fields[1], sstatemirror_fields[0]
                        ]
                    self.sstatemirrors_list.append(sm_list)

        index = 0
        for mirror in self.sstatemirrors_list:
            if mirror[0] == 0:
                sstatemirror_widget = self.gen_mirror_entry_widget(
                    mirror[1], index)
            else:
                sstatemirror_widget = self.gen_mirror_entry_widget(
                    mirror[1], index, mirror[2])
            sub_vbox.pack_start(sstatemirror_widget,
                                expand=False,
                                fill=False,
                                padding=9)
            index += 1

        table = gtk.Table(1, 1, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add another mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(150, 30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=9)

        return advanced_vbox
class PackageSelectionPage (HobPage):

    pages = [
        {
         'name'      : 'Included packages',
         'tooltip'   : 'The packages currently included for your image',
         'filter'    : { PackageListModel.COL_INC : [True] },
         'search'    : 'Search packages by name',
         'searchtip' : 'Enter a package name to find it',
         'columns'   : [{
                       'col_name' : 'Package name',
                       'col_id'   : PackageListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Size',
                       'col_id'   : PackageListModel.COL_SIZE,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Recipe',
                       'col_id'   : PackageListModel.COL_RCP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 250,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Brought in by (+others)',
                       'col_id'   : PackageListModel.COL_BINB,
                       'col_style': 'binb',
                       'col_min'  : 100,
                       'col_max'  : 350,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : PackageListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                     }]
        }, {
         'name'      : 'All packages',
         'tooltip'   : 'All packages that have been built',
         'filter'    : {},
         'search'    : 'Search packages by name',
         'searchtip' : 'Enter a package name to find it',
         'columns'   : [{
                       'col_name' : 'Package name',
                       'col_id'   : PackageListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Size',
                       'col_id'   : PackageListModel.COL_SIZE,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 500,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Recipe',
                       'col_id'   : PackageListModel.COL_RCP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 250,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : PackageListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }
    ]
    
    (INCLUDED,
     ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisible members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.label = gtk.Label("Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = [] # we need to modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tab
        for page in self.pages:
            columns = page['columns']
            name = page['name']
            tab = HobViewTable(columns, name)
            search_names.append(page['search'])
            search_tips.append(page['searchtip'])
            filter = page['filter']
            sort_model = self.package_model.tree_model(filter, initial=True)
            tab.set_model(sort_model)
            tab.connect("toggled", self.table_toggled_cb, name)
            tab.connect("button-release-event", self.button_click_cb)
            tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include, filter)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box, expand=False, fill=False)

        self.build_image_button = HobButton('Build image')
        #self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = self.ins.get_current_page()
        filter = self.pages[current_tab]['filter']
        filter[PackageListModel.COL_NAME] = text
        self.tables[current_tab].set_model(self.package_model.tree_model(filter, search_data=text))
        if self.package_model.filtered_nb == 0:
            if not self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).add_no_result_bar(entry)
                self.ins.get_nth_page(current_tab).top_bar.set_no_show_all(True)
            self.ins.get_nth_page(current_tab).top_bar.show()
            self.ins.get_nth_page(current_tab).scroll.hide()
        else:
            if self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).top_bar.hide()
            self.ins.get_nth_page(current_tab).scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title() != 'Included': # else activation is likely a removal
            properties = {'binb': '' , 'name': '', 'size':'', 'recipe':'', 'files_list':''}
            properties['binb'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_BINB)
            properties['name'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_NAME)
            properties['size'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_SIZE)
            properties['recipe'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_RCP)
            properties['files_list'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_FLIST)

            self.builder.show_recipe_property_dialog(properties)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        self.builder.parsing_warnings = []
        self.builder.build_image()

    def refresh_tables(self):
        self.ins.reset_entry(self.ins.search, 0)
        for tab in self.tables:
            index = self.tables.index(tab)
            filter = self.pages[index]['filter']
            tab.set_model(self.package_model.tree_model(filter, initial=True))

    def back_button_clicked_cb(self, button):
        if self.builder.previous_step ==  self.builder.IMAGE_GENERATED:
            self.builder.restore_initial_selected_packages()
            self.refresh_selection()
            self.builder.show_image_details()
        else:
            self.builder.show_configuration()
        self.refresh_tables()

    def refresh_selection(self):
        self.builder.configuration.selected_packages = self.package_model.get_selected_packages()
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages()
        selected_packages_num = len(self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(selected_packages_size)

        if self.builder.configuration.image_packages == self.builder.configuration.selected_packages:
            image_total_size_str = self.builder.configuration.image_size
        else:
            image_overhead_factor = self.builder.configuration.image_overhead_factor
            image_rootfs_size = self.builder.configuration.image_rootfs_size / 1024 # image_rootfs_size is KB
            image_extra_size = self.builder.configuration.image_extra_size / 1024 # image_extra_size is KB
            base_size = image_overhead_factor * selected_packages_size
            image_total_size = max(base_size, image_rootfs_size) + image_extra_size
            if "zypper" in self.builder.configuration.selected_packages:
                image_total_size += (51200 * 1024)
            image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_label("Packages included: %s\nSelected packages size: %s\nTotal image size: %s" %
                            (selected_packages_num, selected_packages_size_str, image_total_size_str))
        self.ins.show_indicator_icon("Included packages", selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path, binb="User Selected")
        else:
            self.pre_fadeout_checkout_include(view_tree)
            self.package_model.exclude_item(item_path=path)
            self.render_fadeout(view_tree, cell)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)
        view_model = view_tree.get_model()
        vpath = self.package_model.convert_path_to_vpath(view_model, path)
        view_tree.set_cursor(vpath)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree):
        #after the fadeout the table will be sorted as before
        self.sort_column_id = self.package_model.sort_column_id
        self.sort_order = self.package_model.sort_order

        self.package_model.resync_fadeout_column(self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = { PackageListModel.COL_FADE_INC  : [True]}
        new_model = self.package_model.tree_model(filter, excluded_items_ahead=True)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model, model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model, view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree, filter):
        self.package_model.sort_column_id = self.sort_column_id
        self.package_model.sort_order = self.sort_order
        tree.set_model(self.package_model.tree_model(filter))
        tree.expand_all()

    def set_packages_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
class RecipeSelectionPage (HobPage):
    pages = [
        {
         'name'      : 'Included recipes',
         'tooltip'   : 'The recipes currently included for your image',
         'filter'    : { RecipeListModel.COL_INC  : [True],
                       RecipeListModel.COL_TYPE : ['recipe', 'packagegroup'] },
         'search'    : 'Search recipes by name',
         'searchtip' : 'Enter a recipe name to find it',
         'columns'   : [{
                       'col_name' : 'Recipe name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Group',
                       'col_id'   : RecipeListModel.COL_GROUP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Brought in by (+others)',
                       'col_id'   : RecipeListModel.COL_BINB,
                       'col_style': 'binb',
                       'col_min'  : 100,
                       'col_max'  : 500,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }, {
         'name'      : 'All recipes',
         'tooltip'   : 'All recipes in your configured layers',
         'filter'    : { RecipeListModel.COL_TYPE : ['recipe'] },
         'search'    : 'Search recipes by name',
         'searchtip' : 'Enter a recipe name to find it',
         'columns'   : [{
                       'col_name' : 'Recipe name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Group',
                       'col_id'   : RecipeListModel.COL_GROUP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'License',
                       'col_id'   : RecipeListModel.COL_LIC,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }, {
         'name'      : 'Package Groups',
         'tooltip'   : 'All package groups in your configured layers',
         'filter'    : { RecipeListModel.COL_TYPE : ['packagegroup'] },
         'search'    : 'Search package groups by name',
         'searchtip' : 'Enter a package group name to find it',
         'columns'   : [{
                       'col_name' : 'Package group name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }
    ]
    
    (INCLUDED,
     ALL,
     TASKS) = range(3)

    def __init__(self, builder = None):
        super(RecipeSelectionPage, self).__init__(builder, "Step 1 of 2: Edit recipes")

        # set invisible members
        self.recipe_model = self.builder.recipe_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.eventbox = self.add_onto_top_bar(None, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = [] # we need modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tabs in order
        for page in self.pages:
            columns = page['columns']
            name = page['name']
            tab = HobViewTable(columns, name)
            search_names.append(page['search'])
            search_tips.append(page['searchtip'])
            filter = page['filter']
            sort_model = self.recipe_model.tree_model(filter, initial=True)
            tab.set_model(sort_model)
            tab.connect("toggled", self.table_toggled_cb, name)
            tab.connect("button-release-event", self.button_click_cb)
            tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include, filter)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)

        # add all into the window
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_end(button_box, expand=False, fill=False)

        self.build_packages_button = HobButton('Build packages')
        #self.build_packages_button.set_size_request(205, 49)
        self.build_packages_button.set_tooltip_text("Build selected recipes into packages")
        self.build_packages_button.set_flags(gtk.CAN_DEFAULT)
        self.build_packages_button.grab_default()
        self.build_packages_button.connect("clicked", self.build_packages_clicked_cb)
        button_box.pack_end(self.build_packages_button, expand=False, fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = self.ins.get_current_page()
        filter = self.pages[current_tab]['filter']
        filter[RecipeListModel.COL_NAME] = text
        self.tables[current_tab].set_model(self.recipe_model.tree_model(filter, search_data=text))
        if self.recipe_model.filtered_nb == 0:
            if not self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).add_no_result_bar(entry)
                self.ins.get_nth_page(current_tab).top_bar.set_no_show_all(True)
            self.ins.get_nth_page(current_tab).top_bar.show()
            self.ins.get_nth_page(current_tab).scroll.hide()
        else:
            if self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).top_bar.hide()
            self.ins.get_nth_page(current_tab).scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title() != 'Included': # else activation is likely a removal
            properties = {'summary': '', 'name': '', 'version': '', 'revision': '', 'binb': '', 'group': '', 'license': '', 'homepage': '', 'bugtracker': '', 'description': ''}
            properties['summary'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_SUMMARY)
            properties['name'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_NAME)
            properties['version'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_VERSION)
            properties['revision'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_REVISION)
            properties['binb'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_BINB)
            properties['group'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_GROUP)
            properties['license'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_LIC)
            properties['homepage'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_HOMEPAGE)
            properties['bugtracker'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_BUGTRACKER)
            properties['description'] = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_DESC)
            self.builder.show_recipe_property_dialog(properties)

    def build_packages_clicked_cb(self, button):
        self.refresh_tables()
        self.builder.build_packages()

    def refresh_tables(self):
        self.ins.reset_entry(self.ins.search, 0)
        for tab in self.tables:
            index = self.tables.index(tab)
            filter = self.pages[index]['filter']
            tab.set_model(self.recipe_model.tree_model(filter, search_data="", initial=True))

    def back_button_clicked_cb(self, button):
        self.builder.recipe_model.set_selected_image(self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_combo(self.builder.recipe_model, self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_desc()
        self.builder.show_configuration()
        self.refresh_tables()

    def refresh_selection(self):
        self.builder.configuration.selected_image = self.recipe_model.get_selected_image()
        _, self.builder.configuration.selected_recipes = self.recipe_model.get_selected_recipes()

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.recipe_model.path_included(path):
            self.recipe_model.include_item(item_path=path, binb="User Selected", image_contents=False)
        else:
            self.pre_fadeout_checkout_include(view_tree, pagename)
            self.recipe_model.exclude_item(item_path=path)
            self.render_fadeout(view_tree, cell)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

        view_model = view_tree.get_model()
        vpath = self.recipe_model.convert_path_to_vpath(view_model, path)
        view_tree.set_cursor(vpath)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a recipe
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.recipe_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree, pagename):
        #after the fadeout the table will be sorted as before
        self.sort_column_id = self.recipe_model.sort_column_id
        self.sort_order = self.recipe_model.sort_order

        #resync the included items to a backup fade include column
        it = self.recipe_model.get_iter_first()
        while it:
            active = self.recipe_model.get_value(it, self.recipe_model.COL_INC)
            self.recipe_model.set(it, self.recipe_model.COL_FADE_INC, active)
            it = self.recipe_model.iter_next(it)
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = { RecipeListModel.COL_FADE_INC:[True] }
        if pagename == "Included recipes":
            filter[RecipeListModel.COL_TYPE] = ['recipe', 'packagegroup']
        elif pagename == "All recipes":
            filter[RecipeListModel.COL_TYPE] = ['recipe']
        else:
            filter[RecipeListModel.COL_TYPE] = ['packagegroup']

        new_model = self.recipe_model.tree_model(filter, excluded_items_ahead=True)
        tree.set_model(new_model)

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        model = tree.get_model()
        it = model.get_iter_first()
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, RecipeListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, RecipeListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            it = model.iter_next(it)

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree, filter):
        self.recipe_model.sort_column_id = self.sort_column_id
        self.recipe_model.sort_order = self.sort_order
        tree.set_model(self.recipe_model.tree_model(filter))

    def set_recipe_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
    def gen_mirror_entry_widget(self, content, index, match_content=""):
        hbox = gtk.HBox(False)
        entry = gtk.Entry()
        content = content[:-2]
        entry.set_text(content)
        entry.set_size_request(350, 30)

        entry_match = gtk.Entry()
        entry_match.set_text(match_content)
        entry_match.set_size_request(100, 30)

        table = gtk.Table(2, 5, False)
        table.set_row_spacings(12)
        table.set_col_spacings(6)
        hbox.pack_start(table, expand=True, fill=True)

        label_configuration = gtk.Label("Configuration")
        label_configuration.set_alignment(0.0, 0.5)
        label_mirror_url = gtk.Label("Mirror URL")
        label_mirror_url.set_alignment(0.0, 0.5)
        label_match = gtk.Label("Match")
        label_match.set_alignment(0.0, 0.5)
        label_replace_with = gtk.Label("Replace with")
        label_replace_with.set_alignment(0.0, 0.5)

        combo = gtk.combo_box_new_text()
        combo.append_text("Standard")
        combo.append_text("Custom")
        if match_content == "":
            combo.set_active(0)
        else:
            combo.set_active(1)
        combo.connect("changed", self.on_combo_changed, index)
        combo.set_size_request(100, 30)

        delete_button = HobAltButton("Delete")
        delete_button.connect("clicked", self.delete_cb, index, entry)
        if content == "" and index == 0 and len(self.sstatemirrors_list) == 1:
            delete_button.set_sensitive(False)
        delete_button.set_size_request(100, 30)

        entry_match.connect("changed", self.insert_entry_match_cb, index)
        entry.connect("changed", self.insert_entry_cb, index, delete_button)

        if match_content == "":
            table.attach(label_configuration,
                         1,
                         2,
                         0,
                         1,
                         xoptions=gtk.SHRINK | gtk.FILL)
            table.attach(label_mirror_url,
                         2,
                         3,
                         0,
                         1,
                         xoptions=gtk.SHRINK | gtk.FILL)
            table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry, 2, 3, 1, 2, xoptions=gtk.SHRINK)
            table.attach(delete_button, 3, 4, 1, 2, xoptions=gtk.SHRINK)
        else:
            table.attach(label_configuration,
                         1,
                         2,
                         0,
                         1,
                         xoptions=gtk.SHRINK | gtk.FILL)
            table.attach(label_match,
                         2,
                         3,
                         0,
                         1,
                         xoptions=gtk.SHRINK | gtk.FILL)
            table.attach(label_replace_with,
                         3,
                         4,
                         0,
                         1,
                         xoptions=gtk.SHRINK | gtk.FILL)
            table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry_match, 2, 3, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry, 3, 4, 1, 2, xoptions=gtk.SHRINK)
            table.attach(delete_button, 4, 5, 1, 2, xoptions=gtk.SHRINK)

        hbox.show_all()
        return hbox
Exemple #33
0
class PackageSelectionPage(HobPage):

    pages = [{
        'name':
        'Included packages',
        'tooltip':
        'The packages currently included for your image',
        'filter': {
            PackageListModel.COL_INC: [True]
        },
        'search':
        'Search packages by name',
        'searchtip':
        'Enter a package name to find it',
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Recipe',
            'col_id': PackageListModel.COL_RCP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 250,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by (+others)',
            'col_id': PackageListModel.COL_BINB,
            'col_style': 'binb',
            'col_min': 100,
            'col_max': 350,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'All packages',
        'tooltip':
        'All packages that have been built',
        'filter': {},
        'search':
        'Search packages by name',
        'searchtip':
        'Enter a package name to find it',
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 500,
            'expand': 'True'
        }, {
            'col_name': 'Recipe',
            'col_id': PackageListModel.COL_RCP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 250,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }]

    (INCLUDED, ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisible members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.label = gtk.Label(
            "Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need to modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tab
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            search_names.append(page['search'])
            search_tips.append(page['searchtip'])
            filter = page['filter']
            sort_model = self.package_model.tree_model(filter)
            tab.set_model(sort_model)
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            if page['name'] == "Included packages":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            if page['name'] == "All packages":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box,
                                       expand=False,
                                       fill=False)

        self.build_image_button = HobButton('Build image')
        #self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = self.ins.get_current_page()
        filter = self.pages[current_tab]['filter']
        filter[PackageListModel.COL_NAME] = text
        self.tables[current_tab].set_model(
            self.package_model.tree_model(filter, search_data=text))
        if self.package_model.filtered_nb == 0:
            if not self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).add_no_result_bar(entry)
            self.ins.get_nth_page(current_tab).top_bar.show()
            self.ins.get_nth_page(current_tab).scroll.hide()
        else:
            if self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).top_bar.hide()
            self.ins.get_nth_page(current_tab).scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title(
        ) != 'Included':  # else activation is likely a removal
            properties = {
                'binb': '',
                'name': '',
                'size': '',
                'recipe': '',
                'files_list': ''
            }
            properties['binb'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_BINB)
            properties['name'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_NAME)
            properties['size'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_SIZE)
            properties['recipe'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_RCP)
            properties['files_list'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_FLIST)

            self.builder.show_recipe_property_dialog(properties)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb,
                                    log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        self.builder.parsing_warnings = []
        self.builder.build_image()

    def back_button_clicked_cb(self, button):
        if self.builder.previous_step == self.builder.IMAGE_GENERATED:
            self.builder.restore_initial_selected_packages()
            self.refresh_selection()
            self.builder.show_image_details()
        else:
            self.builder.show_configuration()

    def refresh_selection(self):
        self.builder.configuration.selected_packages = self.package_model.get_selected_packages(
        )
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages(
        )
        selected_packages_num = len(
            self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(
            selected_packages_size)

        image_overhead_factor = self.builder.configuration.image_overhead_factor
        image_rootfs_size = self.builder.configuration.image_rootfs_size / 1024  # image_rootfs_size is KB
        image_extra_size = self.builder.configuration.image_extra_size / 1024  # image_extra_size is KB
        base_size = image_overhead_factor * selected_packages_size
        image_total_size = max(base_size, image_rootfs_size) + image_extra_size
        if "zypper" in self.builder.configuration.selected_packages:
            image_total_size += (51200 * 1024)
        image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_label(
            "Packages included: %s\nSelected packages size: %s\nTotal image size: %s"
            % (selected_packages_num, selected_packages_size_str,
               image_total_size_str))
        self.ins.show_indicator_icon("Included packages",
                                     selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path,
                                            binb="User Selected")
        else:
            if pagename == "Included packages":
                self.pre_fadeout_checkout_include(view_tree)
                self.package_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.package_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        self.package_model.resync_fadeout_column(
            self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {PackageListModel.COL_FADE_INC: [True]}
        new_model = self.package_model.tree_model(filter)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(
                it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model,
                                       model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model,
                               view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.package_model.tree_model(self.pages[0]['filter']))
        tree.expand_all()

    def set_packages_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
    def show_page(self, step):
        build_succeeded = (step == self.builder.IMAGE_GENERATED)
        image_addr = self.builder.parameters.image_addr
        image_names = self.builder.parameters.image_names
        if build_succeeded:
            machine = self.builder.configuration.curr_mach
            base_image = self.builder.recipe_model.get_selected_image()
            layers = self.builder.configuration.layers
            pkg_num = "%s" % len(self.builder.package_model.get_selected_packages())
        else:
            pkg_num = "N/A"

        # remove
        for button_id, button in self.button_ids.items():
            button.disconnect(button_id)
        self._remove_all_widget()

        # repack
        self.pack_start(self.details_top_buttons, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.build_result = None
        if build_succeeded:
            # building is the previous step
            icon = gtk.Image()
            pixmap_path = hic.ICON_INDI_CONFIRM_FILE
            color = HobColors.RUNNING
            pix_buffer = gtk.gdk.pixbuf_new_from_file(pixmap_path)
            icon.set_from_pixbuf(pix_buffer)
            varlist = [""]
            vallist = ["Your image is ready"]
            self.build_result = self.DetailBox(varlist=varlist, vallist=vallist, icon=icon, color=color)
            self.box_group_area.pack_start(self.build_result, expand=False, fill=False)

        # create the buttons at the bottom first because the buttons are used in apply_button_per_image()
        if build_succeeded:
            self.buttonlist = ["Build new image", "Save as template", "Run image", "Deploy image"]
        else: # get to this page from "My images"
            self.buttonlist = ["Build new image", "Run image", "Deploy image"]

        # Name
        varlist = [""]
        vallist = ["Listed generated image and package files."]
        t = ''
        self.image_store.clear()
        default_toggled = False
        default_image_size = 0
        i = 0
        for image_name in image_names:
            image_size = HobPage._size_to_string(os.stat(os.path.join(image_addr, image_name)).st_size)
            if not default_toggled:
                default_toggled = (self.test_type_runnable(image_name) and self.test_mach_runnable(image_name)) \
                    or self.test_deployable(image_name)
                if i == (len(image_names) - 1):
                    default_toggled = True
                self.image_store.set(self.image_store.append(), 0, image_name, 1, image_size, 2, default_toggled)
                if default_toggled:
                    default_image_size = image_size
                    self.create_bottom_buttons(self.buttonlist, image_name)
                    if 'qemu' in image_name:
                        t = ' (Selected QEMU items to be as runnable image)'
                    else:
                        t = ' (Selected Targeted item to be deploy)'
            else:
                self.image_store.set(self.image_store.append(), 0, image_name, 1, image_size, 2, False)
            i = i + 1

        if build_succeeded:
            varlist = ["Name: ", "Directory: ", ". "]
            vallist = []
            vallist.append(image_name.split('.')[0])
            vallist.append(image_addr)
            vallist.append(t)
            image_table = None
        else:
            image_table = HobViewTable(self.__columns__)
            image_table.set_model(self.image_store)
            image_table.connect("row-activated", self.row_activated_cb)
            if default_image_size and ('qemu' in image_name):
                t = '\n(Selected QEMU items to be as runnable image, so you need to select prompted kernel to run)'
            vallist[0] += t

        view_files_button = HobAltButton("View files")
        view_files_button.connect("clicked", self.view_files_clicked_cb, image_addr)
        view_files_button.set_tooltip_text("Open the directory containing the image files")
        self.image_detail = self.DetailBox(widget=image_table, varlist=varlist, vallist=vallist, button=view_files_button)
        self.box_group_area.pack_start(self.image_detail, expand=True, fill=True)

        # Machine, Base image and Layers
        layer_num_limit = 15
        varlist = ["Machine: ", "Base image: ", "Layers: "]
        vallist = []
        self.setting_detail = None
        if build_succeeded:
            vallist.append(machine)
            vallist.append(base_image)
            i = 0
            for layer in layers:
                varlist.append(" - ")
                if i > layer_num_limit:
                    break
                i += 1
            vallist.append("")
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                elif i == layer_num_limit:
                    vallist.append("and more...")
                else:
                    vallist.append(layer)
                i += 1

            edit_config_button = HobAltButton("Edit configuration")
            edit_config_button.set_tooltip_text("Edit machine, base image and recipes")
            edit_config_button.connect("clicked", self.edit_config_button_clicked_cb)
            self.setting_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_config_button)
            self.box_group_area.pack_start(self.setting_detail, expand=True, fill=True)

        # Packages included, and Total image size
        varlist = ["Packages included: ", "Total image size: "]
        vallist = []
        vallist.append(pkg_num)
        vallist.append(default_image_size)
        if build_succeeded:
            edit_packages_button = HobAltButton("Edit packages")
            edit_packages_button.set_tooltip_text("Edit the packages included in your image")
            edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)
        else: # get to this page from "My images"
            edit_packages_button = None
        self.package_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_packages_button)
        self.box_group_area.pack_start(self.package_detail, expand=False, fill=False)

        # pack the buttons at the bottom, at this time they are already created.
        self.box_group_area.pack_end(self.details_bottom_buttons, expand=False, fill=False)

        self.show_all()
Exemple #35
0
class BuildDetailsPage (HobPage):

    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0,)
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n") # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status, expand=False, fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow ()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config, "Build configuration")

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow ()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, "Issues")

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow ()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, "Log")

        self.builder.handler.build.model.connect_after("row-changed", self.scroll_to_present_row, self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('<< Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n") # to ensure layout is correct
        self.endpath = (0,)

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='medium'>Check the \"Issues\" information for more details</span>")
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked', self.failure_primary_action_button_clicked_cb, primary_action)
        build_fail_tab.attach(action_button, 4, 13, 9, 12)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.failure_open_log_button_clicked_cb, log_file)
            build_fail_tab.attach(open_log_button, 14, 23, 9, 12)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text("Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked', self.failure_activate_file_bug_link_cb)
        build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9, 12)

        return build_fail_top

    def show_fail_page(self, title, action_names):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(action_names, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar, expand=False, fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[0]: # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value == v_adj.upper - v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages()
        elif "Edit image configuration" in action:
            self.builder.show_configuration()

    def failure_open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            os.system("xdg-open /%s" % log_file)

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
    def show_page(self, step):
        self.build_succeeded = (step == self.builder.IMAGE_GENERATED)
        image_addr = self.builder.parameters.image_addr
        image_names = self.builder.parameters.image_names
        if self.build_succeeded:
            machine = self.builder.configuration.curr_mach
            base_image = self.builder.recipe_model.get_selected_image()
            layers = self.builder.configuration.layers
            pkg_num = "%s" % len(self.builder.package_model.get_selected_packages())
            log_file = self.builder.current_logfile
        else:
            pkg_num = "N/A"
            log_file = None

        # remove
        for button_id, button in self.button_ids.items():
            button.disconnect(button_id)
        self._remove_all_widget()

        # repack
        self.pack_start(self.details_top_buttons, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.build_result = None
        if self.image_saved or (self.build_succeeded and self.builder.current_step == self.builder.IMAGE_GENERATING):
            # building is the previous step
            icon = gtk.Image()
            pixmap_path = hic.ICON_INDI_CONFIRM_FILE
            color = HobColors.RUNNING
            pix_buffer = gtk.gdk.pixbuf_new_from_file(pixmap_path)
            icon.set_from_pixbuf(pix_buffer)
            varlist = [""]
            if self.image_saved:
                vallist = ["Your image recipe has been saved"]
            else:
                vallist = ["Your image is ready"]
            self.build_result = self.BuildDetailBox(varlist=varlist, vallist=vallist, icon=icon, color=color)
            self.box_group_area.pack_start(self.build_result, expand=False, fill=False)

        self.buttonlist = ["Build new image", "Save image recipe", "Run image", "Deploy image"]

        # Name
        self.image_store = []
        self.toggled_image = ""
        default_image_size = 0
        self.num_toggled = 0
        i = 0
        for image_name in image_names:
            image_size = HobPage._size_to_string(os.stat(os.path.join(image_addr, image_name)).st_size)

            image_attr = ("run" if (self.test_type_runnable(image_name) and self.test_mach_runnable(image_name)) else \
                          ("deploy" if self.test_deployable(image_name) else ""))
            is_toggled = (image_attr != "")

            if not self.toggled_image:
                if i == (len(image_names) - 1):
                    is_toggled = True
                if is_toggled:
                    default_image_size = image_size
                    self.toggled_image = image_name

            split_stuff = image_name.split('.')
            if "rootfs" in split_stuff:
                image_type = image_name[(len(split_stuff[0]) + len(".rootfs") + 1):]
            else:
                image_type = image_name[(len(split_stuff[0]) + 1):]

            self.image_store.append({'name': image_name,
                                    'type': image_type,
                                    'size': image_size,
                                    'is_toggled': is_toggled,
                                    'action_attr': image_attr,})

            i = i + 1
            self.num_toggled += is_toggled

        is_runnable = self.create_bottom_buttons(self.buttonlist, self.toggled_image)

        # Generated image files info
        varlist = ["Name: ", "Files created: ", "Directory: "]
        vallist = []

        vallist.append(image_name.split('.')[0])
        vallist.append(',  '.join(fileitem['type'] for fileitem in self.image_store))
        vallist.append(image_addr)

        view_files_button = HobAltButton("View files")
        view_files_button.connect("clicked", self.view_files_clicked_cb, image_addr)
        view_files_button.set_tooltip_text("Open the directory containing the image files")
        open_log_button = None
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
        self.image_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=view_files_button, button2=open_log_button)
        self.box_group_area.pack_start(self.image_detail, expand=False, fill=True)

        # The default kernel box for the qemu images
        self.sel_kernel = ""
        self.kernel_detail = None
        if 'qemu' in image_name:
            self.sel_kernel = self.get_kernel_file_name()

        #    varlist = ["Kernel: "]
        #    vallist = []
        #    vallist.append(self.sel_kernel)

        #    change_kernel_button = HobAltButton("Change")
        #    change_kernel_button.connect("clicked", self.change_kernel_cb)
        #    change_kernel_button.set_tooltip_text("Change qemu kernel file")
        #    self.kernel_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=change_kernel_button)
        #    self.box_group_area.pack_start(self.kernel_detail, expand=True, fill=True)

        # Machine, Image recipe and Layers
        layer_num_limit = 15
        varlist = ["Machine: ", "Image recipe: ", "Layers: "]
        vallist = []
        self.setting_detail = None
        if self.build_succeeded:
            vallist.append(machine)
            if self.builder.recipe_model.is_custom_image():
                if self.builder.configuration.initial_selected_image == self.builder.recipe_model.__custom_image__:
                    base_image ="New image recipe"
                else:
                    base_image = self.builder.configuration.initial_selected_image + " (edited)"
            vallist.append(base_image)
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                varlist.append(" - ")
                i += 1
            vallist.append("")
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                elif i == layer_num_limit:
                    vallist.append("and more...")
                else:
                    vallist.append(layer)
                i += 1

            edit_config_button = HobAltButton("Edit configuration")
            edit_config_button.set_tooltip_text("Edit machine and image recipe")
            edit_config_button.connect("clicked", self.edit_config_button_clicked_cb)
            self.setting_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_config_button)
            self.box_group_area.pack_start(self.setting_detail, expand=True, fill=True)

        # Packages included, and Total image size
        varlist = ["Packages included: ", "Total image size: "]
        vallist = []
        vallist.append(pkg_num)
        vallist.append(default_image_size)
        self.builder.configuration.image_size = default_image_size
        self.builder.configuration.image_packages = self.builder.configuration.selected_packages
        if self.build_succeeded:
            edit_packages_button = HobAltButton("Edit packages")
            edit_packages_button.set_tooltip_text("Edit the packages included in your image")
            edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)
        else: # get to this page from "My images"
            edit_packages_button = None
        self.package_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_packages_button)
        self.box_group_area.pack_start(self.package_detail, expand=True, fill=True)

        # pack the buttons at the bottom, at this time they are already created.
        if self.build_succeeded:
            self.box_group_area.pack_end(self.details_bottom_buttons, expand=False, fill=False)
        else: # for "My images" page
            self.details_separator = gtk.HSeparator()
            self.box_group_area.pack_start(self.details_separator, expand=False, fill=False)
            self.box_group_area.pack_start(self.details_bottom_buttons, expand=False, fill=False)

        self.show_all()
        if self.kernel_detail and (not is_runnable):
            self.kernel_detail.hide()
        self.image_saved = False
class RecipeSelectionPage(HobPage):
    pages = [{
        'name':
        'Included recipes',
        'tooltip':
        'The recipes currently included for your image',
        'filter': {
            RecipeListModel.COL_INC: [True],
            RecipeListModel.COL_TYPE: ['recipe', 'packagegroup']
        },
        'search':
        'Search recipes by name',
        'searchtip':
        'Enter a recipe name to find it',
        'columns': [{
            'col_name': 'Recipe name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Group',
            'col_id': RecipeListModel.COL_GROUP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by (+others)',
            'col_id': RecipeListModel.COL_BINB,
            'col_style': 'binb',
            'col_min': 100,
            'col_max': 500,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'All recipes',
        'tooltip':
        'All recipes in your configured layers',
        'filter': {
            RecipeListModel.COL_TYPE: ['recipe']
        },
        'search':
        'Search recipes by name',
        'searchtip':
        'Enter a recipe name to find it',
        'columns': [{
            'col_name': 'Recipe name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Group',
            'col_id': RecipeListModel.COL_GROUP,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'License',
            'col_id': RecipeListModel.COL_LIC,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'Package Groups',
        'tooltip':
        'All package groups in your configured layers',
        'filter': {
            RecipeListModel.COL_TYPE: ['packagegroup']
        },
        'search':
        'Search package groups by name',
        'searchtip':
        'Enter a package group name to find it',
        'columns': [{
            'col_name': 'Package group name',
            'col_id': RecipeListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': RecipeListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }]

    (INCLUDED, ALL, TASKS) = range(3)

    def __init__(self, builder=None):
        super(RecipeSelectionPage, self).__init__(builder,
                                                  "Step 1 of 2: Edit recipes")

        # set invisible members
        self.recipe_model = self.builder.recipe_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.eventbox = self.add_onto_top_bar(None, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tabs in order
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            search_names.append(page['search'])
            search_tips.append(page['searchtip'])
            filter = page['filter']
            sort_model = self.recipe_model.tree_model(filter)
            tab.set_model(sort_model)
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            if page['name'] == "Included recipes":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            if page['name'] == "Package Groups":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            if page['name'] == "All recipes":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped", self.button_click_cb)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)

        # add all into the window
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_end(button_box, expand=False, fill=False)

        self.build_packages_button = HobButton('Build packages')
        #self.build_packages_button.set_size_request(205, 49)
        self.build_packages_button.set_tooltip_text(
            "Build selected recipes into packages")
        self.build_packages_button.set_flags(gtk.CAN_DEFAULT)
        self.build_packages_button.grab_default()
        self.build_packages_button.connect("clicked",
                                           self.build_packages_clicked_cb)
        button_box.pack_end(self.build_packages_button,
                            expand=False,
                            fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = self.ins.get_current_page()
        filter = self.pages[current_tab]['filter']
        filter[RecipeListModel.COL_NAME] = text
        self.tables[current_tab].set_model(
            self.recipe_model.tree_model(filter, search_data=text))
        if self.recipe_model.filtered_nb == 0:
            if not self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).add_no_result_bar(entry)
            self.ins.get_nth_page(current_tab).top_bar.show()
            self.ins.get_nth_page(current_tab).scroll.hide()
        else:
            if self.ins.get_nth_page(current_tab).top_bar:
                self.ins.get_nth_page(current_tab).top_bar.hide()
            self.ins.get_nth_page(current_tab).scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title(
        ) != 'Included':  # else activation is likely a removal
            properties = {
                'summary': '',
                'name': '',
                'version': '',
                'revision': '',
                'binb': '',
                'group': '',
                'license': '',
                'homepage': '',
                'bugtracker': '',
                'description': ''
            }
            properties['summary'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_SUMMARY)
            properties['name'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_NAME)
            properties['version'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_VERSION)
            properties['revision'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_REVISION)
            properties['binb'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_BINB)
            properties['group'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_GROUP)
            properties['license'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_LIC)
            properties['homepage'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_HOMEPAGE)
            properties['bugtracker'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_BUGTRACKER)
            properties['description'] = tree_model.get_value(
                tree_model.get_iter(path), RecipeListModel.COL_DESC)
            self.builder.show_recipe_property_dialog(properties)

    def build_packages_clicked_cb(self, button):
        self.builder.build_packages()

    def back_button_clicked_cb(self, button):
        self.builder.recipe_model.set_selected_image(
            self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_combo(
            self.builder.recipe_model,
            self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_desc()
        self.builder.show_configuration()

    def refresh_selection(self):
        self.builder.configuration.selected_image = self.recipe_model.get_selected_image(
        )
        _, self.builder.configuration.selected_recipes = self.recipe_model.get_selected_recipes(
        )
        self.ins.show_indicator_icon(
            "Included recipes",
            len(self.builder.configuration.selected_recipes))

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.recipe_model.path_included(path):
            self.recipe_model.include_item(item_path=path,
                                           binb="User Selected",
                                           image_contents=False)
        else:
            if pagename == "Included recipes":
                self.pre_fadeout_checkout_include(view_tree)
                self.recipe_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.recipe_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a recipe
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.recipe_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        #resync the included items to a backup fade include column
        it = self.recipe_model.get_iter_first()
        while it:
            active = self.recipe_model.get_value(it, self.recipe_model.COL_INC)
            self.recipe_model.set(it, self.recipe_model.COL_FADE_INC, active)
            it = self.recipe_model.iter_next(it)
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {
            RecipeListModel.COL_FADE_INC: [True],
            RecipeListModel.COL_TYPE: ['recipe', 'packagegroup']
        }
        new_model = self.recipe_model.tree_model(filter,
                                                 excluded_items_ahead=True)
        tree.set_model(new_model)

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        model = tree.get_model()
        it = model.get_iter_first()
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it,
                                                  RecipeListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, RecipeListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            it = model.iter_next(it)

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.recipe_model.tree_model(self.pages[0]['filter']))

    def set_recipe_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content, tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=12)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content, tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False)

        sub_vbox = gtk.VBox(False)
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        scroll.add_with_viewport(sub_vbox)
        scroll.connect('size-allocate', self.scroll_changed)
        advanced_vbox.pack_start(scroll, gtk.TRUE, gtk.TRUE, 0)
        searched_string = "file://"

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = [ 0, "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                while sstatemirrors.find(searched_string) != -1:
                    if sstatemirrors.find(searched_string,1) != -1:
                        sstatemirror = sstatemirrors[:sstatemirrors.find(searched_string,1)]
                        sstatemirrors = sstatemirrors[sstatemirrors.find(searched_string,1):]
                    else:
                        sstatemirror = sstatemirrors
                        sstatemirrors = sstatemirrors[1:]

                    sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()]
                    if sstatemirror_fields[0] == "file://(.*)":
                        sm_list = [ 0, sstatemirror_fields[1], "file://(.*)"]
                    else:
                        sm_list = [ 1, sstatemirror_fields[1], sstatemirror_fields[0]]
                    self.sstatemirrors_list.append(sm_list)

        index = 0
        for mirror in self.sstatemirrors_list:
            if mirror[0] == 0:
                sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index)
            else:
                sstatemirror_widget = self.gen_mirror_entry_widget(mirror[1], index, mirror[2])
            sub_vbox.pack_start(sstatemirror_widget, expand=False, fill=False, padding=9)
            index += 1

        table = gtk.Table(1, 1, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add another mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(150,30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=9)

        return advanced_vbox
    def gen_mirror_entry_widget(self, content, index, match_content=""):
        hbox = gtk.HBox(False)
        entry = gtk.Entry()
        content = content[:-2]
        entry.set_text(content)
        entry.set_size_request(350,30)

        entry_match = gtk.Entry()
        entry_match.set_text(match_content)
        entry_match.set_size_request(100,30)

        table = gtk.Table(2, 5, False)
        table.set_row_spacings(12)
        table.set_col_spacings(6)
        hbox.pack_start(table, expand=True, fill=True)

        label_configuration = gtk.Label("Configuration")
        label_configuration.set_alignment(0.0,0.5)
        label_mirror_url = gtk.Label("Mirror URL")
        label_mirror_url.set_alignment(0.0,0.5)
        label_match = gtk.Label("Match")
        label_match.set_alignment(0.0,0.5)
        label_replace_with = gtk.Label("Replace with")
        label_replace_with.set_alignment(0.0,0.5)

        combo = gtk.combo_box_new_text()
        combo.append_text("Standard")
        combo.append_text("Custom")
        if match_content == "":
            combo.set_active(0)
        else:
            combo.set_active(1)
        combo.connect("changed", self.on_combo_changed, index)
        combo.set_size_request(100,30)

        delete_button = HobAltButton("Delete")
        delete_button.connect("clicked", self.delete_cb, index, entry)
        if content == "" and index == 0  and len(self.sstatemirrors_list) == 1:
            delete_button.set_sensitive(False)
        delete_button.set_size_request(100, 30)

        entry_match.connect("changed", self.insert_entry_match_cb, index)
        entry.connect("changed", self.insert_entry_cb, index, delete_button)

        if match_content == "":
            table.attach(label_configuration, 1, 2, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
            table.attach(label_mirror_url, 2, 3, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
            table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry, 2, 3, 1, 2, xoptions=gtk.SHRINK)
            table.attach(delete_button, 3, 4, 1, 2, xoptions=gtk.SHRINK)
        else:
            table.attach(label_configuration, 1, 2, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
            table.attach(label_match, 2, 3, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
            table.attach(label_replace_with, 3, 4, 0, 1, xoptions=gtk.SHRINK|gtk.FILL)
            table.attach(combo, 1, 2, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry_match, 2, 3, 1, 2, xoptions=gtk.SHRINK)
            table.attach(entry, 3, 4, 1, 2, xoptions=gtk.SHRINK)
            table.attach(delete_button, 4, 5, 1, 2, xoptions=gtk.SHRINK)

        hbox.show_all()
        return hbox
Exemple #40
0
    def show_page(self, step):
        self.build_succeeded = (step == self.builder.IMAGE_GENERATED)
        image_addr = self.builder.parameters.image_addr
        image_names = self.builder.parameters.image_names
        if self.build_succeeded:
            machine = self.builder.configuration.curr_mach
            base_image = self.builder.recipe_model.get_selected_image()
            layers = self.builder.configuration.layers
            pkg_num = "%s" % len(
                self.builder.package_model.get_selected_packages())
            log_file = self.builder.current_logfile
        else:
            pkg_num = "N/A"
            log_file = None

        # remove
        for button_id, button in self.button_ids.items():
            button.disconnect(button_id)
        self._remove_all_widget()

        # repack
        self.pack_start(self.details_top_buttons, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.build_result = None
        if self.image_saved or (self.build_succeeded
                                and self.builder.current_step
                                == self.builder.IMAGE_GENERATING):
            # building is the previous step
            icon = gtk.Image()
            pixmap_path = hic.ICON_INDI_CONFIRM_FILE
            color = HobColors.RUNNING
            pix_buffer = gtk.gdk.pixbuf_new_from_file(pixmap_path)
            icon.set_from_pixbuf(pix_buffer)
            varlist = [""]
            if self.image_saved:
                vallist = ["Your image recipe has been saved"]
            else:
                vallist = ["Your image is ready"]
            self.build_result = self.BuildDetailBox(varlist=varlist,
                                                    vallist=vallist,
                                                    icon=icon,
                                                    color=color)
            self.box_group_area.pack_start(self.build_result,
                                           expand=False,
                                           fill=False)

        self.buttonlist = [
            "Build new image", "Save image recipe", "Run image", "Deploy image"
        ]

        # Name
        self.image_store = []
        self.toggled_image = ""
        default_image_size = 0
        self.num_toggled = 0
        i = 0
        for image_name in image_names:
            image_size = HobPage._size_to_string(
                os.stat(os.path.join(image_addr, image_name)).st_size)

            image_attr = ("run" if (self.test_type_runnable(image_name) and self.test_mach_runnable(image_name)) else \
                          ("deploy" if self.test_deployable(image_name) else ""))
            is_toggled = (image_attr != "")

            if not self.toggled_image:
                if i == (len(image_names) - 1):
                    is_toggled = True
                if is_toggled:
                    default_image_size = image_size
                    self.toggled_image = image_name

            split_stuff = image_name.split('.')
            if "rootfs" in split_stuff:
                image_type = image_name[(len(split_stuff[0]) + len(".rootfs") +
                                         1):]
            else:
                image_type = image_name[(len(split_stuff[0]) + 1):]

            self.image_store.append({
                'name': image_name,
                'type': image_type,
                'size': image_size,
                'is_toggled': is_toggled,
                'action_attr': image_attr,
            })

            i = i + 1
            self.num_toggled += is_toggled

        is_runnable = self.create_bottom_buttons(self.buttonlist,
                                                 self.toggled_image)

        # Generated image files info
        varlist = ["Name: ", "Files created: ", "Directory: "]
        vallist = []

        vallist.append(image_name.split('.')[0])
        vallist.append(',  '.join(fileitem['type']
                                  for fileitem in self.image_store))
        vallist.append(image_addr)

        view_files_button = HobAltButton("View files")
        view_files_button.connect("clicked", self.view_files_clicked_cb,
                                  image_addr)
        view_files_button.set_tooltip_text(
            "Open the directory containing the image files")
        open_log_button = None
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb,
                                    log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
        self.image_detail = self.DetailBox(varlist=varlist,
                                           vallist=vallist,
                                           button=view_files_button,
                                           button2=open_log_button)
        self.box_group_area.pack_start(self.image_detail,
                                       expand=False,
                                       fill=True)

        # The default kernel box for the qemu images
        self.sel_kernel = ""
        self.kernel_detail = None
        if 'qemu' in image_name:
            self.sel_kernel = self.get_kernel_file_name()

        #    varlist = ["Kernel: "]
        #    vallist = []
        #    vallist.append(self.sel_kernel)

        #    change_kernel_button = HobAltButton("Change")
        #    change_kernel_button.connect("clicked", self.change_kernel_cb)
        #    change_kernel_button.set_tooltip_text("Change qemu kernel file")
        #    self.kernel_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=change_kernel_button)
        #    self.box_group_area.pack_start(self.kernel_detail, expand=True, fill=True)

        # Machine, Image recipe and Layers
        layer_num_limit = 15
        varlist = ["Machine: ", "Image recipe: ", "Layers: "]
        vallist = []
        self.setting_detail = None
        if self.build_succeeded:
            vallist.append(machine)
            if self.builder.recipe_model.is_custom_image():
                if self.builder.configuration.initial_selected_image == self.builder.recipe_model.__custom_image__:
                    base_image = "New image recipe"
                else:
                    base_image = self.builder.configuration.initial_selected_image + " (edited)"
            vallist.append(base_image)
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                varlist.append(" - ")
                i += 1
            vallist.append("")
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                elif i == layer_num_limit:
                    vallist.append("and more...")
                else:
                    vallist.append(layer)
                i += 1

            edit_config_button = HobAltButton("Edit configuration")
            edit_config_button.set_tooltip_text(
                "Edit machine and image recipe")
            edit_config_button.connect("clicked",
                                       self.edit_config_button_clicked_cb)
            self.setting_detail = self.DetailBox(varlist=varlist,
                                                 vallist=vallist,
                                                 button=edit_config_button)
            self.box_group_area.pack_start(self.setting_detail,
                                           expand=True,
                                           fill=True)

        # Packages included, and Total image size
        varlist = ["Packages included: ", "Total image size: "]
        vallist = []
        vallist.append(pkg_num)
        vallist.append(default_image_size)
        self.builder.configuration.image_size = default_image_size
        self.builder.configuration.image_packages = self.builder.configuration.selected_packages
        if self.build_succeeded:
            edit_packages_button = HobAltButton("Edit packages")
            edit_packages_button.set_tooltip_text(
                "Edit the packages included in your image")
            edit_packages_button.connect("clicked",
                                         self.edit_packages_button_clicked_cb)
        else:  # get to this page from "My images"
            edit_packages_button = None
        self.package_detail = self.DetailBox(varlist=varlist,
                                             vallist=vallist,
                                             button=edit_packages_button)
        self.box_group_area.pack_start(self.package_detail,
                                       expand=True,
                                       fill=True)

        # pack the buttons at the bottom, at this time they are already created.
        if self.build_succeeded:
            self.box_group_area.pack_end(self.details_bottom_buttons,
                                         expand=False,
                                         fill=False)
        else:  # for "My images" page
            self.details_separator = gtk.HSeparator()
            self.box_group_area.pack_start(self.details_separator,
                                           expand=False,
                                           fill=False)
            self.box_group_area.pack_start(self.details_bottom_buttons,
                                           expand=False,
                                           fill=False)

        self.show_all()
        if self.kernel_detail and (not is_runnable):
            self.kernel_detail.hide()
        self.image_saved = False
class ImageConfigurationPage(HobPage):

    __dummy_machine__ = "--select a machine--"
    __dummy_image__ = "--select an image recipe--"
    __custom_image__ = "Select from my image recipes"

    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder,
                                                     "Image configuration")

        self.image_combo_id = None
        # we use machine_combo_changed_by_manual to identify the machine is changed by code
        # or by manual. If by manual, all user's recipe selection and package selection are
        # cleared.
        self.machine_combo_changed_by_manual = True
        self.stopping = False
        self.warning_shift = 0
        self.custom_image_selected = None
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        my_images_button = self.append_toolbar_button(
            self.toolbar, "Images", hic.ICON_IMAGES_DISPLAY_FILE,
            hic.ICON_IMAGES_HOVER_FILE, "Open previously built images",
            self.my_images_button_clicked_cb)
        settings_button = self.append_toolbar_button(
            self.toolbar, "Settings", hic.ICON_SETTINGS_DISPLAY_FILE,
            hic.ICON_SETTINGS_HOVER_FILE, "View additional build settings",
            self.settings_button_clicked_cb)

        self.config_top_button = self.add_onto_top_bar(self.toolbar)

        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button=False):
        self._remove_all_widget()
        self.pack_start(self.config_top_button, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button,
                                         expand=False,
                                         fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def show_machine(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=False)
        self.show_all()

    def update_progress_bar(self, title, fraction, status=None):
        if self.stopping == False:
            self.progress_bar.update(fraction)
            self.progress_bar.set_text(title)
            self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=True)
        self.set_config_machine_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()
        if self.builder.recipe_model.get_selected_image(
        ) == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

    def add_warnings_bar(self):
        #create the warnings bar shown when recipes parsing generates warnings
        color = HobColors.KHAKI
        warnings_bar = gtk.EventBox()
        warnings_bar.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        warnings_bar.set_flags(gtk.CAN_DEFAULT)
        warnings_bar.grab_default()

        build_stop_tab = gtk.Table(10, 20, True)
        warnings_bar.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ALERT_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 0, 2, 0, 10)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        warnings_nb = len(self.builder.parsing_warnings)
        if warnings_nb == 1:
            label.set_markup(
                "<span size='x-large'><b>1 recipe parsing warning</b></span>")
        else:
            label.set_markup(
                "<span size='x-large'><b>%s recipe parsing warnings</b></span>"
                % warnings_nb)
        build_stop_tab.attach(label, 2, 12, 0, 10)

        view_warnings_button = HobButton("View warnings")
        view_warnings_button.connect('clicked',
                                     self.view_warnings_button_clicked_cb)
        build_stop_tab.attach(view_warnings_button, 15, 19, 1, 9)

        return warnings_bar

    def disable_warnings_bar(self):
        if self.builder.parsing_warnings:
            if hasattr(self, 'warnings_bar'):
                self.warnings_bar.hide_all()
            self.builder.parsing_warnings = []

    def create_config_machine(self):
        self.machine_title = gtk.Label()
        self.machine_title.set_alignment(0.0, 0.5)
        mark = "<span %s>Select a machine</span>" % self.span_tag(
            'x-large', 'bold')
        self.machine_title.set_markup(mark)

        self.machine_title_desc = gtk.Label()
        self.machine_title_desc.set_alignment(0.0, 0.5)
        mark = (
            "<span %s>Your selection is the profile of the target machine for which you"
            " are building the image.\n</span>") % (self.span_tag('medium'))
        self.machine_title_desc.set_markup(mark)

        self.machine_combo = gtk.combo_box_new_text()
        self.machine_combo.connect("changed", self.machine_combo_changed_cb)

        icon_file = hic.ICON_LAYERS_DISPLAY_FILE
        hover_file = hic.ICON_LAYERS_HOVER_FILE
        self.layer_button = HobImageButton(
            "Layers", "Add support for machines, software, etc.", icon_file,
            hover_file)
        self.layer_button.connect("clicked", self.layer_button_clicked_cb)

        markup = "Layers are a powerful mechanism to extend the Yocto Project "
        markup += "with your own functionality.\n"
        markup += "For more on layers, check the <a href=\""
        markup += "http://www.yoctoproject.org/docs/current/dev-manual/"
        markup += "dev-manual.html#understanding-and-using-layers\">reference manual</a>."
        self.layer_info_icon = HobInfoButton("<b>Layers</b>" + "*" + markup,
                                             self.get_parent())
        self.progress_bar = HobProgressBar()
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.machine_separator = gtk.HSeparator()

    def set_config_machine_layout(self, show_progress_bar=False):
        self.gtable.attach(self.machine_title, 0, 40, 0, 4)
        self.gtable.attach(self.machine_title_desc, 0, 40, 4, 6)
        self.gtable.attach(self.machine_combo, 0, 12, 7, 10)
        self.gtable.attach(self.layer_button, 14, 36, 7, 12)
        self.gtable.attach(self.layer_info_icon, 36, 40, 7, 11)
        if show_progress_bar:
            #self.gtable.attach(self.progress_box, 0, 40, 15, 18)
            self.gtable.attach(self.progress_bar, 0, 37, 15, 18)
            self.gtable.attach(self.stop_button, 37, 40, 15, 18, 0, 0)
        if self.builder.parsing_warnings:
            self.warnings_bar = self.add_warnings_bar()
            self.gtable.attach(self.warnings_bar, 0, 40, 14, 18)
            self.warning_shift = 4
        else:
            self.warning_shift = 0
        self.gtable.attach(self.machine_separator, 0, 40, 13, 14)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 1.0)
        mark = "<span %s>Select an image recipe</span>" % self.span_tag(
            'x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_title_desc = gtk.Label()
        self.image_title_desc.set_alignment(0, 0.5)

        mark = (
            "<span %s>Image recipes are a starting point for the type of image you want. "
            "You can build them as \n"
            "they are or edit them to suit your needs.\n</span>"
        ) % self.span_tag('medium')
        self.image_title_desc.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo.set_row_separator_func(self.combo_separator_func,
                                                None)
        self.image_combo_id = self.image_combo.connect(
            "changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0.0, 0.5)
        self.image_desc.set_size_request(256, -1)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        # button to view recipes
        icon_file = hic.ICON_RCIPE_DISPLAY_FILE
        hover_file = hic.ICON_RCIPE_HOVER_FILE
        self.view_adv_configuration_button = HobImageButton(
            "Advanced configuration",
            "Select image types, package formats, etc", icon_file, hover_file)
        self.view_adv_configuration_button.connect(
            "clicked", self.view_adv_configuration_button_clicked_cb)

        self.image_separator = gtk.HSeparator()

    def combo_separator_func(self, model, iter, user_data):
        name = model.get_value(iter, 0)
        if name == "--Separator--":
            return True

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 15 + self.warning_shift,
                           17 + self.warning_shift)
        self.gtable.attach(self.image_title_desc, 0, 40,
                           18 + self.warning_shift, 22 + self.warning_shift)
        self.gtable.attach(self.image_combo, 0, 12, 23 + self.warning_shift,
                           26 + self.warning_shift)
        self.gtable.attach(self.image_desc, 0, 12, 27 + self.warning_shift,
                           33 + self.warning_shift)
        self.gtable.attach(self.view_adv_configuration_button, 14, 36,
                           23 + self.warning_shift, 28 + self.warning_shift)
        self.gtable.attach(self.image_separator, 0, 40,
                           35 + self.warning_shift, 36 + self.warning_shift)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        self.just_bake_button.set_tooltip_text(
            "Build the image recipe as it is")
        self.just_bake_button.connect("clicked",
                                      self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit image recipe"
        self.edit_image_button = HobAltButton("Edit image recipe")
        self.edit_image_button.set_tooltip_text(
            "Customize the recipes and packages to be included in your image")
        self.edit_image_button.connect("clicked",
                                       self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def stop_button_clicked_cb(self, button):
        self.stopping = True
        self.progress_bar.set_text("Stopping recipe parsing")
        self.progress_bar.set_rcstyle("stop")
        self.builder.cancel_parse_sync()

    def view_warnings_button_clicked_cb(self, button):
        self.builder.show_warning_dialog()

    def machine_combo_changed_idle_cb(self):
        self.builder.window.set_cursor(None)

    def machine_combo_changed_cb(self, machine_combo):
        self.stopping = False
        self.builder.parsing_warnings = []
        combo_item = machine_combo.get_active_text()
        if not combo_item or combo_item == self.__dummy_machine__:
            return

        self.builder.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
        self.builder.wait(0.1)  #wait for combo and cursor to update

        # remove __dummy_machine__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = machine_combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_machine__):
            machine_combo.remove_text(0)

        self.builder.configuration.curr_mach = combo_item
        if self.machine_combo_changed_by_manual:
            self.builder.configuration.clear_selection()
        # reset machine_combo_changed_by_manual
        self.machine_combo_changed_by_manual = True

        self.builder.configuration.selected_image = None

        # Do reparse recipes
        self.builder.populate_recipe_package_info_async()

        glib.idle_add(self.machine_combo_changed_idle_cb)

    def update_machine_combo(self):
        self.disable_warnings_bar()
        all_machines = [self.__dummy_machine__
                        ] + self.builder.parameters.all_machines

        model = self.machine_combo.get_model()
        model.clear()
        for machine in all_machines:
            self.machine_combo.append_text(machine)
        self.machine_combo.set_active(0)

    def switch_machine_combo(self):
        self.disable_warnings_bar()
        self.machine_combo_changed_by_manual = False
        model = self.machine_combo.get_model()
        active = 0
        while active < len(model):
            if model[active][0] == self.builder.configuration.curr_mach:
                self.machine_combo.set_active(active)
                return
            active += 1

        if model[0][0] != self.__dummy_machine__:
            self.machine_combo.insert_text(0, self.__dummy_machine__)

        self.machine_combo.set_active(0)

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys(
        ):
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(
                image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes,
                                    selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if selected_image == self.__custom_image__:
            topdir = self.builder.get_topdir()
            images_dir = topdir + "/recipes/images/"
            self.builder.ensure_dir(images_dir)

            dialog = RetrieveImageDialog(
                images_dir, "Select from my image recipes", self.builder,
                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
            response = dialog.run()
            if response == gtk.RESPONSE_OK:
                image_name = dialog.get_filename()
                head, tail = os.path.split(image_name)
                selected_image = os.path.splitext(tail)[0]
                self.custom_image_selected = selected_image
                self.update_image_combo(self.builder.recipe_model,
                                        selected_image)
            else:
                selected_image = self.__dummy_image__
                self.update_image_combo(self.builder.recipe_model, None)
            dialog.destroy()
        else:
            if self.custom_image_selected:
                self.custom_image_selected = None
                self.update_image_combo(self.builder.recipe_model,
                                        selected_image)

        if not selected_image or (selected_image == self.__dummy_image__):
            self.builder.window_sensitive(True)
            self.just_bake_button.hide()
            self.edit_image_button.hide()
            return

        # remove __dummy_image__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_image__):
            combo.remove_text(0)

        self.builder.customized = False

        selected_recipes = []

        image_path = self.builder.recipe_model.pn_path[selected_image]
        image_iter = self.builder.recipe_model.get_iter(image_path)
        selected_packages = self.builder.recipe_model.get_value(
            image_iter, self.builder.recipe_model.COL_INSTALL).split()
        self.update_image_desc()

        self.builder.recipe_model.reset()
        self.builder.package_model.reset()

        self.show_baseimg_selected()

        if selected_image == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

        glib.idle_add(self.image_combo_changed_idle_cb, selected_image,
                      selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect(
                "changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, recipe_model, selected_image):
        # Update the image combo according to the images in the recipe_model
        # populate image combo
        filter = {RecipeListModel.COL_TYPE: ['image']}
        image_model = recipe_model.tree_model(filter)
        image_model.set_sort_column_id(recipe_model.COL_NAME,
                                       gtk.SORT_ASCENDING)
        active = 0
        cnt = 0

        white_pattern = []
        if self.builder.parameters.image_white_pattern:
            for i in self.builder.parameters.image_white_pattern.split():
                white_pattern.append(re.compile(i))

        black_pattern = []
        if self.builder.parameters.image_black_pattern:
            for i in self.builder.parameters.image_black_pattern.split():
                black_pattern.append(re.compile(i))
        black_pattern.append(re.compile("hob-image"))

        it = image_model.get_iter_first()
        self._image_combo_disconnect_signal()
        model = self.image_combo.get_model()
        model.clear()
        # Set a indicator text to combo store when first open
        if not selected_image:
            self.image_combo.append_text(self.__dummy_image__)
            cnt = cnt + 1

        self.image_combo.append_text(self.__custom_image__)
        self.image_combo.append_text("--Separator--")
        cnt = cnt + 2

        topdir = self.builder.get_topdir()
        # append and set active
        while it:
            path = image_model.get_path(it)
            it = image_model.iter_next(it)
            image_name = image_model[path][recipe_model.COL_NAME]
            if image_name == self.builder.recipe_model.__custom_image__:
                continue

            if black_pattern:
                allow = True
                for pattern in black_pattern:
                    if pattern.search(image_name):
                        allow = False
                        break
            elif white_pattern:
                allow = False
                for pattern in white_pattern:
                    if pattern.search(image_name):
                        allow = True
                        break
            else:
                allow = True

            file_name = image_model[path][recipe_model.COL_FILE]
            if file_name and topdir in file_name:
                allow = False

            if allow:
                self.image_combo.append_text(image_name)
                if image_name == selected_image:
                    active = cnt
                cnt = cnt + 1
        self.image_combo.append_text(
            self.builder.recipe_model.__custom_image__)

        if selected_image == self.builder.recipe_model.__custom_image__:
            active = cnt

        if self.custom_image_selected:
            self.image_combo.append_text("--Separator--")
            self.image_combo.append_text(self.custom_image_selected)
            cnt = cnt + 2
            if self.custom_image_selected == selected_image:
                active = cnt

        self.image_combo.set_active(active)

        if active != 0:
            self.show_baseimg_selected()

        self._image_combo_connect_signal()

    def layer_button_clicked_cb(self, button):
        # Create a layer selection dialog
        self.builder.show_layer_selection_dialog()

    def view_adv_configuration_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_adv_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
            self.builder.wait(0.1)  #wait for adv_settings_dialog to terminate
            self.builder.reparse_post_adv_settings()
            self.builder.window.set_cursor(None)

    def just_bake_button_clicked_cb(self, button):
        self.builder.parsing_warnings = []
        self.builder.just_bake()

    def edit_image_button_clicked_cb(self, button):
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_recipes()

    def my_images_button_clicked_cb(self, button):
        self.builder.show_load_my_images_dialog()

    def settings_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_simple_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()
    def show_page(self, step):
        build_succeeded = (step == self.builder.IMAGE_GENERATED)
        image_addr = self.builder.parameters.image_addr
        image_names = self.builder.parameters.image_names
        if build_succeeded:
            machine = self.builder.configuration.curr_mach
            base_image = self.builder.recipe_model.get_selected_image()
            layers = self.builder.configuration.layers
            pkg_num = "%s" % len(self.builder.package_model.get_selected_packages())
        else:
            pkg_num = "N/A"

        # remove
        for button_id, button in self.button_ids.items():
            button.disconnect(button_id)
        self._remove_all_widget()
        # repack
        self.pack_start(self.details_top_buttons, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.build_result = None
        if build_succeeded:
            # building is the previous step
            icon = gtk.Image()
            pixmap_path = hic.ICON_INDI_CONFIRM_FILE
            color = HobColors.RUNNING
            pix_buffer = gtk.gdk.pixbuf_new_from_file(pixmap_path)
            icon.set_from_pixbuf(pix_buffer)
            varlist = [""]
            vallist = ["Your image is ready"]
            self.build_result = self.DetailBox(varlist=varlist, vallist=vallist, icon=icon, color=color)
            self.box_group_area.pack_start(self.build_result, expand=False, fill=False)

        # create the buttons at the bottom first because the buttons are used in apply_button_per_image()
        if build_succeeded:
            self.buttonlist = ["Build new image", "Save as template", "Run image", "Deploy image"]
        else: # get to this page from "My images"
            self.buttonlist = ["Build new image", "Run image", "Deploy image"]

        # Name
        self.image_store.clear()
        default_toggled = False
        default_image_size = 0
        i = 0
        for image_name in image_names:
            image_size = HobPage._size_to_string(os.stat(os.path.join(image_addr, image_name)).st_size)
            if not default_toggled:
                default_toggled = (self.test_type_runnable(image_name) and self.test_mach_runnable(image_name)) \
                    or self.test_deployable(image_name)
                if i == (len(image_names) - 1):
                    default_toggled = True
                self.image_store.set(self.image_store.append(), 0, image_name, 1, image_size, 2, default_toggled)
                if default_toggled:
                    default_image_size = image_size
                    self.create_bottom_buttons(self.buttonlist, image_name)
            else:
                self.image_store.set(self.image_store.append(), 0, image_name, 1, image_size, 2, False)
            i = i + 1
        image_table = HobViewTable(self.__columns__)
        image_table.set_model(self.image_store)
        image_table.connect("toggled", self.toggled_cb)
        view_files_button = HobAltButton("View files")
        view_files_button.connect("clicked", self.view_files_clicked_cb, image_addr)
        view_files_button.set_tooltip_text("Open the directory containing the image files")
        self.image_detail = self.DetailBox(widget=image_table, button=view_files_button)
        self.box_group_area.pack_start(self.image_detail, expand=True, fill=True)

        # Machine, Base image and Layers
        layer_num_limit = 15
        varlist = ["Machine: ", "Base image: ", "Layers: "]
        vallist = []
        self.setting_detail = None
        if build_succeeded:
            vallist.append(machine)
            vallist.append(base_image)
            i = 0
            for layer in layers:
                varlist.append(" - ")
                if i > layer_num_limit:
                    break
                i += 1
            vallist.append("")
            i = 0
            for layer in layers:
                if i > layer_num_limit:
                    break
                elif i == layer_num_limit:
                    vallist.append("and more...")
                else:
                    vallist.append(layer)
                i += 1

            edit_config_button = HobAltButton("Edit configuration")
            edit_config_button.set_tooltip_text("Edit machine, base image and recipes")
            edit_config_button.connect("clicked", self.edit_config_button_clicked_cb)
            self.setting_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_config_button)
            self.box_group_area.pack_start(self.setting_detail, expand=False, fill=False)

        # Packages included, and Total image size
        varlist = ["Packages included: ", "Total image size: "]
        vallist = []
        vallist.append(pkg_num)
        vallist.append(default_image_size)
        if build_succeeded:
            edit_packages_button = HobAltButton("Edit packages")
            edit_packages_button.set_tooltip_text("Edit the packages included in your image")
            edit_packages_button.connect("clicked", self.edit_packages_button_clicked_cb)
        else: # get to this page from "My images"
            edit_packages_button = None
        self.package_detail = self.DetailBox(varlist=varlist, vallist=vallist, button=edit_packages_button)
        self.box_group_area.pack_start(self.package_detail, expand=False, fill=False)

        # pack the buttons at the bottom, at this time they are already created.
        self.box_group_area.pack_end(self.details_bottom_buttons, expand=False, fill=False)

        self.show_all()
class PackageSelectionPage (HobPage):

    pages = [
        {
         'name'    : 'Included',
         'filter'  : { PackageListModel.COL_INC : [True] },
         'columns' : [{
                       'col_name' : 'Package name',
                       'col_id'   : PackageListModel.COL_NAME,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Brought in by',
                       'col_id'   : PackageListModel.COL_BINB,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'binb',
                       'col_min'  : 100,
                       'col_max'  : 350,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Size',
                       'col_id'   : PackageListModel.COL_SIZE,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : PackageListModel.COL_INC,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'check toggle',
                       'col_group': 'tree store group',
                       'col_min'  : 100,
                       'col_max'  : 100
                     }]
        }, {
         'name'    : 'All packages',
         'filter'  : {},
         'columns' : [{
                       'col_name' : 'Package name',
                       'col_id'   : PackageListModel.COL_NAME,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Size',
                       'col_id'   : PackageListModel.COL_SIZE,
                       'col_t_id' : PackageListModel.COL_FONT,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 500,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : PackageListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_group': 'tree store group',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }
    ]

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Packages")

        # set invisiable members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        self.label = gtk.Label("Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visiable members
        self.ins = HobNotebook()
        self.tables = [] # we need to modify table when the dialog is shown
        # append the tab
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            filter = page['filter']
            tab.set_model(self.package_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            tab.connect_group_selection(self.table_selected_cb)
            if page['name'] == "Included":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include)
            label = gtk.Label(page['name'])
            self.ins.append_page(tab, label)
            self.tables.append(tab)

        self.ins.set_entry("Search packages:")
        # set the search entry for each table
        for tab in self.tables:
            tab.set_search_entry(0, self.ins.search)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(button_box, expand=False, fill=False)

        self.build_image_button = HobButton('Build image')
        self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        button_box.pack_end(self.build_image_button, expand=False, fill=False)

        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_start(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path: # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def build_image_clicked_cb(self, button):
        self.builder.build_image()

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def _expand_all(self):
        for tab in self.tables:
            tab.table_tree.expand_all()

    def refresh_selection(self):
        self._expand_all()

        self.builder.configuration.selected_packages = self.package_model.get_selected_packages()
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages()
        selected_packages_num = len(self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(selected_packages_size)

        image_overhead_factor = self.builder.configuration.image_overhead_factor
        image_rootfs_size = self.builder.configuration.image_rootfs_size * 1024 # image_rootfs_size is KB
        image_extra_size = self.builder.configuration.image_extra_size * 1024 # image_extra_size is KB
        base_size = image_overhead_factor * selected_packages_size
        image_total_size = max(base_size, image_rootfs_size) + image_extra_size
        if "zypper" in self.builder.configuration.selected_packages:
            image_total_size += (51200 * 1024)
        image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_text("Packages included: %s\nSelected packages size: %s\nTotal image size: %s" %
                            (selected_packages_num, selected_packages_size_str, image_total_size_str))
        self.ins.show_indicator_icon("Included", selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path, binb="User Selected")
        else:
            if pagename == "Included":
                self.pre_fadeout_checkout_include(view_tree)
                self.package_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.package_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__dummy_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree):
        self.package_model.resync_fadeout_column(self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = { PackageListModel.COL_FADE_INC  : [True]}
        new_model = self.package_model.tree_model(filter)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model, model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model, view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.package_model.tree_model(self.pages[0]['filter']))
        tree.expand_all()

    def foreach_cell_change_font(self, model, path, iter, paths=None):
        # Changed the font for a group cells
        if path and iter and path[0] == paths[0]:
            self.package_model.set(iter, self.package_model.COL_FONT, "bold")
        else:
            if iter and model.iter_parent(iter) == None:
                self.package_model.set(iter, self.package_model.COL_FONT, '11')
            else:
                self.package_model.set(iter, self.package_model.COL_FONT, '10')

    def table_selected_cb(self, selection):
        model, paths = selection.get_selected_rows()
        if paths:
            child_path = self.package_model.convert_vpath_to_path(model, paths[0])
            self.package_model.foreach(self.foreach_cell_change_font, child_path)
Exemple #44
0
class PackageSelectionPage(HobPage):

    pages = [{
        'name':
        'All packages',
        'tooltip':
        'All packages that have been built',
        'filter': {},
        'search':
        'Search packages by name',
        'searchtip':
        'Enter a package name to find it',
        'columns': [{
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 50,
            'col_max': 50
        }, {
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 200,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_style': 'text',
            'col_min': 80,
            'col_max': 80,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by',
            'col_id': PackageListModel.COL_BINB,
            'col_style': 'binb',
            'col_min': 150,
            'col_max': 170,
            'expand': 'True'
        }]
    }]

    (INCLUDED, ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisible members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        self.label = gtk.Label(
            "Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, padding=15)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need to modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tab
        page = self.pages[0]
        columns = page['columns']
        name = page['name']
        self.tab = HobViewTable(columns, name)
        search_names.append(page['search'])
        search_tips.append(page['searchtip'])
        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)
        filter = page['filter']
        sort_model = self.package_model.tree_model(filter, initial=True)
        self.tab.set_model(sort_model)
        self.tab.connect("toggled", self.table_toggled_cb, name)
        self.tab.connect("button-release-event", self.button_click_cb)
        self.tab.connect("cell-fadeinout-stopped",
                         self.after_fadeout_checkin_include, filter)
        #self.tab.set_size_request(-1, 350)
        self.ins.append_page(self.tab, page['name'], page['tooltip'])
        self.tables.append(self.tab)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box,
                                       expand=False,
                                       fill=False)

        self.build_image_button = HobButton('Build image')
        self.build_image_button.set_tooltip_text("Build your image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = 0
        filter = self.pages[current_tab]['filter']
        filter[PackageListModel.COL_NAME] = text
        self.tables[current_tab].set_model(
            self.package_model.tree_model(filter, search_data=text))
        if self.package_model.filtered_nb == 0:
            if not self.tab.top_bar:
                self.tab.add_no_result_bar(entry)
                self.tab.top_bar.set_no_show_all(True)
            self.tab.top_bar.show()
            self.tab.scroll.hide()
        else:
            if self.tab.top_bar:
                self.tab.top_bar.hide()
            self.tab.scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title(
        ) != 'Included':  # else activation is likely a removal
            properties = {
                'binb': '',
                'name': '',
                'size': '',
                'recipe': '',
                'files_list': ''
            }
            properties['binb'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_BINB)
            properties['name'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_NAME)
            properties['size'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_SIZE)
            properties['files_list'] = tree_model.get_value(
                tree_model.get_iter(path), PackageListModel.COL_FLIST)

            self.builder.show_recipe_property_dialog(properties)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb,
                                    log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        selected_pkgs = self.package_model.get_selected_packages()
        show_missing_pkg_dialog = False
        lbl = "<b>Missing important packages</b>\n\nYour list of included "
        lbl = lbl + " packages is missing:\n\n"
        if not ('eglibc' in selected_pkgs or 'uclibc' in selected_pkgs):
            show_missing_pkg_dialog = True
            lbl = lbl + "-A C library (choose eglibc or uclibc)\n\n"
        if not ('bash' in selected_pkgs or 'busybox' in selected_pkgs):
            show_missing_pkg_dialog = True
            lbl = lbl + "-A shell provider (choose bash or busybox)\n\n"
        if 'initscripts' not in selected_pkgs:
            show_missing_pkg_dialog = True
            lbl = lbl + "-Initialization scripts (choose initscripts)\n\n"

        if show_missing_pkg_dialog:
            dialog = CrumbsMessageDialog(None, lbl, gtk.STOCK_DIALOG_INFO)
            button = dialog.add_button("Build anyway", gtk.RESPONSE_OK)
            tooltip = "Build the image without changing the included packages"
            button.set_tooltip_text(tooltip)
            HobButton.style_button(button)
            button = dialog.add_button("Edit packages", gtk.RESPONSE_CANCEL)
            tooltip = "Change the list of included packages"
            button.set_tooltip_text(tooltip)
            HobButton.style_button(button)
            response = dialog.run()
            dialog.destroy()
            if response == gtk.RESPONSE_CANCEL:
                return
        self.builder.build_image()

    def refresh_tables(self):
        self.ins.reset_entry(self.ins.search, 0)
        for tab in self.tables:
            index = self.tables.index(tab)
            filter = self.pages[index]['filter']
            tab.set_model(self.package_model.tree_model(filter, initial=True))

    def back_button_clicked_cb(self, button):
        self.builder.restore_initial_selected_packages()
        self.refresh_selection()
        self.ins.search.set_text("")
        self.builder.recipe_model.set_selected_image(
            self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_combo(
            self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_desc()
        self.builder.show_configuration()
        self.refresh_tables()

    def refresh_selection(self):
        self.builder.configuration.selected_packages = self.package_model.get_selected_packages(
        )
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages(
        )
        selected_packages_num = len(
            self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(
            selected_packages_size)

        self.label.set_label(
            "Packages included: %s   Selected packages size: %s" %
            (selected_packages_num, selected_packages_size_str))

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path,
                                            binb="User Selected")
        else:
            self.pre_fadeout_checkout_include(view_tree)
            self.package_model.exclude_item(item_path=path)
            self.render_fadeout(view_tree, cell)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)
        view_model = view_tree.get_model()
        vpath = self.package_model.convert_path_to_vpath(view_model, path)
        view_tree.set_cursor(vpath)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        #after the fadeout the table will be sorted as before
        self.sort_column_id = self.package_model.sort_column_id
        self.sort_order = self.package_model.sort_order

        self.package_model.resync_fadeout_column(
            self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {PackageListModel.COL_FADE_INC: [True]}
        new_model = self.package_model.tree_model(filter,
                                                  excluded_items_ahead=True)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(
                it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model,
                                       model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model,
                               view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree, filter):
        self.package_model.sort_column_id = self.sort_column_id
        self.package_model.sort_order = self.sort_order
        tree.set_model(self.package_model.tree_model(filter))
        tree.expand_all()
    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build. Check the \"Issues\" tab for more details</span>"
            label.set_markup(markup)
        else:
            label.set_markup("<span size='medium'>Check the \"Issues\" information for more details</span>")
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked', self.failure_primary_action_button_clicked_cb, primary_action)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb, log_file)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text("Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked', self.failure_activate_file_bug_link_cb)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 13, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, 14, 23, 9, 12)
            build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked', self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, attach_pos, attach_pos + 9, 9, 12)

        self.builder.disk_full = False
        return build_fail_top
class SimpleSettingsDialog (CrumbsDialog, SettingsUIHelper):

    (BUILD_ENV_PAGE_ID,
     SHARED_STATE_PAGE_ID,
     PROXIES_PAGE_ID,
     OTHERS_PAGE_ID) = range(4)

    (TEST_NETWORK_NONE,
     TEST_NETWORK_INITIAL,
     TEST_NETWORK_RUNNING,
     TEST_NETWORK_PASSED,
     TEST_NETWORK_FAILED,
     TEST_NETWORK_CANCELED) = range(6)

    TARGETS = [
        ("MY_TREE_MODEL_ROW", gtk.TARGET_SAME_WIDGET, 0),
        ("text/plain", 0, 1),
        ("TEXT", 0, 2),
        ("STRING", 0, 3),
        ]

    def __init__(self, title, configuration, all_image_types,
            all_package_formats, all_distros, all_sdk_machines,
            max_threads, parent, flags, handler, buttons=None):
        super(SimpleSettingsDialog, self).__init__(title, parent, flags, buttons)

        # class members from other objects
        # bitbake settings from Builder.Configuration
        self.configuration = configuration
        self.image_types = all_image_types
        self.all_package_formats = all_package_formats
        self.all_distros = all_distros
        self.all_sdk_machines = all_sdk_machines
        self.max_threads = max_threads

        # class members for internal use
        self.dldir_text = None
        self.sstatedir_text = None
        self.sstatemirrors_list = []
        self.sstatemirrors_changed = 0
        self.bb_spinner = None
        self.pmake_spinner = None
        self.rootfs_size_spinner = None
        self.extra_size_spinner = None
        self.gplv3_checkbox = None
        self.toolchain_checkbox = None
        self.setting_store = None
        self.image_types_checkbuttons = {}

        self.md5 = self.config_md5()
        self.proxy_md5 = self.config_proxy_md5()
        self.settings_changed = False
        self.proxy_settings_changed = False
        self.handler = handler
        self.proxy_test_ran = False
        self.selected_mirror_row = 0
        self.new_mirror = False

        # create visual elements on the dialog
        self.create_visual_elements()
        self.connect("response", self.response_cb)

    def _get_sorted_value(self, var):
        return " ".join(sorted(str(var).split())) + "\n"

    def config_proxy_md5(self):
        data = ("ENABLE_PROXY: "         + self._get_sorted_value(self.configuration.enable_proxy))
        if self.configuration.enable_proxy:
            for protocol in self.configuration.proxies.keys():
                data += (protocol + ": " + self._get_sorted_value(self.configuration.combine_proxy(protocol)))
        return hashlib.md5(data).hexdigest()

    def config_md5(self):
        data = ""
        for key in self.configuration.extra_setting.keys():
            data += (key + ": " + self._get_sorted_value(self.configuration.extra_setting[key]))
        return hashlib.md5(data).hexdigest()

    def gen_proxy_entry_widget(self, protocol, parent, need_button=True, line=0):
        label = gtk.Label(protocol.upper() + " proxy")
        self.proxy_table.attach(label, 0, 1, line, line+1, xpadding=24)

        proxy_entry = gtk.Entry()
        proxy_entry.set_size_request(300, -1)
        self.proxy_table.attach(proxy_entry, 1, 2, line, line+1, ypadding=4)

        self.proxy_table.attach(gtk.Label(":"), 2, 3, line, line+1, xpadding=12, ypadding=4)

        port_entry = gtk.Entry()
        port_entry.set_size_request(60, -1)
        self.proxy_table.attach(port_entry, 3, 4, line, line+1, ypadding=4)

        details_button = HobAltButton("Details")
        details_button.connect("clicked", self.details_cb, parent, protocol)
        self.proxy_table.attach(details_button, 4, 5, line, line+1, xpadding=4, yoptions=gtk.EXPAND)

        return proxy_entry, port_entry, details_button

    def refresh_proxy_components(self):
        self.same_checkbox.set_sensitive(self.configuration.enable_proxy)

        self.http_proxy.set_text(self.configuration.combine_host_only("http"))
        self.http_proxy.set_editable(self.configuration.enable_proxy)
        self.http_proxy.set_sensitive(self.configuration.enable_proxy)
        self.http_proxy_port.set_text(self.configuration.combine_port_only("http"))
        self.http_proxy_port.set_editable(self.configuration.enable_proxy)
        self.http_proxy_port.set_sensitive(self.configuration.enable_proxy)
        self.http_proxy_details.set_sensitive(self.configuration.enable_proxy)

        self.https_proxy.set_text(self.configuration.combine_host_only("https"))
        self.https_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_port.set_text(self.configuration.combine_port_only("https"))
        self.https_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.https_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.ftp_proxy.set_text(self.configuration.combine_host_only("ftp"))
        self.ftp_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_port.set_text(self.configuration.combine_port_only("ftp"))
        self.ftp_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.ftp_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.socks_proxy.set_text(self.configuration.combine_host_only("socks"))
        self.socks_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.socks_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.socks_proxy_port.set_text(self.configuration.combine_port_only("socks"))
        self.socks_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.socks_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.socks_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        self.cvs_proxy.set_text(self.configuration.combine_host_only("cvs"))
        self.cvs_proxy.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_port.set_text(self.configuration.combine_port_only("cvs"))
        self.cvs_proxy_port.set_editable(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_port.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))
        self.cvs_proxy_details.set_sensitive(self.configuration.enable_proxy and (not self.configuration.same_proxy))

        if self.configuration.same_proxy:
            if self.http_proxy.get_text():
                [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses]
            if self.http_proxy_port.get_text():
                [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports]

    def proxy_checkbox_toggled_cb(self, button):
        self.configuration.enable_proxy = self.proxy_checkbox.get_active()
        if not self.configuration.enable_proxy:
            self.configuration.same_proxy = False
            self.same_checkbox.set_active(self.configuration.same_proxy)
        self.save_proxy_data()
        self.refresh_proxy_components()

    def same_checkbox_toggled_cb(self, button):
        self.configuration.same_proxy = self.same_checkbox.get_active()
        self.save_proxy_data()
        self.refresh_proxy_components()

    def save_proxy_data(self):
        self.configuration.split_proxy("http", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
        if self.configuration.same_proxy:
            self.configuration.split_proxy("https", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("ftp", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("socks", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
            self.configuration.split_proxy("cvs", self.http_proxy.get_text() + ":" + self.http_proxy_port.get_text())
        else:
            self.configuration.split_proxy("https", self.https_proxy.get_text() + ":" + self.https_proxy_port.get_text())
            self.configuration.split_proxy("ftp", self.ftp_proxy.get_text() + ":" + self.ftp_proxy_port.get_text())
            self.configuration.split_proxy("socks", self.socks_proxy.get_text() + ":" + self.socks_proxy_port.get_text())
            self.configuration.split_proxy("cvs", self.cvs_proxy.get_text() + ":" + self.cvs_proxy_port.get_text())       

    def response_cb(self, dialog, response_id):
        if response_id == gtk.RESPONSE_YES:
            if self.proxy_checkbox.get_active():
                # Check that all proxy entries have a corresponding port
                for proxy, port in zip(self.all_proxy_addresses, self.all_proxy_ports):
                    if proxy.get_text() and not port.get_text():
                        lbl = "<b>Enter all port numbers</b>"
                        msg = "Proxy servers require a port number. Please make sure you have entered a port number for each proxy server."
                        dialog = CrumbsMessageDialog(self, lbl, gtk.MESSAGE_WARNING, msg)
                        button = dialog.add_button("Close", gtk.RESPONSE_OK)
                        HobButton.style_button(button)
                        response = dialog.run()
                        dialog.destroy()
                        self.emit_stop_by_name("response")
                        return

        self.configuration.dldir = self.dldir_text.get_text()
        self.configuration.sstatedir = self.sstatedir_text.get_text()
        self.configuration.sstatemirror = ""
        for mirror in self.sstatemirrors_list:
            if mirror[1] != "" and mirror[2].startswith("file://"):
                if mirror[1].endswith("\\1"):
                    smirror = mirror[2] + " " + mirror[1] + " \\n "
                else:
                    smirror = mirror[2] + " " + mirror[1] + "\\1 \\n "
                self.configuration.sstatemirror += smirror
        self.configuration.bbthread = self.bb_spinner.get_value_as_int()
        self.configuration.pmake = self.pmake_spinner.get_value_as_int()
        self.save_proxy_data()
        self.configuration.extra_setting = {}
        it = self.setting_store.get_iter_first()
        while it:
            key = self.setting_store.get_value(it, 0)
            value = self.setting_store.get_value(it, 1)
            self.configuration.extra_setting[key] = value
            it = self.setting_store.iter_next(it)

        md5 = self.config_md5()
        self.settings_changed = (self.md5 != md5)
        self.proxy_settings_changed = (self.proxy_md5 != self.config_proxy_md5())

    def create_build_environment_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)

        advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Parallel threads</span>'), expand=False, fill=False)
        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("BitBake parallel threads")
        tooltip = "Sets the number of threads that BitBake tasks can simultaneously run. See the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#var-BB_NUMBER_THREADS\">Poky reference manual</a> for information"
        bbthread_widget, self.bb_spinner = self.gen_spinner_widget(self.configuration.bbthread, 1, self.max_threads,"<b>BitBake prallalel threads</b>" + "*" + tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(bbthread_widget, expand=False, fill=False)

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("Make parallel threads")
        tooltip = "Sets the maximum number of threads the host can use during the build. See the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#var-PARALLEL_MAKE\">Poky reference manual</a> for information"
        pmake_widget, self.pmake_spinner = self.gen_spinner_widget(self.configuration.pmake, 1, self.max_threads,"<b>Make parallel threads</b>" + "*" + tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(pmake_widget, expand=False, fill=False)

        advanced_vbox.pack_start(self.gen_label_widget('<span weight="bold">Downloaded source code</span>'), expand=False, fill=False)
        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("Downloads directory")
        tooltip = "Select a folder that caches the upstream project source code"
        dldir_widget, self.dldir_text = self.gen_entry_widget(self.configuration.dldir, self,"<b>Downloaded source code</b>" + "*" + tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(dldir_widget, expand=False, fill=False)

        return advanced_vbox

    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content,"<b>Shared state directory</b>" + "*" + tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=6)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content,"<b>Shared state mirrors</b>" + "*" + tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, gtk.TRUE, gtk.TRUE, 0)

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = ["Standard", "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                sstatemirrors = [x for x in sstatemirrors.split('\\n')]
                for sstatemirror in sstatemirrors:
                    sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()]
                    if len(sstatemirror_fields) == 2:
                        if sstatemirror_fields[0] == "file://(.*)" or sstatemirror_fields[0] == "file://.*":
                            sm_list = ["Standard", sstatemirror_fields[1], sstatemirror_fields[0]]
                        else:
                            sm_list = ["Custom", sstatemirror_fields[1], sstatemirror_fields[0]]
                        self.sstatemirrors_list.append(sm_list)

        sstatemirrors_widget, sstatemirrors_store = self.gen_shared_sstate_widget(self.sstatemirrors_list, self)
        sub_vbox.pack_start(sstatemirrors_widget, expand=True, fill=True)

        table = gtk.Table(1, 10, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(120,30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)

        self.delete_button = HobAltButton("Delete mirror")
        self.delete_button.connect("clicked", self.delete_cb)
        self.delete_button.set_size_request(120, 30)
        table.attach(self.delete_button, 3, 4, 0, 1, xoptions=gtk.SHRINK)

        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        return advanced_vbox

    def gen_shared_sstate_widget(self, sstatemirrors_list, window):
        hbox = gtk.HBox(False)

        sstatemirrors_store = gtk.ListStore(str, str, str)
        for sstatemirror in sstatemirrors_list:
            sstatemirrors_store.append(sstatemirror)

        self.sstatemirrors_tv = gtk.TreeView()
        self.sstatemirrors_tv.set_rules_hint(True)
        self.sstatemirrors_tv.set_headers_visible(True)
        tree_selection = self.sstatemirrors_tv.get_selection()
        tree_selection.set_mode(gtk.SELECTION_SINGLE)

        # Allow enable drag and drop of rows including row move
        self.sstatemirrors_tv.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,
            self.TARGETS,
            gtk.gdk.ACTION_DEFAULT|
            gtk.gdk.ACTION_MOVE)
        self.sstatemirrors_tv.enable_model_drag_dest(self.TARGETS,
            gtk.gdk.ACTION_DEFAULT)
        self.sstatemirrors_tv.connect("drag_data_get", self.drag_data_get_cb)
        self.sstatemirrors_tv.connect("drag_data_received", self.drag_data_received_cb)


        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.scroll.set_shadow_type(gtk.SHADOW_IN)
        self.scroll.connect('size-allocate', self.scroll_changed)
        self.scroll.add(self.sstatemirrors_tv)

        #list store for cell renderer
        m = gtk.ListStore(gobject.TYPE_STRING)
        m.append(["Standard"])
        m.append(["Custom"])

        cell0 = gtk.CellRendererCombo()
        cell0.set_property("model",m)
        cell0.set_property("text-column", 0)
        cell0.set_property("editable", True)
        cell0.set_property("has-entry", False)
        col0 = gtk.TreeViewColumn("Configuration")
        col0.pack_start(cell0, False)
        col0.add_attribute(cell0, "text", 0)
        col0.set_cell_data_func(cell0, self.configuration_field)
        self.sstatemirrors_tv.append_column(col0)

        cell0.connect("edited", self.combo_changed, sstatemirrors_store)

        self.cell1 = gtk.CellRendererText()
        self.cell1.set_padding(5,2)
        col1 = gtk.TreeViewColumn('Regex', self.cell1)
        col1.set_cell_data_func(self.cell1, self.regex_field)
        self.sstatemirrors_tv.append_column(col1)

        self.cell1.connect("edited", self.regex_changed, sstatemirrors_store)

        cell2 = gtk.CellRendererText()
        cell2.set_padding(5,2)
        cell2.set_property("editable", True)
        col2 = gtk.TreeViewColumn('URL', cell2)
        col2.set_cell_data_func(cell2, self.url_field)
        self.sstatemirrors_tv.append_column(col2)

        cell2.connect("edited", self.url_changed, sstatemirrors_store)

        self.sstatemirrors_tv.set_model(sstatemirrors_store)
        self.sstatemirrors_tv.set_cursor(self.selected_mirror_row)
        hbox.pack_start(self.scroll, expand=True, fill=True)
        hbox.show_all()

        return hbox, sstatemirrors_store

    def drag_data_get_cb(self, treeview, context, selection, target_id, etime):
        treeselection = treeview.get_selection()
        model, iter = treeselection.get_selected()
        data = model.get_string_from_iter(iter)
        selection.set(selection.target, 8, data)

    def drag_data_received_cb(self, treeview, context, x, y, selection, info, etime):
        model = treeview.get_model()
        data = []
        tree_iter = model.get_iter_from_string(selection.data)
        data.append(model.get_value(tree_iter, 0))
        data.append(model.get_value(tree_iter, 1))
        data.append(model.get_value(tree_iter, 2))

        drop_info = treeview.get_dest_row_at_pos(x, y)
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)
            if (position == gtk.TREE_VIEW_DROP_BEFORE or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                model.insert_before(iter, data)
            else:
                model.insert_after(iter, data)
        else:
            model.append(data)
        if context.action == gtk.gdk.ACTION_MOVE:
            context.finish(True, True, etime)
        return

    def delete_cb(self, button):
        selection = self.sstatemirrors_tv.get_selection()
        tree_model, tree_iter = selection.get_selected()
        index = int(tree_model.get_string_from_iter(tree_iter))
        if index == 0:
            self.selected_mirror_row = index
        else:
            self.selected_mirror_row = index - 1
        self.sstatemirrors_list.pop(index)
        self.refresh_shared_state_page()
        if not self.sstatemirrors_list:
            self.delete_button.set_sensitive(False)

    def add_mirror(self, button):
        self.new_mirror = True
        tooltip = "Select the pre-built mirror that will speed your build"
        index = len(self.sstatemirrors_list)
        self.selected_mirror_row = index
        sm_list = ["Standard", "", "file://(.*)"]
        self.sstatemirrors_list.append(sm_list)
        self.refresh_shared_state_page()

    def scroll_changed(self, widget, event, data=None):
        if self.new_mirror == True:
            adj = widget.get_vadjustment()
            adj.set_value(adj.upper - adj.page_size)
            self.new_mirror = False

    def combo_changed(self, widget, path, text, model):
        model[path][0] = text
        selection = self.sstatemirrors_tv.get_selection()
        tree_model, tree_iter = selection.get_selected()
        index = int(tree_model.get_string_from_iter(tree_iter))
        self.sstatemirrors_list[index][0] = text

    def regex_changed(self, cell, path, new_text, user_data):
        user_data[path][2] = new_text
        selection = self.sstatemirrors_tv.get_selection()
        tree_model, tree_iter = selection.get_selected()
        index = int(tree_model.get_string_from_iter(tree_iter))
        self.sstatemirrors_list[index][2] = new_text
        return

    def url_changed(self, cell, path, new_text, user_data):
        if new_text!="Enter the mirror URL" and new_text!="Match regex and replace it with this URL":
            user_data[path][1] = new_text
            selection = self.sstatemirrors_tv.get_selection()
            tree_model, tree_iter = selection.get_selected()
            index = int(tree_model.get_string_from_iter(tree_iter))
            self.sstatemirrors_list[index][1] = new_text
        return

    def configuration_field(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 0))
        if model.get_value(iter, 0) == "Standard":
            self.cell1.set_property("sensitive", False)
            self.cell1.set_property("editable", False)
        else:
            self.cell1.set_property("sensitive", True)
            self.cell1.set_property("editable", True)
        return

    def regex_field(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 2))
        return

    def url_field(self, column, cell, model, iter):
        text = model.get_value(iter, 1)
        if text == "":
            if model.get_value(iter, 0) == "Standard":
                text = "Enter the mirror URL"
            else:
                text = "Match regex and replace it with this URL"
        cell.set_property('text', text)
        return

    def refresh_shared_state_page(self):
        page_num = self.nb.get_current_page()
        self.nb.remove_page(page_num);
        self.nb.insert_page(self.create_shared_state_page(), gtk.Label("Shared state"),page_num)
        self.show_all()
        self.nb.set_current_page(page_num)

    def test_proxy_ended(self, passed):
        self.proxy_test_running = False
        self.set_test_proxy_state(self.TEST_NETWORK_PASSED if passed else self.TEST_NETWORK_FAILED)
        self.set_sensitive(True)
        self.refresh_proxy_components()

    def timer_func(self):
        self.test_proxy_progress.pulse()
        return self.proxy_test_running

    def test_network_button_cb(self, b):
        self.set_test_proxy_state(self.TEST_NETWORK_RUNNING)
        self.set_sensitive(False)
        self.save_proxy_data()
        if self.configuration.enable_proxy == True:
            self.handler.set_http_proxy(self.configuration.combine_proxy("http"))
            self.handler.set_https_proxy(self.configuration.combine_proxy("https"))
            self.handler.set_ftp_proxy(self.configuration.combine_proxy("ftp"))
            self.handler.set_socks_proxy(self.configuration.combine_proxy("socks"))
            self.handler.set_cvs_proxy(self.configuration.combine_host_only("cvs"), self.configuration.combine_port_only("cvs"))
        elif self.configuration.enable_proxy == False:
            self.handler.set_http_proxy("")
            self.handler.set_https_proxy("")
            self.handler.set_ftp_proxy("")
            self.handler.set_socks_proxy("")
            self.handler.set_cvs_proxy("", "")
        self.proxy_test_ran = True
        self.proxy_test_running = True
        gobject.timeout_add(100, self.timer_func)
        self.handler.trigger_network_test()

    def test_proxy_focus_event(self, w, direction):
        if self.test_proxy_state in [self.TEST_NETWORK_PASSED, self.TEST_NETWORK_FAILED]:
            self.set_test_proxy_state(self.TEST_NETWORK_INITIAL)
        return False

    def http_proxy_changed(self, e):
        if not self.configuration.same_proxy:
            return
        if e == self.http_proxy:
            [w.set_text(self.http_proxy.get_text()) for w in self.same_proxy_addresses]
        else:
            [w.set_text(self.http_proxy_port.get_text()) for w in self.same_proxy_ports]

    def proxy_address_focus_out_event(self, w, direction):
        text = w.get_text()
        if not text:
            return False
        if text.find("//") == -1:
            w.set_text("http://" + text)
        return False

    def set_test_proxy_state(self, state):
        if self.test_proxy_state == state:
            return
        [self.proxy_table.remove(w) for w in self.test_gui_elements]
        if state == self.TEST_NETWORK_INITIAL:
            self.proxy_table.attach(self.test_network_button, 1, 2, 5, 6)
            self.test_network_button.show()
        elif state == self.TEST_NETWORK_RUNNING:
            self.test_proxy_progress.set_rcstyle("running")
            self.test_proxy_progress.set_text("Testing network configuration")
            self.proxy_table.attach(self.test_proxy_progress, 0, 5, 5, 6, xpadding=4)
            self.test_proxy_progress.show()
        else: # passed or failed
            self.dummy_progress.update(1.0)
            if state == self.TEST_NETWORK_PASSED:
                self.dummy_progress.set_text("Your network is properly configured")
                self.dummy_progress.set_rcstyle("running")
            else:
                self.dummy_progress.set_text("Network test failed")
                self.dummy_progress.set_rcstyle("fail")
            self.proxy_table.attach(self.dummy_progress, 0, 4, 5, 6)
            self.proxy_table.attach(self.retest_network_button, 4, 5, 5, 6, xpadding=4)
            self.dummy_progress.show()
            self.retest_network_button.show()
        self.test_proxy_state = state

    def create_network_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)
        self.same_proxy_addresses = []
        self.same_proxy_ports = []
        self.all_proxy_ports = []
        self.all_proxy_addresses = []

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False)
        label = self.gen_label_widget("<span weight=\"bold\">Set the proxies used when fetching source code</span>")
        tooltip = "Set the proxies used when fetching source code.  A blank field uses a direct internet connection."
        info = HobInfoButton("<span weight=\"bold\">Set the proxies used when fetching source code</span>" + "*" + tooltip, self)
        hbox = gtk.HBox(False, 12)
        hbox.pack_start(label, expand=True, fill=True)
        hbox.pack_start(info, expand=False, fill=False)
        sub_vbox.pack_start(hbox, expand=False, fill=False)

        proxy_test_focus = []
        self.direct_checkbox = gtk.RadioButton(None, "Direct network connection")
        proxy_test_focus.append(self.direct_checkbox)
        self.direct_checkbox.set_tooltip_text("Check this box to use a direct internet connection with no proxy")
        self.direct_checkbox.set_active(not self.configuration.enable_proxy)
        sub_vbox.pack_start(self.direct_checkbox, expand=False, fill=False)

        self.proxy_checkbox = gtk.RadioButton(self.direct_checkbox, "Manual proxy configuration")
        proxy_test_focus.append(self.proxy_checkbox)
        self.proxy_checkbox.set_tooltip_text("Check this box to manually set up a specific proxy")
        self.proxy_checkbox.set_active(self.configuration.enable_proxy)
        sub_vbox.pack_start(self.proxy_checkbox, expand=False, fill=False)

        self.same_checkbox = gtk.CheckButton("Use the HTTP proxy for all protocols")
        proxy_test_focus.append(self.same_checkbox)
        self.same_checkbox.set_tooltip_text("Check this box to use the HTTP proxy for all five proxies")
        self.same_checkbox.set_active(self.configuration.same_proxy)
        hbox = gtk.HBox(False, 12)
        hbox.pack_start(self.same_checkbox, expand=False, fill=False, padding=24)
        sub_vbox.pack_start(hbox, expand=False, fill=False)

        self.proxy_table = gtk.Table(6, 5, False)
        self.http_proxy, self.http_proxy_port, self.http_proxy_details = self.gen_proxy_entry_widget(
            "http", self, True, 0)
        proxy_test_focus +=[self.http_proxy, self.http_proxy_port]
        self.http_proxy.connect("changed", self.http_proxy_changed)
        self.http_proxy_port.connect("changed", self.http_proxy_changed)

        self.https_proxy, self.https_proxy_port, self.https_proxy_details = self.gen_proxy_entry_widget(
            "https", self, True, 1)
        proxy_test_focus += [self.https_proxy, self.https_proxy_port]
        self.same_proxy_addresses.append(self.https_proxy)
        self.same_proxy_ports.append(self.https_proxy_port)

        self.ftp_proxy, self.ftp_proxy_port, self.ftp_proxy_details = self.gen_proxy_entry_widget(
            "ftp", self, True, 2)
        proxy_test_focus += [self.ftp_proxy, self.ftp_proxy_port]
        self.same_proxy_addresses.append(self.ftp_proxy)
        self.same_proxy_ports.append(self.ftp_proxy_port)

        self.socks_proxy, self.socks_proxy_port, self.socks_proxy_details = self.gen_proxy_entry_widget(
            "socks", self, True, 3)
        proxy_test_focus += [self.socks_proxy, self.socks_proxy_port]
        self.same_proxy_addresses.append(self.socks_proxy)
        self.same_proxy_ports.append(self.socks_proxy_port)

        self.cvs_proxy, self.cvs_proxy_port, self.cvs_proxy_details = self.gen_proxy_entry_widget(
            "cvs", self, True, 4)
        proxy_test_focus += [self.cvs_proxy, self.cvs_proxy_port]
        self.same_proxy_addresses.append(self.cvs_proxy)
        self.same_proxy_ports.append(self.cvs_proxy_port)
        self.all_proxy_ports = self.same_proxy_ports + [self.http_proxy_port]
        self.all_proxy_addresses = self.same_proxy_addresses + [self.http_proxy]
        sub_vbox.pack_start(self.proxy_table, expand=False, fill=False)
        self.proxy_table.show_all()

        # Create the graphical elements for the network test feature, but don't display them yet
        self.test_network_button = HobAltButton("Test network configuration")
        self.test_network_button.connect("clicked", self.test_network_button_cb)
        self.test_proxy_progress = HobProgressBar()
        self.dummy_progress = HobProgressBar()
        self.retest_network_button = HobAltButton("Retest")
        self.retest_network_button.connect("clicked", self.test_network_button_cb)
        self.test_gui_elements = [self.test_network_button, self.test_proxy_progress, self.dummy_progress, self.retest_network_button]
        # Initialize the network tester
        self.test_proxy_state = self.TEST_NETWORK_NONE
        self.set_test_proxy_state(self.TEST_NETWORK_INITIAL)
        self.proxy_test_passed_id = self.handler.connect("network-passed", lambda h:self.test_proxy_ended(True))
        self.proxy_test_failed_id = self.handler.connect("network-failed", lambda h:self.test_proxy_ended(False))
        [w.connect("focus-in-event", self.test_proxy_focus_event) for w in proxy_test_focus]
        [w.connect("focus-out-event", self.proxy_address_focus_out_event) for w in self.all_proxy_addresses]

        self.direct_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb)
        self.proxy_checkbox.connect("toggled", self.proxy_checkbox_toggled_cb)
        self.same_checkbox.connect("toggled", self.same_checkbox_toggled_cb)

        self.refresh_proxy_components()
        return advanced_vbox

    def switch_to_page(self, page_id):
        self.nb.set_current_page(page_id)

    def details_cb(self, button, parent, protocol):
        self.save_proxy_data()
        dialog = ProxyDetailsDialog(title = protocol.upper() + " Proxy Details",
            user = self.configuration.proxies[protocol][1],
            passwd = self.configuration.proxies[protocol][2],
            parent = parent,
            flags = gtk.DIALOG_MODAL
                    | gtk.DIALOG_DESTROY_WITH_PARENT
                    | gtk.DIALOG_NO_SEPARATOR)
        dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_OK)
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.configuration.proxies[protocol][1] = dialog.user
            self.configuration.proxies[protocol][2] = dialog.passwd
            self.refresh_proxy_components()
        dialog.destroy()    

    def rootfs_combo_changed_cb(self, rootfs_combo, all_package_format, check_hbox):
        combo_item = self.rootfs_combo.get_active_text()
        for child in check_hbox.get_children():
            if isinstance(child, gtk.CheckButton):
                check_hbox.remove(child)
        for format in all_package_format:
            if format != combo_item:
                check_button = gtk.CheckButton(format)
                check_hbox.pack_start(check_button, expand=False, fill=False)
        check_hbox.show_all()

    def gen_pkgfmt_widget(self, curr_package_format, all_package_format, tooltip_combo="", tooltip_extra=""):
        pkgfmt_hbox = gtk.HBox(False, 24)

        rootfs_vbox = gtk.VBox(False, 6)
        pkgfmt_hbox.pack_start(rootfs_vbox, expand=False, fill=False)

        label = self.gen_label_widget("Root file system package format")
        rootfs_vbox.pack_start(label, expand=False, fill=False)

        rootfs_format = ""
        if curr_package_format:
            rootfs_format = curr_package_format.split()[0]

        rootfs_format_widget, rootfs_combo = self.gen_combo_widget(rootfs_format, all_package_format, tooltip_combo)
        rootfs_vbox.pack_start(rootfs_format_widget, expand=False, fill=False)

        extra_vbox = gtk.VBox(False, 6)
        pkgfmt_hbox.pack_start(extra_vbox, expand=False, fill=False)

        label = self.gen_label_widget("Additional package formats")
        extra_vbox.pack_start(label, expand=False, fill=False)

        check_hbox = gtk.HBox(False, 12)
        extra_vbox.pack_start(check_hbox, expand=False, fill=False)
        for format in all_package_format:
            if format != rootfs_format:
                check_button = gtk.CheckButton(format)
                is_active = (format in curr_package_format.split())
                check_button.set_active(is_active)
                check_hbox.pack_start(check_button, expand=False, fill=False)

        info = HobInfoButton(tooltip_extra, self)
        check_hbox.pack_end(info, expand=False, fill=False)

        rootfs_combo.connect("changed", self.rootfs_combo_changed_cb, all_package_format, check_hbox)

        pkgfmt_hbox.show_all()

        return pkgfmt_hbox, rootfs_combo, check_hbox

    def editable_settings_cell_edited(self, cell, path_string, new_text, model):
        it = model.get_iter_from_string(path_string)
        column = cell.get_data("column")
        model.set(it, column, new_text)

    def editable_settings_add_item_clicked(self, button, model):
        new_item = ["##KEY##", "##VALUE##"]

        iter = model.append()
        model.set (iter,
            0, new_item[0],
            1, new_item[1],
       )

    def editable_settings_remove_item_clicked(self, button, treeview):
        selection = treeview.get_selection()
        model, iter = selection.get_selected()

        if iter:
            path = model.get_path(iter)[0]
            model.remove(iter)
 
    def gen_editable_settings(self, setting, tooltip=""):
        setting_hbox = gtk.HBox(False, 12)

        vbox = gtk.VBox(False, 12)
        setting_hbox.pack_start(vbox, expand=True, fill=True)

        setting_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        for key in setting.keys():
            setting_store.set(setting_store.append(), 0, key, 1, setting[key])

        setting_tree = gtk.TreeView(setting_store)
        setting_tree.set_headers_visible(True)
        setting_tree.set_size_request(300, 100)

        col = gtk.TreeViewColumn('Key')
        col.set_min_width(100)
        col.set_max_width(150)
        col.set_resizable(True)
        col1 = gtk.TreeViewColumn('Value')
        col1.set_min_width(100)
        col1.set_max_width(150)
        col1.set_resizable(True)
        setting_tree.append_column(col)
        setting_tree.append_column(col1)
        cell = gtk.CellRendererText()
        cell.set_property('width-chars', 10)
        cell.set_property('editable', True)
        cell.set_data("column", 0)
        cell.connect("edited", self.editable_settings_cell_edited, setting_store)
        cell1 = gtk.CellRendererText()
        cell1.set_property('width-chars', 10)
        cell1.set_property('editable', True)
        cell1.set_data("column", 1)
        cell1.connect("edited", self.editable_settings_cell_edited, setting_store)
        col.pack_start(cell, True)
        col1.pack_end(cell1, True)
        col.set_attributes(cell, text=0)
        col1.set_attributes(cell1, text=1)

        scroll = gtk.ScrolledWindow()
        scroll.set_shadow_type(gtk.SHADOW_IN)
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll.add(setting_tree)
        vbox.pack_start(scroll, expand=True, fill=True)

        # some buttons
        hbox = gtk.HBox(True, 6)
        vbox.pack_start(hbox, False, False)

        button = gtk.Button(stock=gtk.STOCK_ADD)
        button.connect("clicked", self.editable_settings_add_item_clicked, setting_store)
        hbox.pack_start(button)

        button = gtk.Button(stock=gtk.STOCK_REMOVE)
        button.connect("clicked", self.editable_settings_remove_item_clicked, setting_tree)
        hbox.pack_start(button)

        info = HobInfoButton(tooltip, self)
        setting_hbox.pack_start(info, expand=False, fill=False)

        return setting_hbox, setting_store

    def create_others_page(self):
        advanced_vbox = gtk.VBox(False, 6)
        advanced_vbox.set_border_width(6)

        sub_vbox = gtk.VBox(False, 6)
        advanced_vbox.pack_start(sub_vbox, expand=True, fill=True)
        label = self.gen_label_widget("<span weight=\"bold\">Add your own variables:</span>")
        tooltip = "These are key/value pairs for your extra settings. Click \'Add\' and then directly edit the key and the value"
        setting_widget, self.setting_store = self.gen_editable_settings(self.configuration.extra_setting,"<b>Add your own variables</b>" + "*" + tooltip)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(setting_widget, expand=True, fill=True)

        return advanced_vbox

    def create_visual_elements(self):
        self.nb = gtk.Notebook()
        self.nb.set_show_tabs(True)        
        self.nb.append_page(self.create_build_environment_page(), gtk.Label("Build environment"))
        self.nb.append_page(self.create_shared_state_page(), gtk.Label("Shared state"))
        self.nb.append_page(self.create_network_page(), gtk.Label("Network"))        
        self.nb.append_page(self.create_others_page(), gtk.Label("Others"))
        self.nb.set_current_page(0)
        self.vbox.pack_start(self.nb, expand=True, fill=True)
        self.vbox.pack_end(gtk.HSeparator(), expand=True, fill=True)

        self.show_all()

    def destroy(self):
        self.handler.disconnect(self.proxy_test_passed_id)
        self.handler.disconnect(self.proxy_test_failed_id)
        super(SimpleSettingsDialog, self).destroy()
    def create_bottom_buttons(self, buttonlist, image_name):
        # Create the buttons at the bottom
        created = False
        packed = False
        self.button_ids = {}

        # create button "Deploy image"
        name = "Deploy image"
        if name in buttonlist and self.test_deployable(image_name):
            deploy_button = HobButton('Deploy image')
            deploy_button.set_size_request(205, 49)
            deploy_button.set_tooltip_text("Burn a live image to a USB drive or flash memory")
            deploy_button.set_flags(gtk.CAN_DEFAULT)
            button_id = deploy_button.connect("clicked", self.deploy_button_clicked_cb, image_name)
            self.button_ids[button_id] = deploy_button
            self.details_bottom_buttons.pack_end(deploy_button, expand=False, fill=False)
            created = True
            packed = True

        name = "Run image"
        if name in buttonlist and self.test_type_runnable(image_name) and self.test_mach_runnable(image_name):
            if created == True:
                # separator
                label = gtk.Label(" or ")
                self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

                # create button "Run image"
                run_button = HobAltButton("Run image")
            else:
                # create button "Run image" as the primary button
                run_button = HobButton("Run image")
                run_button.set_size_request(205, 49)
                run_button.set_flags(gtk.CAN_DEFAULT)
                packed = True
            run_button.set_tooltip_text("Start up an image with qemu emulator")
            button_id = run_button.connect("clicked", self.run_button_clicked_cb, image_name)
            self.button_ids[button_id] = run_button
            self.details_bottom_buttons.pack_end(run_button, expand=False, fill=False)
            created = True

        if not packed:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.details_bottom_buttons.pack_end(box, False, False)

        name = "Save as template"
        if name in buttonlist:
            if created == True:
                # separator
                label = gtk.Label(" or ")
                self.details_bottom_buttons.pack_end(label, expand=False, fill=False)

            # create button "Save as template"
            save_button = HobAltButton("Save as template")
            save_button.set_tooltip_text("Save the image configuration for reuse")
            button_id = save_button.connect("clicked", self.save_button_clicked_cb)
            self.button_ids[button_id] = save_button
            self.details_bottom_buttons.pack_end(save_button, expand=False, fill=False)
            create = True

        name = "Build new image"
        if name in buttonlist:
            # create button "Build new image"
            build_new_button = HobAltButton("Build new image")
            build_new_button.set_tooltip_text("Create a new image from scratch")
            button_id = build_new_button.connect("clicked", self.build_new_button_clicked_cb)
            self.button_ids[button_id] = build_new_button
            self.details_bottom_buttons.pack_start(build_new_button, expand=False, fill=False)
    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(
            hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build. Check the \"Issues\" tab for more details</span>"
            label.set_markup(markup)
        else:
            label.set_markup(
                "<span size='medium'>Check the \"Issues\" information for more details</span>"
            )
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked',
                              self.failure_primary_action_button_clicked_cb,
                              primary_action)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb,
                                    log_file)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text(
            "Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked',
                                self.failure_activate_file_bug_link_cb)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 13, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, 14, 23, 9, 12)
            build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9,
                                  9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked',
                                  self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, attach_pos,
                                      attach_pos + 9, 9, 12)

        self.builder.disk_full = False
        return build_fail_top
class BuildDetailsPage (HobPage):

    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0,)
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        tooltip = "Cancel build in progress"
        self.stop_button.set_tooltip_text(tooltip)
        self.stop_button.set_sensitive(True)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow ()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)

        self.builder.handler.build.model.connect_after("row-changed", self.scroll_to_present_row, self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('&lt;&lt; Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def reset_build_status(self):
        self.endpath = (0,)

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 40, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build."
            label.set_markup(markup)
            build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked', self.failure_primary_action_button_clicked_cb, primary_action)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 19, 9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked', self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)

        self.builder.disk_full = False
        return build_fail_top

    def show_fail_page(self, title):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(title, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar, expand=False, fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()

    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 40, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked', self.stop_primary_action_button_clicked_cb, action)
        build_stop_tab.attach(action_button, 4, 20, 6, 9)

        build_button = HobAltButton("Build new image")
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, 21, 40, 6, 9)

        return build_stop_top, action_button

    def show_stop_page(self, action):
        self._remove_all_widget()
        self.title = "Build stopped"
        self.build_stop_bar, action_button = self.add_build_stop_top_bar(action, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_stop_bar, expand=False, fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()
        return action_button

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None, padding=15)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.scrolled_view_build, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def new_image_button_clicked_cb(self, button):
        self.builder.populate_recipe_package_info_async()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[0]: # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value == v_adj.upper - v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages(ask=False)
        elif "Edit image" in action:
            self.builder.show_configuration()

    def restart_build_button_clicked_cb(self, button):
        self.builder.just_bake()

    def stop_primary_action_button_clicked_cb(self, button, action):
        if "recipes" in action:
            self.builder.show_recipes()
        elif "packages" in action:
            self.builder.show_packages(ask=False)
        elif "image" in action:
            self.builder.show_configuration()

    def open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
Exemple #50
0
class ImageConfigurationPage(HobPage):
    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder,
                                                     "Image configuration")

        self.image_combo_id = None
        self.custom_image_selected = None
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button=False):
        self._remove_all_widget()
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button,
                                         expand=False,
                                         fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_text(title)
        self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button=False)
        self.set_config_distro_layout(show_progress_bar=True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=True)
        self.set_config_distro_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=True)
        self.set_config_distro_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()

    def create_config_machine(self):
        self.progress_bar = HobProgressBar()

    def set_config_distro_layout(self, show_progress_bar=False):
        if show_progress_bar:
            self.gtable.attach(self.progress_bar, 0, 40, 12, 15)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 0)
        mark = "<span %s>Select an image to build</span>" % self.span_tag(
            'x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo.set_row_separator_func(self.combo_separator_func,
                                                None)
        self.image_combo.set_tooltip_text(
            "Select an image to see a description of it")
        self.image_combo_id = self.image_combo.connect(
            "changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0, 0)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        self.toolchain_checkbox = gtk.CheckButton("Build a matching toolchain")
        self.toolchain_checkbox.set_active(
            self.builder.configuration.toolchain_build)
        tooltip = "Check this box to generate a toolchain installer "
        tooltip += "that contains a sysroot for your selected image"
        self.toolchain_checkbox.set_tooltip_text(tooltip)

    def combo_separator_func(self, model, iter, user_data):
        name = model.get_value(iter, 0)
        if name == "--Separator--":
            return True

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 8, 11)
        self.gtable.attach(self.image_combo, 0, 20, 12, 15)
        self.gtable.attach(self.image_desc, 0, 40, 16, 20)
        self.gtable.attach(self.toolchain_checkbox, 0, 40, 21, 24)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        tooltip = "Build your selected image"
        self.just_bake_button.set_tooltip_text(tooltip)
        self.just_bake_button.connect("clicked",
                                      self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit packages"
        self.edit_image_button = HobAltButton("Edit packages")
        tooltip = "Customize the list of packages to be included in your image"
        self.edit_image_button.set_tooltip_text(tooltip)
        self.edit_image_button.connect("clicked",
                                       self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys(
        ):
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(
                image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes,
                                    selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        if not self.builder.request_pkg_info:
            self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if selected_image:
            self.builder.customized = False

            selected_recipes = []

            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)

            distro = self.builder.parameters.image_list[selected_image]
            self.builder.set_distro_packages(distro)

            selected_packages = self.builder.recipe_model.get_value(
                image_iter, self.builder.recipe_model.COL_INSTALL).split()
            self.update_image_desc()

            self.builder.recipe_model.reset()
            self.builder.package_model.reset()

            self.show_baseimg_selected()

            glib.idle_add(self.image_combo_changed_idle_cb, selected_image,
                          selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect(
                "changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, selected_image):
        model = self.image_combo.get_model()
        model.clear()

        active = 0
        cnt = 0
        for image_name in self.builder.parameters.image_list.keys():
            self.image_combo.append_text(image_name)
            if image_name == selected_image:
                active = cnt
            cnt = cnt + 1
        self.image_combo.set_active(active)

    def update_conf(self):
        self.builder.configuration.toolchain_build = self.toolchain_checkbox.get_active(
        )

    def just_bake_button_clicked_cb(self, button):
        self.update_conf()
        self.builder.build_image()

    def edit_image_button_clicked_cb(self, button):
        self.update_conf()
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_packages(ask=False)
class ImageConfigurationPage (HobPage):

    __dummy_machine__ = "--select a machine--"
    __dummy_image__   = "--select a base image--"

    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder, "Image configuration")

        self.image_combo_id = None
        # we use machine_combo_changed_by_manual to identify the machine is changed by code
        # or by manual. If by manual, all user's recipe selection and package selection are
        # cleared.
        self.machine_combo_changed_by_manual = True
        self.stopping = False
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        template_button = self.append_toolbar_button(self.toolbar,
            "Templates",
            hic.ICON_TEMPLATES_DISPLAY_FILE,
            hic.ICON_TEMPLATES_HOVER_FILE,
            "Load a previously saved template",
            self.template_button_clicked_cb)
        my_images_button = self.append_toolbar_button(self.toolbar,
            "Images",
            hic.ICON_IMAGES_DISPLAY_FILE,
            hic.ICON_IMAGES_HOVER_FILE,
            "Open previously built images",
            self.my_images_button_clicked_cb)
        settings_button = self.append_toolbar_button(self.toolbar,
            "Settings",
            hic.ICON_SETTINGS_DISPLAY_FILE,
            hic.ICON_SETTINGS_HOVER_FILE,
            "View additional build settings",
            self.settings_button_clicked_cb)

        self.config_top_button = self.add_onto_top_bar(self.toolbar)

        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button = False):
        self._remove_all_widget()
        self.pack_start(self.config_top_button, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button, expand=False, fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def show_machine(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = False)
        self.show_all()

    def update_progress_bar(self, title, fraction, status=None):
        if self.stopping == False:
            self.progress_bar.update(fraction)
            self.progress_bar.set_text(title)
            self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = True)
        self.set_config_machine_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()
        if self.builder.recipe_model.get_selected_image() == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

    def create_config_machine(self):
        self.machine_title = gtk.Label()
        self.machine_title.set_alignment(0.0, 0.5)
        mark = "<span %s>Select a machine</span>" % self.span_tag('x-large', 'bold')
        self.machine_title.set_markup(mark)

        self.machine_title_desc = gtk.Label()
        self.machine_title_desc.set_alignment(0.0, 0.5)
        mark = ("<span %s>Your selection is the profile of the target machine for which you"
        " are building the image.\n</span>") % (self.span_tag('medium'))
        self.machine_title_desc.set_markup(mark)

        self.machine_combo = gtk.combo_box_new_text()
        self.machine_combo.connect("changed", self.machine_combo_changed_cb)

        icon_file = hic.ICON_LAYERS_DISPLAY_FILE
        hover_file = hic.ICON_LAYERS_HOVER_FILE
        self.layer_button = HobImageButton("Layers", "Add support for machines, software, etc.",
                                icon_file, hover_file)
        self.layer_button.connect("clicked", self.layer_button_clicked_cb)

        markup = "Layers are a powerful mechanism to extend the Yocto Project "
        markup += "with your own functionality.\n"
        markup += "For more on layers, check the <a href=\""
        markup += "http://www.yoctoproject.org/docs/current/dev-manual/"
        markup += "dev-manual.html#understanding-and-using-layers\">reference manual</a>."
        self.layer_info_icon = HobInfoButton(markup, self.get_parent())

#        self.progress_box = gtk.HBox(False, 6)
        self.progress_bar = HobProgressBar()
#        self.progress_box.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
#        self.progress_box.pack_end(stop_button, expand=False, fill=False)
        self.machine_separator = gtk.HSeparator()

    def set_config_machine_layout(self, show_progress_bar = False):
        self.gtable.attach(self.machine_title, 0, 40, 0, 4)
        self.gtable.attach(self.machine_title_desc, 0, 40, 4, 6)
        self.gtable.attach(self.machine_combo, 0, 12, 7, 10)
        self.gtable.attach(self.layer_button, 14, 36, 7, 12)
        self.gtable.attach(self.layer_info_icon, 36, 40, 7, 11)
        if show_progress_bar:
            #self.gtable.attach(self.progress_box, 0, 40, 15, 18)
            self.gtable.attach(self.progress_bar, 0, 37, 15, 18)
            self.gtable.attach(self.stop_button, 37, 40, 15, 18, 0, 0)
        self.gtable.attach(self.machine_separator, 0, 40, 13, 14)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 1.0)
        mark = "<span %s>Select a base image</span>" % self.span_tag('x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_title_desc = gtk.Label()
        self.image_title_desc.set_alignment(0, 0.5)
        mark = ("<span %s>Base images are a starting point for the type of image you want. "
                "You can build them as \n"
                "they are or customize them to your specific needs.\n</span>") % self.span_tag('medium')
        self.image_title_desc.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0.0, 0.5)
        self.image_desc.set_size_request(256, -1)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        # button to view recipes
        icon_file = hic.ICON_RCIPE_DISPLAY_FILE
        hover_file = hic.ICON_RCIPE_HOVER_FILE
        self.view_adv_configuration_button = HobImageButton("Advanced configuration",
                                                                 "Select image types, package formats, etc",
                                                                 icon_file, hover_file)        
        self.view_adv_configuration_button.connect("clicked", self.view_adv_configuration_button_clicked_cb)

        self.image_separator = gtk.HSeparator()

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 15, 17)
        self.gtable.attach(self.image_title_desc, 0, 40, 18, 22)
        self.gtable.attach(self.image_combo, 0, 12, 23, 26)
        self.gtable.attach(self.image_desc, 0, 12, 27, 33)
        self.gtable.attach(self.view_adv_configuration_button, 14, 36, 23, 28)
        self.gtable.attach(self.image_separator, 0, 40, 35, 36)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        #self.just_bake_button.set_size_request(205, 49)
        self.just_bake_button.set_tooltip_text("Build target image")
        self.just_bake_button.connect("clicked", self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit Image"
        self.edit_image_button = HobAltButton("Edit image")
        #self.edit_image_button.set_size_request(205, 49)
        self.edit_image_button.set_tooltip_text("Edit target image")
        self.edit_image_button.connect("clicked", self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def stop_button_clicked_cb(self, button):
        self.stopping = True
        self.progress_bar.set_text("Stopping recipe parsing")
        self.progress_bar.set_rcstyle("stop")
        self.builder.cancel_parse_sync()

    def machine_combo_changed_cb(self, machine_combo):
        self.stopping = False
        combo_item = machine_combo.get_active_text()
        if not combo_item or combo_item == self.__dummy_machine__:
            return

        # remove __dummy_machine__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = machine_combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_machine__):
            machine_combo.remove_text(0)

        self.builder.configuration.curr_mach = combo_item
        if self.machine_combo_changed_by_manual:
            self.builder.configuration.clear_selection()
        # reset machine_combo_changed_by_manual
        self.machine_combo_changed_by_manual = True

        # Do reparse recipes
        self.builder.populate_recipe_package_info_async()

    def update_machine_combo(self):
        all_machines = [self.__dummy_machine__] + self.builder.parameters.all_machines

        model = self.machine_combo.get_model()
        model.clear()
        for machine in all_machines:
            self.machine_combo.append_text(machine)
        self.machine_combo.set_active(0)

    def switch_machine_combo(self):
        self.machine_combo_changed_by_manual = False
        model = self.machine_combo.get_model()
        active = 0
        while active < len(model):
            if model[active][0] == self.builder.configuration.curr_mach:
                self.machine_combo.set_active(active)
                return
            active += 1

        if model[0][0] != self.__dummy_machine__:
            self.machine_combo.insert_text(0, self.__dummy_machine__)

        self.machine_combo.set_active(0)

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys():
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes, selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if not selected_image or (selected_image == self.__dummy_image__):
            return

        # remove __dummy_image__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_image__):
            combo.remove_text(0)

        self.builder.customized = False

        selected_recipes = []

        image_path = self.builder.recipe_model.pn_path[selected_image]
        image_iter = self.builder.recipe_model.get_iter(image_path)
        selected_packages = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_INSTALL).split()
        self.update_image_desc()

        self.builder.recipe_model.reset()
        self.builder.package_model.reset()

        self.show_baseimg_selected()

        if selected_image == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

        glib.idle_add(self.image_combo_changed_idle_cb, selected_image, selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, recipe_model, selected_image):
        # Update the image combo according to the images in the recipe_model
        # populate image combo
        filter = {RecipeListModel.COL_TYPE : ['image']}
        image_model = recipe_model.tree_model(filter)
        image_model.set_sort_column_id(recipe_model.COL_NAME, gtk.SORT_ASCENDING)
        active = 0
        cnt = 1

        white_pattern = []
        if self.builder.parameters.image_white_pattern:
            for i in self.builder.parameters.image_white_pattern.split():
                white_pattern.append(re.compile(i))

        black_pattern = []
        if self.builder.parameters.image_black_pattern:
            for i in self.builder.parameters.image_black_pattern.split():
                black_pattern.append(re.compile(i))
        black_pattern.append(re.compile("hob-image"))

        it = image_model.get_iter_first()
        self._image_combo_disconnect_signal()
        model = self.image_combo.get_model()
        model.clear()
        # Set a indicator text to combo store when first open
        self.image_combo.append_text(self.__dummy_image__)
        # append and set active
        while it:
            path = image_model.get_path(it)
            it = image_model.iter_next(it)
            image_name = image_model[path][recipe_model.COL_NAME]
            if image_name == self.builder.recipe_model.__custom_image__:
                continue

            if black_pattern:
                allow = True
                for pattern in black_pattern:
                    if pattern.search(image_name):
                        allow = False
                        break
            elif white_pattern:
                allow = False
                for pattern in white_pattern:
                    if pattern.search(image_name):
                        allow = True
                        break
            else:
                allow = True

            if allow:
                self.image_combo.append_text(image_name)
                if image_name == selected_image:
                    active = cnt
                cnt = cnt + 1

        self.image_combo.append_text(self.builder.recipe_model.__custom_image__)
        if selected_image == self.builder.recipe_model.__custom_image__:
            active = cnt

        self.image_combo.set_active(active)

        if active != 0:
            self.show_baseimg_selected()

        self._image_combo_connect_signal()

    def layer_button_clicked_cb(self, button):
        # Create a layer selection dialog
        self.builder.show_layer_selection_dialog()
        
    def view_adv_configuration_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_adv_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()        

    def just_bake_button_clicked_cb(self, button):
        self.builder.just_bake()

    def edit_image_button_clicked_cb(self, button):
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_recipes()

    def template_button_clicked_cb(self, button):
        response, path = self.builder.show_load_template_dialog()
        if not response:
            return
        if path:
            self.builder.load_template(path)

    def my_images_button_clicked_cb(self, button):
        self.builder.show_load_my_images_dialog()

    def settings_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_simple_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()
Exemple #52
0
class ImageConfigurationPage(HobPage):

    __dummy_machine__ = "--select a machine--"
    __dummy_image__ = "--select a base image--"

    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder,
                                                     "Image configuration")

        self.image_combo_id = None
        # we use machine_combo_changed_by_manual to identify the machine is changed by code
        # or by manual. If by manual, all user's recipe selection and package selection are
        # cleared.
        self.machine_combo_changed_by_manual = True
        self.stopping = False
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        template_button = self.append_toolbar_button(
            self.toolbar, "Templates", hic.ICON_TEMPLATES_DISPLAY_FILE,
            hic.ICON_TEMPLATES_HOVER_FILE, "Load a previously saved template",
            self.template_button_clicked_cb)
        my_images_button = self.append_toolbar_button(
            self.toolbar, "Images", hic.ICON_IMAGES_DISPLAY_FILE,
            hic.ICON_IMAGES_HOVER_FILE, "Open previously built images",
            self.my_images_button_clicked_cb)
        settings_button = self.append_toolbar_button(
            self.toolbar, "Settings", hic.ICON_SETTINGS_DISPLAY_FILE,
            hic.ICON_SETTINGS_HOVER_FILE, "View additional build settings",
            self.settings_button_clicked_cb)

        self.config_top_button = self.add_onto_top_bar(self.toolbar)

        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button=False):
        self._remove_all_widget()
        self.pack_start(self.config_top_button, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button,
                                         expand=False,
                                         fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def show_machine(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=False)
        self.show_all()

    def update_progress_bar(self, title, fraction, status=None):
        if self.stopping == False:
            self.progress_bar.update(fraction)
            self.progress_bar.set_text(title)
            self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=False)
        self.set_config_machine_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button=True)
        self.set_config_machine_layout(show_progress_bar=False)
        self.set_config_baseimg_layout()
        self.show_all()
        if self.builder.recipe_model.get_selected_image(
        ) == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

    def create_config_machine(self):
        self.machine_title = gtk.Label()
        self.machine_title.set_alignment(0.0, 0.5)
        mark = "<span %s>Select a machine</span>" % self.span_tag(
            'x-large', 'bold')
        self.machine_title.set_markup(mark)

        self.machine_title_desc = gtk.Label()
        self.machine_title_desc.set_alignment(0.0, 0.5)
        mark = (
            "<span %s>Your selection is the profile of the target machine for which you"
            " are building the image.\n</span>") % (self.span_tag('medium'))
        self.machine_title_desc.set_markup(mark)

        self.machine_combo = gtk.combo_box_new_text()
        self.machine_combo.connect("changed", self.machine_combo_changed_cb)

        icon_file = hic.ICON_LAYERS_DISPLAY_FILE
        hover_file = hic.ICON_LAYERS_HOVER_FILE
        self.layer_button = HobImageButton(
            "Layers", "Add support for machines, software, etc.", icon_file,
            hover_file)
        self.layer_button.connect("clicked", self.layer_button_clicked_cb)

        markup = "Layers are a powerful mechanism to extend the Yocto Project "
        markup += "with your own functionality.\n"
        markup += "For more on layers, check the <a href=\""
        markup += "http://www.yoctoproject.org/docs/current/dev-manual/"
        markup += "dev-manual.html#understanding-and-using-layers\">reference manual</a>."
        self.layer_info_icon = HobInfoButton(markup, self.get_parent())

        #        self.progress_box = gtk.HBox(False, 6)
        self.progress_bar = HobProgressBar()
        #        self.progress_box.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        #        self.progress_box.pack_end(stop_button, expand=False, fill=False)
        self.machine_separator = gtk.HSeparator()

    def set_config_machine_layout(self, show_progress_bar=False):
        self.gtable.attach(self.machine_title, 0, 40, 0, 4)
        self.gtable.attach(self.machine_title_desc, 0, 40, 4, 6)
        self.gtable.attach(self.machine_combo, 0, 12, 7, 10)
        self.gtable.attach(self.layer_button, 14, 36, 7, 12)
        self.gtable.attach(self.layer_info_icon, 36, 40, 7, 11)
        if show_progress_bar:
            #self.gtable.attach(self.progress_box, 0, 40, 15, 18)
            self.gtable.attach(self.progress_bar, 0, 37, 15, 18)
            self.gtable.attach(self.stop_button, 37, 40, 15, 18, 0, 0)
        self.gtable.attach(self.machine_separator, 0, 40, 13, 14)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 1.0)
        mark = "<span %s>Select a base image</span>" % self.span_tag(
            'x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_title_desc = gtk.Label()
        self.image_title_desc.set_alignment(0, 0.5)
        mark = (
            "<span %s>Base images are a starting point for the type of image you want. "
            "You can build them as \n"
            "they are or customize them to your specific needs.\n</span>"
        ) % self.span_tag('medium')
        self.image_title_desc.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo_id = self.image_combo.connect(
            "changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0.0, 0.5)
        self.image_desc.set_size_request(256, -1)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        # button to view recipes
        icon_file = hic.ICON_RCIPE_DISPLAY_FILE
        hover_file = hic.ICON_RCIPE_HOVER_FILE
        self.view_adv_configuration_button = HobImageButton(
            "Advanced configuration",
            "Select image types, package formats, etc", icon_file, hover_file)
        self.view_adv_configuration_button.connect(
            "clicked", self.view_adv_configuration_button_clicked_cb)

        self.image_separator = gtk.HSeparator()

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 15, 17)
        self.gtable.attach(self.image_title_desc, 0, 40, 18, 22)
        self.gtable.attach(self.image_combo, 0, 12, 23, 26)
        self.gtable.attach(self.image_desc, 0, 12, 27, 33)
        self.gtable.attach(self.view_adv_configuration_button, 14, 36, 23, 28)
        self.gtable.attach(self.image_separator, 0, 40, 35, 36)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        #self.just_bake_button.set_size_request(205, 49)
        self.just_bake_button.set_tooltip_text("Build target image")
        self.just_bake_button.connect("clicked",
                                      self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit Image"
        self.edit_image_button = HobAltButton("Edit image")
        #self.edit_image_button.set_size_request(205, 49)
        self.edit_image_button.set_tooltip_text("Edit target image")
        self.edit_image_button.connect("clicked",
                                       self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def stop_button_clicked_cb(self, button):
        self.stopping = True
        self.progress_bar.set_text("Stopping recipe parsing")
        self.progress_bar.set_rcstyle("stop")
        self.builder.cancel_parse_sync()

    def machine_combo_changed_cb(self, machine_combo):
        self.stopping = False
        combo_item = machine_combo.get_active_text()
        if not combo_item or combo_item == self.__dummy_machine__:
            return

        # remove __dummy_machine__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = machine_combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_machine__):
            machine_combo.remove_text(0)

        self.builder.configuration.curr_mach = combo_item
        if self.machine_combo_changed_by_manual:
            self.builder.configuration.clear_selection()
        # reset machine_combo_changed_by_manual
        self.machine_combo_changed_by_manual = True

        # Do reparse recipes
        self.builder.populate_recipe_package_info_async()

    def update_machine_combo(self):
        all_machines = [self.__dummy_machine__
                        ] + self.builder.parameters.all_machines

        model = self.machine_combo.get_model()
        model.clear()
        for machine in all_machines:
            self.machine_combo.append_text(machine)
        self.machine_combo.set_active(0)

    def switch_machine_combo(self):
        self.machine_combo_changed_by_manual = False
        model = self.machine_combo.get_model()
        active = 0
        while active < len(model):
            if model[active][0] == self.builder.configuration.curr_mach:
                self.machine_combo.set_active(active)
                return
            active += 1

        if model[0][0] != self.__dummy_machine__:
            self.machine_combo.insert_text(0, self.__dummy_machine__)

        self.machine_combo.set_active(0)

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys(
        ):
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(
                image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes,
                                    selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if not selected_image or (selected_image == self.__dummy_image__):
            return

        # remove __dummy_image__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_image__):
            combo.remove_text(0)

        self.builder.customized = False

        selected_recipes = []

        image_path = self.builder.recipe_model.pn_path[selected_image]
        image_iter = self.builder.recipe_model.get_iter(image_path)
        selected_packages = self.builder.recipe_model.get_value(
            image_iter, self.builder.recipe_model.COL_INSTALL).split()
        self.update_image_desc()

        self.builder.recipe_model.reset()
        self.builder.package_model.reset()

        self.show_baseimg_selected()

        if selected_image == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

        glib.idle_add(self.image_combo_changed_idle_cb, selected_image,
                      selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect(
                "changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, recipe_model, selected_image):
        # Update the image combo according to the images in the recipe_model
        # populate image combo
        filter = {RecipeListModel.COL_TYPE: ['image']}
        image_model = recipe_model.tree_model(filter)
        image_model.set_sort_column_id(recipe_model.COL_NAME,
                                       gtk.SORT_ASCENDING)
        active = 0
        cnt = 1

        white_pattern = []
        if self.builder.parameters.image_white_pattern:
            for i in self.builder.parameters.image_white_pattern.split():
                white_pattern.append(re.compile(i))

        black_pattern = []
        if self.builder.parameters.image_black_pattern:
            for i in self.builder.parameters.image_black_pattern.split():
                black_pattern.append(re.compile(i))
        black_pattern.append(re.compile("hob-image"))

        it = image_model.get_iter_first()
        self._image_combo_disconnect_signal()
        model = self.image_combo.get_model()
        model.clear()
        # Set a indicator text to combo store when first open
        self.image_combo.append_text(self.__dummy_image__)
        # append and set active
        while it:
            path = image_model.get_path(it)
            it = image_model.iter_next(it)
            image_name = image_model[path][recipe_model.COL_NAME]
            if image_name == self.builder.recipe_model.__custom_image__:
                continue

            if black_pattern:
                allow = True
                for pattern in black_pattern:
                    if pattern.search(image_name):
                        allow = False
                        break
            elif white_pattern:
                allow = False
                for pattern in white_pattern:
                    if pattern.search(image_name):
                        allow = True
                        break
            else:
                allow = True

            if allow:
                self.image_combo.append_text(image_name)
                if image_name == selected_image:
                    active = cnt
                cnt = cnt + 1

        self.image_combo.append_text(
            self.builder.recipe_model.__custom_image__)
        if selected_image == self.builder.recipe_model.__custom_image__:
            active = cnt

        self.image_combo.set_active(active)

        if active != 0:
            self.show_baseimg_selected()

        self._image_combo_connect_signal()

    def layer_button_clicked_cb(self, button):
        # Create a layer selection dialog
        self.builder.show_layer_selection_dialog()

    def view_adv_configuration_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_adv_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()

    def just_bake_button_clicked_cb(self, button):
        self.builder.just_bake()

    def edit_image_button_clicked_cb(self, button):
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_recipes()

    def template_button_clicked_cb(self, button):
        response, path = self.builder.show_load_template_dialog()
        if not response:
            return
        if path:
            self.builder.load_template(path)

    def my_images_button_clicked_cb(self, button):
        self.builder.show_load_my_images_dialog()

    def settings_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_simple_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()
class PackageSelectionPage (HobPage):

    pages = [
        {
         'name'      : 'All packages',
         'tooltip'   : 'All packages that have been built',
         'filter'    : {},
         'search'    : 'Search packages by name',
         'searchtip' : 'Enter a package name to find it',
         'columns'   : [{
                       'col_name' : 'Included',
                       'col_id'   : PackageListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 50,
                       'col_max'  : 50
                      }, {
                       'col_name' : 'Package name',
                       'col_id'   : PackageListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 200,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Size',
                       'col_id'   : PackageListModel.COL_SIZE,
                       'col_style': 'text',
                       'col_min'  : 80,
                       'col_max'  : 80,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Brought in by',
                       'col_id'   : PackageListModel.COL_BINB,
                       'col_style': 'binb',
                       'col_min'  : 150,
                       'col_max'  : 170,
                       'expand'   : 'True'
                      }]
        }
    ]
    
    (INCLUDED,
     ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisible members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        self.label = gtk.Label("Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, padding=15)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = [] # we need to modify table when the dialog is shown

        search_names = []
        search_tips = []
        # append the tab
        page = self.pages[0]
        columns = page['columns']
        name = page['name']
        self.tab = HobViewTable(columns, name)
        search_names.append(page['search'])
        search_tips.append(page['searchtip'])
        self.ins.set_entry(search_names, search_tips)
        self.ins.search.connect("changed", self.search_entry_changed)
        filter = page['filter']
        sort_model = self.package_model.tree_model(filter, initial=True)
        self.tab.set_model(sort_model)
        self.tab.connect("toggled", self.table_toggled_cb, name)
        self.tab.connect("button-release-event", self.button_click_cb)
        self.tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include, filter)
        #self.tab.set_size_request(-1, 350)
        self.ins.append_page(self.tab, page['name'], page['tooltip'])
        self.tables.append(self.tab)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box, expand=False, fill=False)

        self.build_image_button = HobButton('Build image')
        self.build_image_button.set_tooltip_text("Build your image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def search_entry_changed(self, entry):
        text = entry.get_text()
        if self.ins.search_focus:
            self.ins.search_focus = False
        elif self.ins.page_changed:
            self.ins.page_change = False
            self.filter_search(entry)
        elif text not in self.ins.search_names:
            self.filter_search(entry)

    def filter_search(self, entry):
        text = entry.get_text()
        current_tab = 0
        filter = self.pages[current_tab]['filter']
        filter[PackageListModel.COL_NAME] = text
        self.tables[current_tab].set_model(self.package_model.tree_model(filter, search_data=text))
        if self.package_model.filtered_nb == 0:
            if not self.tab.top_bar:
                self.tab.add_no_result_bar(entry)
                self.tab.top_bar.set_no_show_all(True)
            self.tab.top_bar.show()
            self.tab.scroll.hide()
        else:
            if self.tab.top_bar:
                self.tab.top_bar.hide()
            self.tab.scroll.show()
        if entry.get_text() == '':
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, False)
        else:
            entry.set_icon_sensitive(gtk.ENTRY_ICON_SECONDARY, True)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path and col.get_title() != 'Included': # else activation is likely a removal
            properties = {'binb': '' , 'name': '', 'size':'', 'recipe':'', 'files_list':''}
            properties['binb'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_BINB)
            properties['name'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_NAME)
            properties['size'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_SIZE)
            properties['files_list'] = tree_model.get_value(tree_model.get_iter(path), PackageListModel.COL_FLIST)

            self.builder.show_recipe_property_dialog(properties)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            log_file = "file:///" + log_file
            gtk.show_uri(screen=button.get_screen(), uri=log_file, timestamp=0)

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button, expand=False, fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb, log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        selected_pkgs = self.package_model.get_selected_packages()
        show_missing_pkg_dialog = False
        lbl = "<b>Missing important packages</b>\n\nYour list of included "
        lbl = lbl + " packages is missing:\n\n"
        if not ('eglibc' in selected_pkgs or 'uclibc' in selected_pkgs):
            show_missing_pkg_dialog = True
            lbl = lbl + "-A C library (choose eglibc or uclibc)\n\n"
        if not ('bash' in selected_pkgs or 'busybox'  in selected_pkgs):
            show_missing_pkg_dialog = True
            lbl = lbl + "-A shell provider (choose bash or busybox)\n\n"
        if 'initscripts' not in selected_pkgs:
            show_missing_pkg_dialog = True
            lbl = lbl + "-Initialization scripts (choose initscripts)\n\n"

        if show_missing_pkg_dialog:
            dialog = CrumbsMessageDialog(None, lbl, gtk.STOCK_DIALOG_INFO)
            button = dialog.add_button("Build anyway", gtk.RESPONSE_OK)
            tooltip = "Build the image without changing the included packages"
            button.set_tooltip_text(tooltip)
            HobButton.style_button(button)
            button = dialog.add_button("Edit packages", gtk.RESPONSE_CANCEL)
            tooltip = "Change the list of included packages"
            button.set_tooltip_text(tooltip)
            HobButton.style_button(button)
            response = dialog.run()
            dialog.destroy()
            if response == gtk.RESPONSE_CANCEL:
                return
        self.builder.build_image()

    def refresh_tables(self):
        self.ins.reset_entry(self.ins.search, 0)
        for tab in self.tables:
            index = self.tables.index(tab)
            filter = self.pages[index]['filter']
            tab.set_model(self.package_model.tree_model(filter, initial=True))

    def back_button_clicked_cb(self, button):
        self.builder.restore_initial_selected_packages()
        self.refresh_selection()
        self.ins.search.set_text("")
        self.builder.recipe_model.set_selected_image(self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_combo(self.builder.configuration.initial_selected_image)
        self.builder.image_configuration_page.update_image_desc()
        self.builder.show_configuration()
        self.refresh_tables()

    def refresh_selection(self):
        self.builder.configuration.selected_packages = self.package_model.get_selected_packages()
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages()
        selected_packages_num = len(self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(selected_packages_size)

        self.label.set_label("Packages included: %s   Selected packages size: %s" %
                            (selected_packages_num, selected_packages_size_str))

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path, binb="User Selected")
        else:
            self.pre_fadeout_checkout_include(view_tree)
            self.package_model.exclude_item(item_path=path)
            self.render_fadeout(view_tree, cell)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)
        view_model = view_tree.get_model()
        vpath = self.package_model.convert_path_to_vpath(view_model, path)
        view_tree.set_cursor(vpath)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree):
        #after the fadeout the table will be sorted as before
        self.sort_column_id = self.package_model.sort_column_id
        self.sort_order = self.package_model.sort_order

        self.package_model.resync_fadeout_column(self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = { PackageListModel.COL_FADE_INC  : [True]}
        new_model = self.package_model.tree_model(filter, excluded_items_ahead=True)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model, model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model, view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree, filter):
        self.package_model.sort_column_id = self.sort_column_id
        self.package_model.sort_order = self.sort_order
        tree.set_model(self.package_model.tree_model(filter))
        tree.expand_all()
Exemple #54
0
class RecipeSelectionPage (HobPage):
    pages = [
        {
         'name'    : 'Included recipes',
         'tooltip' : 'The recipes currently included for your image',
         'filter'  : { RecipeListModel.COL_INC  : [True],
                       RecipeListModel.COL_TYPE : ['recipe', 'packagegroup'] },
         'columns' : [{
                       'col_name' : 'Recipe name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Group',
                       'col_id'   : RecipeListModel.COL_GROUP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 300,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Brought in by',
                       'col_id'   : RecipeListModel.COL_BINB,
                       'col_style': 'binb',
                       'col_min'  : 100,
                       'col_max'  : 500,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }, {
         'name'    : 'All recipes',
         'tooltip' : 'All recipes in your configured layers',
         'filter'  : { RecipeListModel.COL_TYPE : ['recipe'] },
         'columns' : [{
                       'col_name' : 'Recipe name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Group',
                       'col_id'   : RecipeListModel.COL_GROUP,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'License',
                       'col_id'   : RecipeListModel.COL_LIC,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }, {
         'name'    : 'Package Groups',
         'tooltip' : 'All package groups in your configured layers',
         'filter'  : { RecipeListModel.COL_TYPE : ['packagegroup'] },
         'columns' : [{
                       'col_name' : 'Package group name',
                       'col_id'   : RecipeListModel.COL_NAME,
                       'col_style': 'text',
                       'col_min'  : 100,
                       'col_max'  : 400,
                       'expand'   : 'True'
                      }, {
                       'col_name' : 'Included',
                       'col_id'   : RecipeListModel.COL_INC,
                       'col_style': 'check toggle',
                       'col_min'  : 100,
                       'col_max'  : 100
                      }]
        }
    ]
    
    (INCLUDED,
     ALL,
     TASKS) = range(3)

    def __init__(self, builder = None):
        super(RecipeSelectionPage, self).__init__(builder, "Step 1 of 2: Edit recipes")

        # set invisible members
        self.recipe_model = self.builder.recipe_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.eventbox = self.add_onto_top_bar(None, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = [] # we need modify table when the dialog is shown
        # append the tabs in order
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            filter = page['filter']
            tab.set_model(self.recipe_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            if page['name'] == "Included recipes":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped", self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry("Search recipes:")
        # set the search entry for each table
        for tab in self.tables:
            search_tip = "Enter a recipe's or task's name to find it"
            self.ins.search.set_tooltip_text(search_tip)
            self.ins.search.props.has_tooltip = True
            tab.set_search_entry(0, self.ins.search)

        # add all into the window
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_end(button_box, expand=False, fill=False)

        self.build_packages_button = HobButton('Build packages')
        #self.build_packages_button.set_size_request(205, 49)
        self.build_packages_button.set_tooltip_text("Build selected recipes into packages")
        self.build_packages_button.set_flags(gtk.CAN_DEFAULT)
        self.build_packages_button.grab_default()
        self.build_packages_button.connect("clicked", self.build_packages_clicked_cb)
        button_box.pack_end(self.build_packages_button, expand=False, fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        button_box.pack_end(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path: # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path), RecipeListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def build_packages_clicked_cb(self, button):
        self.builder.build_packages()

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def refresh_selection(self):
        self.builder.configuration.selected_image = self.recipe_model.get_selected_image()
        _, self.builder.configuration.selected_recipes = self.recipe_model.get_selected_recipes()
        self.ins.show_indicator_icon("Included recipes", len(self.builder.configuration.selected_recipes))

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.recipe_model.path_included(path):
            self.recipe_model.include_item(item_path=path, binb="User Selected", image_contents=False)
        else:
            if pagename == "Included recipes":
                self.pre_fadeout_checkout_include(view_tree)
                self.recipe_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.recipe_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid, view_tree, pagename):
        # Click to include a recipe
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.recipe_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell, pagename)

    def pre_fadeout_checkout_include(self, tree):
        #resync the included items to a backup fade include column
        it = self.recipe_model.get_iter_first()
        while it:
            active = self.recipe_model.get_value(it, self.recipe_model.COL_INC)
            self.recipe_model.set(it, self.recipe_model.COL_FADE_INC, active)
            it = self.recipe_model.iter_next(it)
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = { RecipeListModel.COL_FADE_INC  : [True],
                   RecipeListModel.COL_TYPE      : ['recipe', 'packagegroup'] }
        new_model = self.recipe_model.tree_model(filter, excluded_items_ahead=True)
        tree.set_model(new_model)

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        model = tree.get_model()
        it = model.get_iter_first()
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(it, RecipeListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, RecipeListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active == False):
                to_render_cells.append(path)
            it = model.iter_next(it)

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.recipe_model.tree_model(self.pages[0]['filter']))

    def set_recipe_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
Exemple #55
0
class PackageSelectionPage(HobPage):

    pages = [{
        'name':
        'Included packages',
        'tooltip':
        'The packages currently included for your image',
        'filter': {
            PackageListModel.COL_INC: [True]
        },
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 300,
            'expand': 'True'
        }, {
            'col_name': 'Brought in by (+others)',
            'col_id': PackageListModel.COL_BINB,
            'col_style': 'binb',
            'col_min': 100,
            'col_max': 350,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }, {
        'name':
        'All packages',
        'tooltip':
        'All packages that have been built',
        'filter': {},
        'columns': [{
            'col_name': 'Package name',
            'col_id': PackageListModel.COL_NAME,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 400,
            'expand': 'True'
        }, {
            'col_name': 'Size',
            'col_id': PackageListModel.COL_SIZE,
            'col_style': 'text',
            'col_min': 100,
            'col_max': 500,
            'expand': 'True'
        }, {
            'col_name': 'Included',
            'col_id': PackageListModel.COL_INC,
            'col_style': 'check toggle',
            'col_min': 100,
            'col_max': 100
        }]
    }]

    (INCLUDED, ALL) = range(2)

    def __init__(self, builder):
        super(PackageSelectionPage, self).__init__(builder, "Edit packages")

        # set invisiable members
        self.recipe_model = self.builder.recipe_model
        self.package_model = self.builder.package_model

        # create visual elements
        self.create_visual_elements()

    def included_clicked_cb(self, button):
        self.ins.set_current_page(self.INCLUDED)

    def create_visual_elements(self):
        self.label = gtk.Label(
            "Packages included: 0\nSelected packages size: 0 MB")
        self.eventbox = self.add_onto_top_bar(self.label, 73)
        self.pack_start(self.eventbox, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        # set visible members
        self.ins = HobNotebook()
        self.tables = []  # we need to modify table when the dialog is shown
        # append the tab
        for page in self.pages:
            columns = page['columns']
            tab = HobViewTable(columns)
            filter = page['filter']
            tab.set_model(self.package_model.tree_model(filter))
            tab.connect("toggled", self.table_toggled_cb, page['name'])
            if page['name'] == "Included packages":
                tab.connect("button-release-event", self.button_click_cb)
                tab.connect("cell-fadeinout-stopped",
                            self.after_fadeout_checkin_include)
            self.ins.append_page(tab, page['name'], page['tooltip'])
            self.tables.append(tab)

        self.ins.set_entry("Search packages:")
        # set the search entry for each table
        for tab in self.tables:
            search_tip = "Enter a package name to find it"
            self.ins.search.set_tooltip_text(search_tip)
            self.ins.search.props.has_tooltip = True
            tab.set_search_entry(0, self.ins.search)

        # add all into the dialog
        self.box_group_area.pack_start(self.ins, expand=True, fill=True)

        self.button_box = gtk.HBox(False, 6)
        self.box_group_area.pack_start(self.button_box,
                                       expand=False,
                                       fill=False)

        self.build_image_button = HobButton('Build image')
        #self.build_image_button.set_size_request(205, 49)
        self.build_image_button.set_tooltip_text("Build target image")
        self.build_image_button.set_flags(gtk.CAN_DEFAULT)
        self.build_image_button.grab_default()
        self.build_image_button.connect("clicked", self.build_image_clicked_cb)
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)

        self.back_button = HobAltButton('Cancel')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)

    def button_click_cb(self, widget, event):
        path, col = widget.table_tree.get_cursor()
        tree_model = widget.table_tree.get_model()
        if path:  # else activation is likely a removal
            binb = tree_model.get_value(tree_model.get_iter(path),
                                        PackageListModel.COL_BINB)
            if binb:
                self.builder.show_binb_dialog(binb)

    def open_log_clicked_cb(self, button, log_file):
        if log_file:
            self.stop = False
            dialog = OpeningLogDialog(title="Opening Log",
                                      parent=None,
                                      flags=gtk.DIALOG_MODAL
                                      | gtk.DIALOG_DESTROY_WITH_PARENT
                                      | gtk.DIALOG_NO_SEPARATOR)
            #create a thread to open log file
            background = OpeningLogThread(dialog, log_file, self)
            background.start()
            response = dialog.run()
            self.stop = True
            background.join()

    def show_page(self, log_file):
        children = self.button_box.get_children() or []
        for child in children:
            self.button_box.remove(child)
        # re-packed the buttons as request, add the 'open log' button if build success
        self.button_box.pack_end(self.build_image_button,
                                 expand=False,
                                 fill=False)
        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.connect("clicked", self.open_log_clicked_cb,
                                    log_file)
            open_log_button.set_tooltip_text("Open the build's log file")
            self.button_box.pack_end(open_log_button, expand=False, fill=False)
        self.button_box.pack_end(self.back_button, expand=False, fill=False)
        self.show_all()

    def build_image_clicked_cb(self, button):
        self.builder.build_image()

    def back_button_clicked_cb(self, button):
        if self.builder.previous_step == self.builder.IMAGE_GENERATED:
            self.builder.restore_initial_selected_packages()
            self.refresh_selection()
            self.builder.show_image_details()
        else:
            self.builder.show_configuration()

    def _expand_all(self):
        for tab in self.tables:
            tab.table_tree.expand_all()

    def refresh_selection(self):
        self._expand_all()

        self.builder.configuration.selected_packages = self.package_model.get_selected_packages(
        )
        self.builder.configuration.user_selected_packages = self.package_model.get_user_selected_packages(
        )
        selected_packages_num = len(
            self.builder.configuration.selected_packages)
        selected_packages_size = self.package_model.get_packages_size()
        selected_packages_size_str = HobPage._size_to_string(
            selected_packages_size)

        image_overhead_factor = self.builder.configuration.image_overhead_factor
        image_rootfs_size = self.builder.configuration.image_rootfs_size / 1024  # image_rootfs_size is KB
        image_extra_size = self.builder.configuration.image_extra_size / 1024  # image_extra_size is KB
        base_size = image_overhead_factor * selected_packages_size
        image_total_size = max(base_size, image_rootfs_size) + image_extra_size
        if "zypper" in self.builder.configuration.selected_packages:
            image_total_size += (51200 * 1024)
        image_total_size_str = HobPage._size_to_string(image_total_size)

        self.label.set_label(
            "Packages included: %s\nSelected packages size: %s\nTotal image size: %s"
            % (selected_packages_num, selected_packages_size_str,
               image_total_size_str))
        self.ins.show_indicator_icon("Included packages",
                                     selected_packages_num)

    def toggle_item_idle_cb(self, path, view_tree, cell, pagename):
        if not self.package_model.path_included(path):
            self.package_model.include_item(item_path=path,
                                            binb="User Selected")
        else:
            if pagename == "Included packages":
                self.pre_fadeout_checkout_include(view_tree)
                self.package_model.exclude_item(item_path=path)
                self.render_fadeout(view_tree, cell)
            else:
                self.package_model.exclude_item(item_path=path)

        self.refresh_selection()
        if not self.builder.customized:
            self.builder.customized = True
            self.builder.configuration.selected_image = self.recipe_model.__custom_image__
            self.builder.rcppkglist_populated()

        self.builder.window_sensitive(True)

    def table_toggled_cb(self, table, cell, view_path, toggled_columnid,
                         view_tree, pagename):
        # Click to include a package
        self.builder.window_sensitive(False)
        view_model = view_tree.get_model()
        path = self.package_model.convert_vpath_to_path(view_model, view_path)
        glib.idle_add(self.toggle_item_idle_cb, path, view_tree, cell,
                      pagename)

    def pre_fadeout_checkout_include(self, tree):
        self.package_model.resync_fadeout_column(
            self.package_model.get_iter_first())
        # Check out a model which base on the column COL_FADE_INC,
        # it's save the prev state of column COL_INC before do exclude_item
        filter = {PackageListModel.COL_FADE_INC: [True]}
        new_model = self.package_model.tree_model(filter)
        tree.set_model(new_model)
        tree.expand_all()

    def get_excluded_rows(self, to_render_cells, model, it):
        while it:
            path = model.get_path(it)
            prev_cell_is_active = model.get_value(
                it, PackageListModel.COL_FADE_INC)
            curr_cell_is_active = model.get_value(it, PackageListModel.COL_INC)
            if (prev_cell_is_active == True) and (curr_cell_is_active
                                                  == False):
                to_render_cells.append(path)
            if model.iter_has_child(it):
                self.get_excluded_rows(to_render_cells, model,
                                       model.iter_children(it))
            it = model.iter_next(it)

        return to_render_cells

    def render_fadeout(self, tree, cell):
        if (not cell) or (not tree):
            return
        to_render_cells = []
        view_model = tree.get_model()
        self.get_excluded_rows(to_render_cells, view_model,
                               view_model.get_iter_first())

        cell.fadeout(tree, 1000, to_render_cells)

    def after_fadeout_checkin_include(self, table, ctrl, cell, tree):
        tree.set_model(self.package_model.tree_model(self.pages[0]['filter']))
        tree.expand_all()

    def set_packages_curr_tab(self, curr_page):
        self.ins.set_current_page(curr_page)
class BuildDetailsPage (HobPage):

    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0,)
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n") # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status, expand=False, fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow ()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config, "Build configuration")

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow ()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, "Issues")

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow ()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, "Log")

        self.builder.handler.build.model.connect_after("row-changed", self.scroll_to_present_row, self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton('&lt;&lt; Back')
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n") # to ensure layout is correct
        self.endpath = (0,)

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def add_build_fail_top_bar(self, actions, log_file=None):
        primary_action = "Edit %s" % actions

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        #build_fail_top.set_size_request(-1, 200)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(14, 46, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_fail_tab.attach(label, 4, 26, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        # Ensure variable disk_full is defined
        if not hasattr(self.builder, 'disk_full'):
            self.builder.disk_full = False

        if self.builder.disk_full:
            markup = "<span size='medium'>There is no disk space left, so Hob cannot finish building your image. Free up some disk space\n"
            markup += "and restart the build. Check the \"Issues\" tab for more details</span>"
            label.set_markup(markup)
        else:
            label.set_markup("<span size='medium'>Check the \"Issues\" information for more details</span>")
        build_fail_tab.attach(label, 4, 40, 4, 9)

        # create button 'Edit packages'
        action_button = HobButton(primary_action)
        #action_button.set_size_request(-1, 40)
        action_button.set_tooltip_text("Edit the %s parameters" % actions)
        action_button.connect('clicked', self.failure_primary_action_button_clicked_cb, primary_action)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb, log_file)

        attach_pos = (24 if log_file else 14)
        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_relief(gtk.RELIEF_HALF)
        file_bug_button.set_tooltip_text("Open the Yocto Project bug tracking website")
        file_bug_button.connect('clicked', self.failure_activate_file_bug_link_cb)

        if not self.builder.disk_full:
            build_fail_tab.attach(action_button, 4, 13, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, 14, 23, 9, 12)
            build_fail_tab.attach(file_bug_button, attach_pos, attach_pos + 9, 9, 12)

        else:
            restart_build = HobButton("Restart the build")
            restart_build.set_tooltip_text("Restart the build")
            restart_build.connect('clicked', self.restart_build_button_clicked_cb)

            build_fail_tab.attach(restart_build, 4, 13, 9, 12)
            build_fail_tab.attach(action_button, 14, 23, 9, 12)
            if log_file:
                build_fail_tab.attach(open_log_button, attach_pos, attach_pos + 9, 9, 12)

        self.builder.disk_full = False
        return build_fail_top

    def show_fail_page(self, title):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(title, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_fail_bar, expand=False, fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)
        self.show_all()
        self.notebook.set_page("Issues")
        self.back_button.hide()

    def add_build_stop_top_bar(self, action, log_file=None):
        color = HobColors.LIGHT_GRAY
        build_stop_top = gtk.EventBox()
        #build_stop_top.set_size_request(-1, 200)
        build_stop_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        build_stop_top.set_flags(gtk.CAN_DEFAULT)
        build_stop_top.grab_default()

        build_stop_tab = gtk.Table(11, 46, True)
        build_stop_top.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INFO_HOVER_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 1, 4, 0, 6)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'><b>%s</b></span>" % self.title)
        build_stop_tab.attach(label, 4, 26, 0, 6)

        action_button = HobButton("Edit %s" % action)
        action_button.set_size_request(-1, 40)
        if action == "image":
            action_button.set_tooltip_text("Edit the image parameters")
        elif action == "recipes":
            action_button.set_tooltip_text("Edit the included recipes")
        elif action == "packages":
            action_button.set_tooltip_text("Edit the included packages")
        action_button.connect('clicked', self.stop_primary_action_button_clicked_cb, action)
        build_stop_tab.attach(action_button, 4, 13, 6, 9)

        if log_file:
            open_log_button = HobAltButton("Open log")
            open_log_button.set_relief(gtk.RELIEF_HALF)
            open_log_button.set_tooltip_text("Open the build's log file")
            open_log_button.connect('clicked', self.open_log_button_clicked_cb, log_file)
            build_stop_tab.attach(open_log_button, 14, 23, 6, 9)

        attach_pos = (24 if log_file else 14)
        build_button = HobAltButton("Build new image")
        #build_button.set_size_request(-1, 40)
        build_button.set_tooltip_text("Create a new image from scratch")
        build_button.connect('clicked', self.new_image_button_clicked_cb)
        build_stop_tab.attach(build_button, attach_pos, attach_pos + 9, 6, 9)

        return build_stop_top, action_button

    def show_stop_page(self, action):
        self._remove_all_widget()
        self.title = "Build stopped"
        self.build_stop_bar, action_button = self.add_build_stop_top_bar(action, self.builder.current_logfile)

        self.pack_start(self.group_align, expand=True, fill=True)
        self.box_group_area.pack_start(self.build_stop_bar, expand=False, fill=False)
        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)
        self.show_all()
        self.back_button.hide()
        return action_button

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.notebook.set_page("Log")
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def new_image_button_clicked_cb(self, button):
        self.builder.reset()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[0]: # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value == v_adj.upper - v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)

    def failure_primary_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages()
        elif "Edit image" in action:
            self.builder.show_configuration()

    def restart_build_button_clicked_cb(self, button):
        self.builder.just_bake()

    def stop_primary_action_button_clicked_cb(self, button, action):
        if "recipes" in action:
            self.builder.show_recipes()
        elif "packages" in action:
            self.builder.show_packages(ask=False)
        elif "image" in action:
            self.builder.show_configuration()

    def open_log_button_clicked_cb(self, button, log_file):
        if log_file:
            self.stop = False
            dialog = OpeningLogDialog(title = "Opening Log",
                parent = None,
                flags = gtk.DIALOG_MODAL
                        | gtk.DIALOG_DESTROY_WITH_PARENT
                        | gtk.DIALOG_NO_SEPARATOR)
            #create a thread to open log file
            background = OpeningLogThread(dialog, log_file, self)
            background.start()
            response = dialog.run()
            self.stop = True
            background.join()

    def failure_activate_file_bug_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")
class ImageConfigurationPage (HobPage):

    __dummy_machine__ = "--select a machine--"
    __dummy_image__   = "--select an image recipe--"
    __custom_image__  = "Select from my image recipes"

    def __init__(self, builder):
        super(ImageConfigurationPage, self).__init__(builder, "Image configuration")

        self.image_combo_id = None
        # we use machine_combo_changed_by_manual to identify the machine is changed by code
        # or by manual. If by manual, all user's recipe selection and package selection are
        # cleared.
        self.machine_combo_changed_by_manual = True
        self.stopping = False
        self.warning_shift = 0
        self.custom_image_selected = None
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        my_images_button = self.append_toolbar_button(self.toolbar,
            "Images",
            hic.ICON_IMAGES_DISPLAY_FILE,
            hic.ICON_IMAGES_HOVER_FILE,
            "Open previously built images",
            self.my_images_button_clicked_cb)
        settings_button = self.append_toolbar_button(self.toolbar,
            "Settings",
            hic.ICON_SETTINGS_DISPLAY_FILE,
            hic.ICON_SETTINGS_HOVER_FILE,
            "View additional build settings",
            self.settings_button_clicked_cb)

        self.config_top_button = self.add_onto_top_bar(self.toolbar)

        self.gtable = gtk.Table(40, 40, True)
        self.create_config_machine()
        self.create_config_baseimg()
        self.config_build_button = self.create_config_build_button()

    def _remove_all_widget(self):
        children = self.gtable.get_children() or []
        for child in children:
            self.gtable.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def _pack_components(self, pack_config_build_button = False):
        self._remove_all_widget()
        self.pack_start(self.config_top_button, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.gtable, expand=True, fill=True)
        if pack_config_build_button:
            self.box_group_area.pack_end(self.config_build_button, expand=False, fill=False)
        else:
            box = gtk.HBox(False, 6)
            box.show()
            subbox = gtk.HBox(False, 0)
            subbox.set_size_request(205, 49)
            subbox.show()
            box.add(subbox)
            self.box_group_area.pack_end(box, False, False)

    def show_machine(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = False)
        self.show_all()

    def update_progress_bar(self, title, fraction, status=None):
        if self.stopping == False:
            self.progress_bar.update(fraction)
            self.progress_bar.set_text(title)
            self.progress_bar.set_rcstyle(status)

    def show_info_populating(self):
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = True)
        self.show_all()

    def show_info_populated(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = False)
        self.set_config_machine_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()

    def show_baseimg_selected(self):
        self.progress_bar.reset()
        self._pack_components(pack_config_build_button = True)
        self.set_config_machine_layout(show_progress_bar = False)
        self.set_config_baseimg_layout()
        self.show_all()
        if self.builder.recipe_model.get_selected_image() == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

    def add_warnings_bar(self):
        #create the warnings bar shown when recipes parsing generates warnings
        color = HobColors.KHAKI
        warnings_bar = gtk.EventBox()
        warnings_bar.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
        warnings_bar.set_flags(gtk.CAN_DEFAULT)
        warnings_bar.grab_default()

        build_stop_tab = gtk.Table(10, 20, True)
        warnings_bar.add(build_stop_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ALERT_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_stop_tab.attach(icon, 0, 2, 0, 10)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        warnings_nb = len(self.builder.parsing_warnings)
        if warnings_nb == 1:
            label.set_markup("<span size='x-large'><b>1 recipe parsing warning</b></span>")
        else:
            label.set_markup("<span size='x-large'><b>%s recipe parsing warnings</b></span>" % warnings_nb)
        build_stop_tab.attach(label, 2, 12, 0, 10)

        view_warnings_button = HobButton("View warnings")
        view_warnings_button.connect('clicked', self.view_warnings_button_clicked_cb)
        build_stop_tab.attach(view_warnings_button, 15, 19, 1, 9)

        return warnings_bar

    def disable_warnings_bar(self):
        if self.builder.parsing_warnings:
            if hasattr(self, 'warnings_bar'):
                self.warnings_bar.hide_all()
            self.builder.parsing_warnings = []

    def create_config_machine(self):
        self.machine_title = gtk.Label()
        self.machine_title.set_alignment(0.0, 0.5)
        mark = "<span %s>Select a machine</span>" % self.span_tag('x-large', 'bold')
        self.machine_title.set_markup(mark)

        self.machine_title_desc = gtk.Label()
        self.machine_title_desc.set_alignment(0.0, 0.5)
        mark = ("<span %s>Your selection is the profile of the target machine for which you"
        " are building the image.\n</span>") % (self.span_tag('medium'))
        self.machine_title_desc.set_markup(mark)

        self.machine_combo = gtk.combo_box_new_text()
        self.machine_combo.connect("changed", self.machine_combo_changed_cb)

        icon_file = hic.ICON_LAYERS_DISPLAY_FILE
        hover_file = hic.ICON_LAYERS_HOVER_FILE
        self.layer_button = HobImageButton("Layers", "Add support for machines, software, etc.",
                                icon_file, hover_file)
        self.layer_button.connect("clicked", self.layer_button_clicked_cb)

        markup = "Layers are a powerful mechanism to extend the Yocto Project "
        markup += "with your own functionality.\n"
        markup += "For more on layers, check the <a href=\""
        markup += "http://www.yoctoproject.org/docs/current/dev-manual/"
        markup += "dev-manual.html#understanding-and-using-layers\">reference manual</a>."
        self.layer_info_icon = HobInfoButton("<b>Layers</b>" + "*" + markup, self.get_parent())
        self.progress_bar = HobProgressBar()
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.machine_separator = gtk.HSeparator()

    def set_config_machine_layout(self, show_progress_bar = False):
        self.gtable.attach(self.machine_title, 0, 40, 0, 4)
        self.gtable.attach(self.machine_title_desc, 0, 40, 4, 6)
        self.gtable.attach(self.machine_combo, 0, 12, 7, 10)
        self.gtable.attach(self.layer_button, 14, 36, 7, 12)
        self.gtable.attach(self.layer_info_icon, 36, 40, 7, 11)
        if show_progress_bar:
            #self.gtable.attach(self.progress_box, 0, 40, 15, 18)
            self.gtable.attach(self.progress_bar, 0, 37, 15, 18)
            self.gtable.attach(self.stop_button, 37, 40, 15, 18, 0, 0)
        if self.builder.parsing_warnings:
            self.warnings_bar = self.add_warnings_bar()
            self.gtable.attach(self.warnings_bar, 0, 40, 14, 18)
            self.warning_shift = 4
        else:
            self.warning_shift = 0
        self.gtable.attach(self.machine_separator, 0, 40, 13, 14)

    def create_config_baseimg(self):
        self.image_title = gtk.Label()
        self.image_title.set_alignment(0, 1.0)
        mark = "<span %s>Select an image recipe</span>" % self.span_tag('x-large', 'bold')
        self.image_title.set_markup(mark)

        self.image_title_desc = gtk.Label()
        self.image_title_desc.set_alignment(0, 0.5)

        mark = ("<span %s>Image recipes are a starting point for the type of image you want. "
                "You can build them as \n"
                "they are or edit them to suit your needs.\n</span>") % self.span_tag('medium')
        self.image_title_desc.set_markup(mark)

        self.image_combo = gtk.combo_box_new_text()
        self.image_combo.set_row_separator_func(self.combo_separator_func, None)
        self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

        self.image_desc = gtk.Label()
        self.image_desc.set_alignment(0.0, 0.5)
        self.image_desc.set_size_request(256, -1)
        self.image_desc.set_justify(gtk.JUSTIFY_LEFT)
        self.image_desc.set_line_wrap(True)

        # button to view recipes
        icon_file = hic.ICON_RCIPE_DISPLAY_FILE
        hover_file = hic.ICON_RCIPE_HOVER_FILE
        self.view_adv_configuration_button = HobImageButton("Advanced configuration",
                                                                 "Select image types, package formats, etc",
                                                                 icon_file, hover_file)        
        self.view_adv_configuration_button.connect("clicked", self.view_adv_configuration_button_clicked_cb)

        self.image_separator = gtk.HSeparator()

    def combo_separator_func(self, model, iter, user_data):
        name = model.get_value(iter, 0)
        if name == "--Separator--":
            return True

    def set_config_baseimg_layout(self):
        self.gtable.attach(self.image_title, 0, 40, 15+self.warning_shift, 17+self.warning_shift)
        self.gtable.attach(self.image_title_desc, 0, 40, 18+self.warning_shift, 22+self.warning_shift)
        self.gtable.attach(self.image_combo, 0, 12, 23+self.warning_shift, 26+self.warning_shift)
        self.gtable.attach(self.image_desc, 0, 12, 27+self.warning_shift, 33+self.warning_shift)
        self.gtable.attach(self.view_adv_configuration_button, 14, 36, 23+self.warning_shift, 28+self.warning_shift)
        self.gtable.attach(self.image_separator, 0, 40, 35+self.warning_shift, 36+self.warning_shift)

    def create_config_build_button(self):
        # Create the "Build packages" and "Build image" buttons at the bottom
        button_box = gtk.HBox(False, 6)

        # create button "Build image"
        self.just_bake_button = HobButton("Build image")
        self.just_bake_button.set_tooltip_text("Build the image recipe as it is")
        self.just_bake_button.connect("clicked", self.just_bake_button_clicked_cb)
        button_box.pack_end(self.just_bake_button, expand=False, fill=False)

        # create button "Edit image recipe"
        self.edit_image_button = HobAltButton("Edit image recipe")
        self.edit_image_button.set_tooltip_text("Customize the recipes and packages to be included in your image")
        self.edit_image_button.connect("clicked", self.edit_image_button_clicked_cb)
        button_box.pack_end(self.edit_image_button, expand=False, fill=False)

        return button_box

    def stop_button_clicked_cb(self, button):
        self.stopping = True
        self.progress_bar.set_text("Stopping recipe parsing")
        self.progress_bar.set_rcstyle("stop")
        self.builder.cancel_parse_sync()

    def view_warnings_button_clicked_cb(self, button):
        self.builder.show_warning_dialog()

    def machine_combo_changed_idle_cb(self):
        self.builder.window.set_cursor(None)

    def machine_combo_changed_cb(self, machine_combo):
        self.builder.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
        self.builder.wait(0.1) #wait for combo and cursor to update
        self.stopping = False
        self.builder.parsing_warnings = []
        combo_item = machine_combo.get_active_text()
        if not combo_item or combo_item == self.__dummy_machine__:
            return

        # remove __dummy_machine__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = machine_combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_machine__):
            machine_combo.remove_text(0)

        self.builder.configuration.curr_mach = combo_item
        if self.machine_combo_changed_by_manual:
            self.builder.configuration.clear_selection()
        # reset machine_combo_changed_by_manual
        self.machine_combo_changed_by_manual = True

        self.builder.configuration.selected_image = None

        # Do reparse recipes
        self.builder.populate_recipe_package_info_async()

        glib.idle_add(self.machine_combo_changed_idle_cb)

    def update_machine_combo(self):
        self.disable_warnings_bar()
        all_machines = [self.__dummy_machine__] + self.builder.parameters.all_machines

        model = self.machine_combo.get_model()
        model.clear()
        for machine in all_machines:
            self.machine_combo.append_text(machine)
        self.machine_combo.set_active(0)

    def switch_machine_combo(self):
        self.disable_warnings_bar()
        self.machine_combo_changed_by_manual = False
        model = self.machine_combo.get_model()
        active = 0
        while active < len(model):
            if model[active][0] == self.builder.configuration.curr_mach:
                self.machine_combo.set_active(active)
                return
            active += 1

        if model[0][0] != self.__dummy_machine__:
            self.machine_combo.insert_text(0, self.__dummy_machine__)

        self.machine_combo.set_active(0)

    def update_image_desc(self):
        desc = ""
        selected_image = self.image_combo.get_active_text()
        if selected_image and selected_image in self.builder.recipe_model.pn_path.keys():
            image_path = self.builder.recipe_model.pn_path[selected_image]
            image_iter = self.builder.recipe_model.get_iter(image_path)
            desc = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_DESC)

        mark = ("<span %s>%s</span>\n") % (self.span_tag('small'), desc)
        self.image_desc.set_markup(mark)

    def image_combo_changed_idle_cb(self, selected_image, selected_recipes, selected_packages):
        self.builder.update_recipe_model(selected_image, selected_recipes)
        self.builder.update_package_model(selected_packages)
        self.builder.window_sensitive(True)

    def image_combo_changed_cb(self, combo):
        self.builder.window_sensitive(False)
        selected_image = self.image_combo.get_active_text()
        if selected_image == self.__custom_image__:
            topdir = self.builder.get_topdir()
            images_dir = topdir + "/recipes/images/"
            self.builder.ensure_dir(images_dir)

            dialog = RetrieveImageDialog(images_dir, "Select from my image recipes",
                            self.builder, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
            response = dialog.run()
            if response == gtk.RESPONSE_OK:
                image_name = dialog.get_filename()
                head, tail = os.path.split(image_name)
                selected_image = os.path.splitext(tail)[0]
                self.custom_image_selected = selected_image
                self.update_image_combo(self.builder.recipe_model, selected_image)
            else:
                selected_image = self.__dummy_image__
                self.update_image_combo(self.builder.recipe_model, None)
            dialog.destroy()
        else:
            if self.custom_image_selected:
                self.custom_image_selected = None
                self.update_image_combo(self.builder.recipe_model, selected_image)

        if not selected_image or (selected_image == self.__dummy_image__):
            self.builder.window_sensitive(True)
            self.just_bake_button.hide()
            self.edit_image_button.hide()
            return

        # remove __dummy_image__ item from the store list after first user selection
        # because it is no longer valid
        combo_store = combo.get_model()
        if len(combo_store) and (combo_store[0][0] == self.__dummy_image__):
            combo.remove_text(0)

        self.builder.customized = False

        selected_recipes = []

        image_path = self.builder.recipe_model.pn_path[selected_image]
        image_iter = self.builder.recipe_model.get_iter(image_path)
        selected_packages = self.builder.recipe_model.get_value(image_iter, self.builder.recipe_model.COL_INSTALL).split()
        self.update_image_desc()

        self.builder.recipe_model.reset()
        self.builder.package_model.reset()

        self.show_baseimg_selected()

        if selected_image == self.builder.recipe_model.__custom_image__:
            self.just_bake_button.hide()

        glib.idle_add(self.image_combo_changed_idle_cb, selected_image, selected_recipes, selected_packages)

    def _image_combo_connect_signal(self):
        if not self.image_combo_id:
            self.image_combo_id = self.image_combo.connect("changed", self.image_combo_changed_cb)

    def _image_combo_disconnect_signal(self):
        if self.image_combo_id:
            self.image_combo.disconnect(self.image_combo_id)
            self.image_combo_id = None

    def update_image_combo(self, recipe_model, selected_image):
        # Update the image combo according to the images in the recipe_model
        # populate image combo
        filter = {RecipeListModel.COL_TYPE : ['image']}
        image_model = recipe_model.tree_model(filter)
        image_model.set_sort_column_id(recipe_model.COL_NAME, gtk.SORT_ASCENDING)
        active = 0
        cnt = 0

        white_pattern = []
        if self.builder.parameters.image_white_pattern:
            for i in self.builder.parameters.image_white_pattern.split():
                white_pattern.append(re.compile(i))

        black_pattern = []
        if self.builder.parameters.image_black_pattern:
            for i in self.builder.parameters.image_black_pattern.split():
                black_pattern.append(re.compile(i))
        black_pattern.append(re.compile("hob-image"))

        it = image_model.get_iter_first()
        self._image_combo_disconnect_signal()
        model = self.image_combo.get_model()
        model.clear()
        # Set a indicator text to combo store when first open
        if not selected_image:
            self.image_combo.append_text(self.__dummy_image__)
            cnt = cnt + 1

        self.image_combo.append_text(self.__custom_image__)
        self.image_combo.append_text("--Separator--")
        cnt = cnt + 2

        topdir = self.builder.get_topdir()
        # append and set active
        while it:
            path = image_model.get_path(it)
            it = image_model.iter_next(it)
            image_name = image_model[path][recipe_model.COL_NAME]
            if image_name == self.builder.recipe_model.__custom_image__:
                continue

            if black_pattern:
                allow = True
                for pattern in black_pattern:
                    if pattern.search(image_name):
                        allow = False
                        break
            elif white_pattern:
                allow = False
                for pattern in white_pattern:
                    if pattern.search(image_name):
                        allow = True
                        break
            else:
                allow = True

            file_name = image_model[path][recipe_model.COL_FILE]
            if file_name and topdir in file_name:
                allow = False

            if allow:
                self.image_combo.append_text(image_name)
                if image_name == selected_image:
                    active = cnt
                cnt = cnt + 1
        self.image_combo.append_text(self.builder.recipe_model.__custom_image__)

        if selected_image == self.builder.recipe_model.__custom_image__:
            active = cnt

        if self.custom_image_selected:
            self.image_combo.append_text("--Separator--")
            self.image_combo.append_text(self.custom_image_selected)
            cnt = cnt + 2
            if self.custom_image_selected == selected_image:
                active = cnt

        self.image_combo.set_active(active)

        if active != 0:
            self.show_baseimg_selected()

        self._image_combo_connect_signal()

    def layer_button_clicked_cb(self, button):
        # Create a layer selection dialog
        self.builder.show_layer_selection_dialog()

    def view_adv_configuration_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_adv_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
            self.builder.wait(0.1) #wait for adv_settings_dialog to terminate
            self.builder.reparse_post_adv_settings()
            self.builder.window.set_cursor(None)

    def just_bake_button_clicked_cb(self, button):
        self.builder.parsing_warnings = []
        self.builder.just_bake()

    def edit_image_button_clicked_cb(self, button):
        self.builder.configuration.initial_selected_image = self.builder.configuration.selected_image
        self.builder.show_recipes()

    def my_images_button_clicked_cb(self, button):
        self.builder.show_load_my_images_dialog()

    def settings_button_clicked_cb(self, button):
        # Create an advanced settings dialog
        response, settings_changed = self.builder.show_simple_settings_dialog()
        if not response:
            return
        if settings_changed:
            self.builder.reparse_post_adv_settings()
    def create_shared_state_page(self):
        advanced_vbox = gtk.VBox(False)
        advanced_vbox.set_border_width(12)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, expand=False, fill=False, padding=24)
        content = "<span>Shared state directory</span>"
        tooltip = "Select a folder that caches your prebuilt results"
        label = self.gen_label_info_widget(content,"<b>Shared state directory</b>" + "*" + tooltip)
        sstatedir_widget, self.sstatedir_text = self.gen_entry_widget(self.configuration.sstatedir, self)
        sub_vbox.pack_start(label, expand=False, fill=False)
        sub_vbox.pack_start(sstatedir_widget, expand=False, fill=False, padding=6)

        content = "<span weight=\"bold\">Shared state mirrors</span>"
        tooltip = "URLs pointing to pre-built mirrors that will speed your build. "
        tooltip += "Select the \'Standard\' configuration if the structure of your "
        tooltip += "mirror replicates the structure of your local shared state directory. "
        tooltip += "For more information on shared state mirrors, check the <a href=\""
        tooltip += "http://www.yoctoproject.org/docs/current/poky-ref-manual/"
        tooltip += "poky-ref-manual.html#shared-state\">Yocto Project Reference Manual</a>."
        table = self.gen_label_info_widget(content,"<b>Shared state mirrors</b>" + "*" + tooltip)
        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        sub_vbox = gtk.VBox(False)
        advanced_vbox.pack_start(sub_vbox, gtk.TRUE, gtk.TRUE, 0)
        searched_string = "file://"

        if self.sstatemirrors_changed == 0:
            self.sstatemirrors_changed = 1
            sstatemirrors = self.configuration.sstatemirror
            if sstatemirrors == "":
                sm_list = ["Standard", "", "file://(.*)"]
                self.sstatemirrors_list.append(sm_list)
            else:
                while sstatemirrors.find(searched_string) != -1:
                    if sstatemirrors.find(searched_string,1) != -1:
                        sstatemirror = sstatemirrors[:sstatemirrors.find(searched_string,1)]
                        sstatemirrors = sstatemirrors[sstatemirrors.find(searched_string,1):]
                    else:
                        sstatemirror = sstatemirrors
                        sstatemirrors = sstatemirrors[1:]

                    sstatemirror_fields = [x for x in sstatemirror.split(' ') if x.strip()]
                    if len(sstatemirror_fields):
                        if sstatemirror_fields[0] == "file://(.*)":
                            sm_list = ["Standard", sstatemirror_fields[1], "file://(.*)"]
                        else:
                            sm_list = ["Custom", sstatemirror_fields[1], sstatemirror_fields[0]]
                        self.sstatemirrors_list.append(sm_list)

        sstatemirrors_widget, sstatemirrors_store = self.gen_shared_sstate_widget(self.sstatemirrors_list, self)
        sub_vbox.pack_start(sstatemirrors_widget, expand=True, fill=True)

        table = gtk.Table(1, 10, False)
        table.set_col_spacings(6)
        add_mirror_button = HobAltButton("Add mirror")
        add_mirror_button.connect("clicked", self.add_mirror)
        add_mirror_button.set_size_request(120,30)
        table.attach(add_mirror_button, 1, 2, 0, 1, xoptions=gtk.SHRINK)

        self.delete_button = HobAltButton("Delete mirror")
        self.delete_button.connect("clicked", self.delete_cb)
        self.delete_button.set_size_request(120, 30)
        table.attach(self.delete_button, 3, 4, 0, 1, xoptions=gtk.SHRINK)

        advanced_vbox.pack_start(table, expand=False, fill=False, padding=6)

        return advanced_vbox
Exemple #59
0
class BuildDetailsPage (HobPage):

    def __init__(self, builder):
        super(BuildDetailsPage, self).__init__(builder, "Building ...")

        self.num_of_issues = 0
        self.endpath = (0,)
        # create visual elements
        self.create_visual_elements()

    def create_visual_elements(self):
        # create visual elements
        self.vbox = gtk.VBox(False, 12)

        self.progress_box = gtk.VBox(False, 12)
        self.task_status = gtk.Label("\n") # to ensure layout is correct
        self.task_status.set_alignment(0.0, 0.5)
        self.progress_box.pack_start(self.task_status, expand=False, fill=False)
        self.progress_hbox = gtk.HBox(False, 6)
        self.progress_box.pack_end(self.progress_hbox, expand=True, fill=True)
        self.progress_bar = HobProgressBar()
        self.progress_hbox.pack_start(self.progress_bar, expand=True, fill=True)
        self.stop_button = HobAltButton("Stop")
        self.stop_button.connect("clicked", self.stop_button_clicked_cb)
        self.stop_button.set_sensitive(False)
        self.progress_hbox.pack_end(self.stop_button, expand=False, fill=False)

        self.notebook = HobNotebook()
        self.config_tv = BuildConfigurationTreeView()
        self.scrolled_view_config = gtk.ScrolledWindow ()
        self.scrolled_view_config.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_config.add(self.config_tv)
        self.notebook.append_page(self.scrolled_view_config, "Build configuration")

        self.failure_tv = BuildFailureTreeView()
        self.failure_model = self.builder.handler.build.model.failure_model()
        self.failure_tv.set_model(self.failure_model)
        self.scrolled_view_failure = gtk.ScrolledWindow ()
        self.scrolled_view_failure.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_failure.add(self.failure_tv)
        self.notebook.append_page(self.scrolled_view_failure, "Issues")

        self.build_tv = RunningBuildTreeView(readonly=True, hob=True)
        self.build_tv.set_model(self.builder.handler.build.model)
        self.scrolled_view_build = gtk.ScrolledWindow ()
        self.scrolled_view_build.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.scrolled_view_build.add(self.build_tv)
        self.notebook.append_page(self.scrolled_view_build, "Log")

        self.builder.handler.build.model.connect_after("row-changed", self.scroll_to_present_row, self.scrolled_view_build.get_vadjustment(), self.build_tv)

        self.button_box = gtk.HBox(False, 6)
        self.back_button = HobAltButton("<< Back to image configuration")
        self.back_button.connect("clicked", self.back_button_clicked_cb)
        self.button_box.pack_start(self.back_button, expand=False, fill=False)

    def update_build_status(self, current, total, task):
        recipe_path, recipe_task = task.split(", ")
        recipe = os.path.basename(recipe_path).rstrip(".bb")
        tsk_msg = "<b>Running task %s of %s:</b> %s\n<b>Recipe:</b> %s" % (current, total, recipe_task, recipe)
        self.task_status.set_markup(tsk_msg)
        self.stop_button.set_sensitive(True)

    def reset_build_status(self):
        self.task_status.set_markup("\n") # to ensure layout is correct
        self.endpath = (0,)

    def show_issues(self):
        self.num_of_issues += 1
        self.notebook.show_indicator_icon("Issues", self.num_of_issues)

    def reset_issues(self):
        self.num_of_issues = 0
        self.notebook.hide_indicator_icon("Issues")

    def _remove_all_widget(self):
        children = self.vbox.get_children() or []
        for child in children:
            self.vbox.remove(child)
        children = self.box_group_area.get_children() or []
        for child in children:
            self.box_group_area.remove(child)
        children = self.get_children() or []
        for child in children:
            self.remove(child)

    def update_failures_sum_display(self):
        num = 0
        it = self.failure_model.get_iter_first()
        while it:
            color = self.failure_model.get_value(it, self.builder.handler.build.model.COL_COLOR)
            if color == HobColors.ERROR:
                num += 1
            it = self.failure_model.iter_next(it)

        return num

    def add_build_fail_top_bar(self, actions):
        mainly_action = "Edit %s" % actions
        if 'image' in actions:
            next_action   = ""
        else:
            next_action   = "Create new image"

        #set to issue page
        self.notebook.set_page("Issues")

        color = HobColors.ERROR
        build_fail_top = gtk.EventBox()
        build_fail_top.set_size_request(-1, 260)
        build_fail_top.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))

        build_fail_tab = gtk.Table(7, 40, True)
        build_fail_top.add(build_fail_tab)

        icon = gtk.Image()
        icon_pix_buffer = gtk.gdk.pixbuf_new_from_file(hic.ICON_INDI_ERROR_FILE)
        icon.set_from_pixbuf(icon_pix_buffer)
        build_fail_tab.attach(icon, 1, 4, 0, 3)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        label.set_markup("<span size='x-large'>%s</span>" % self.title)
        build_fail_tab.attach(label, 4, 20, 0, 3)

        label = gtk.Label()
        label.set_alignment(0.0, 0.5)
        num_of_fails = self.update_failures_sum_display()
        current_fail, recipe_task_status = self.task_status.get_text().split('\n')
        label.set_markup(" %d tasks failed,  %s, %s" % (num_of_fails, current_fail, recipe_task_status))
        build_fail_tab.attach(label, 4, 40, 2, 4)

        # create button 'Edit packages'
        action_button = HobButton(mainly_action)
        action_button.set_size_request(-1, 49)
        action_button.connect('clicked', self.failure_main_action_button_clicked_cb, mainly_action)
        build_fail_tab.attach(action_button, 4, 16, 4, 6)

        if next_action:
            next_button = HobAltButton(next_action)
            next_button.set_alignment(0.0, 0.5)
            next_button.connect('clicked', self.failure_next_action_button_clicked_cb, next_action)
            build_fail_tab.attach(next_button, 17, 24, 4, 5)

        file_bug_button = HobAltButton('File a bug')
        file_bug_button.set_alignment(0.0, 0.5)
        file_bug_button.connect('clicked', self.failure_file_bug_activate_link_cb)
        build_fail_tab.attach(file_bug_button, 17, 24, 4 + abs(next_action != ""), 6)

        return build_fail_top

    def show_fail_page(self, title, action_names):
        self._remove_all_widget()
        self.title = "Hob cannot build your %s" % title

        self.build_fail_bar = self.add_build_fail_top_bar(action_names)
        self.pack_start(self.build_fail_bar)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

    def show_page(self, step):
        self._remove_all_widget()
        if step == self.builder.PACKAGE_GENERATING or step == self.builder.FAST_IMAGE_GENERATING:
            self.title = "Building packages ..."
        else:
            self.title = "Building image ..."
        self.build_details_top = self.add_onto_top_bar(None)
        self.pack_start(self.build_details_top, expand=False, fill=False)
        self.pack_start(self.group_align, expand=True, fill=True)

        self.box_group_area.pack_start(self.vbox, expand=True, fill=True)

        self.progress_bar.reset()
        self.config_tv.reset()
        self.vbox.pack_start(self.progress_box, expand=False, fill=False)

        self.vbox.pack_start(self.notebook, expand=True, fill=True)

        self.box_group_area.pack_end(self.button_box, expand=False, fill=False)
        self.show_all()
        self.back_button.hide()

        self.reset_build_status()
        self.reset_issues()

    def update_progress_bar(self, title, fraction, status=None):
        self.progress_bar.update(fraction)
        self.progress_bar.set_title(title)
        self.progress_bar.set_rcstyle(status)

    def back_button_clicked_cb(self, button):
        self.builder.show_configuration()

    def show_back_button(self):
        self.back_button.show()

    def stop_button_clicked_cb(self, button):
        self.builder.stop_build()

    def hide_stop_button(self):
        self.stop_button.set_sensitive(False)
        self.stop_button.hide()

    def scroll_to_present_row(self, model, path, iter, v_adj, treeview):
        if treeview and v_adj:
            if path[0] > self.endpath[0]: # check the event is a new row append or not
                self.endpath = path
                # check the gtk.adjustment position is at end boundary or not
                if (v_adj.upper <= v_adj.page_size) or (v_adj.value == v_adj.upper - v_adj.page_size):
                    treeview.scroll_to_cell(path)

    def show_configurations(self, configurations, params):
        self.config_tv.show(configurations, params)

    def failure_main_action_button_clicked_cb(self, button, action):
        if "Edit recipes" in action:
            self.builder.show_recipes()
        elif "Edit packages" in action:
            self.builder.show_packages()
        elif "Edit image configuration" in action:
            self.builder.show_configuration()

    def failure_next_action_button_clicked_cb(self, button, action):
        if "Create new image" in action:
            self.builder.initiate_new_build_async()

    def failure_file_bug_activate_link_cb(self, button):
        button.child.emit('activate-link', "http://bugzilla.yoctoproject.org")