Ejemplo n.º 1
0
    def update(self):
        """Update the Applet."""
        info = copy.deepcopy(self.hosts_suites_info)
        stop_info = copy.deepcopy(self.stopped_hosts_suites_info)
        suite_host_tuples = []
        for host in self.hosts:
            suites = (info.get(host, {}).keys() +
                      stop_info.get(host, {}).keys())
            for suite in suites:
                if (suite, host) not in suite_host_tuples:
                    suite_host_tuples.append((suite, host))
        suite_host_tuples.sort()
        for child in self.dot_hbox.get_children():
            self.dot_hbox.remove(child)
        number_mode = (not self.is_compact and
                       len(suite_host_tuples) > self.MAX_INDIVIDUAL_SUITES)
        suite_statuses = {}
        compact_suite_statuses = []
        for suite, host in suite_host_tuples:
            if suite in info.get(host, {}):
                suite_info = info[host][suite]
                is_stopped = False
            else:
                suite_info = stop_info[host][suite]
                is_stopped = True

            if "states" not in suite_info:
                continue

            status = extract_group_state(suite_info['states'].keys(),
                                         is_stopped=is_stopped)
            status_map = suite_info['states']
            if number_mode:
                suite_statuses.setdefault(is_stopped, {})
                suite_statuses[is_stopped].setdefault(status, [])
                suite_statuses[is_stopped][status].append(
                    (suite, host, status_map.items()))
            elif self.is_compact:
                compact_suite_statuses.append((suite, host, status,
                                               status_map.items(), is_stopped))
            else:
                self._add_image_box([(suite, host, status, status_map.items(),
                                      is_stopped)])
        if number_mode:
            for is_stopped in sorted(suite_statuses.keys()):
                statuses = suite_statuses[is_stopped].items()
                # Sort by number of suites in this state.
                statuses.sort(lambda x, y: cmp(len(y[1]), len(x[1])))
                for status, suite_host_states_tuples in statuses:
                    label = gtk.Label(str(len(suite_host_states_tuples)) + ":")
                    label.show()
                    self.dot_hbox.pack_start(label, expand=False, fill=False)
                    suite_info_tuples = []
                    for suite, host, task_states in suite_host_states_tuples:
                        suite_info_tuples.append((suite, host, status,
                                                  task_states, is_stopped))
                    self._add_image_box(suite_info_tuples)
        if self.is_compact:
            if not compact_suite_statuses:
                # No suites running or stopped.
                self.gcylc_image.show()
                return False
            self.gcylc_image.hide()
            self._add_image_box(compact_suite_statuses)
        return False
Ejemplo n.º 2
0
    def _add_image_box(self, suite_host_info_tuples):
        image_eb = gtk.EventBox()
        image_eb.show()
        is_all_stopped = False
        running_status_list = []
        status_list = []
        suite_host_tuples = []
        for info_tuple in suite_host_info_tuples:
            suite, host, status, task_states, is_stopped = info_tuple
            suite_host_tuples.append((suite, host))
            if not is_stopped:
                running_status_list.append(status)
            status_list.append(status)
        if running_status_list:
            status = extract_group_state(running_status_list,
                                         is_stopped=False)
            image = self.dots.get_image(status, is_stopped=False)
        else:
            status = extract_group_state(status_list, is_stopped=True)
            image = self.dots.get_image(status, is_stopped=True)
        image.show()
        image_eb.add(image)
        image_eb._connect_args = suite_host_tuples
        image_eb.connect("button-press-event",
                         self._on_button_press_event)

        text_format = "%s - %s - %s"
        long_text_format = text_format + "\n    %s\n"
        text = ""
        tip_vbox = gtk.VBox()  # Only used in PyGTK 2.12+
        tip_vbox.show()
        for info_tuple in suite_host_info_tuples:
            suite, host, status, state_counts, is_stopped = info_tuple
            state_counts.sort(lambda x, y: cmp(y[1], x[1]))
            tip_hbox = gtk.HBox()
            tip_hbox.show()
            state_info = []
            for state_name, number in state_counts:
                state_info.append("%d %s" % (number, state_name))
                image = self.dots.get_image(state_name, is_stopped=is_stopped)
                image.show()
                tip_hbox.pack_start(image, expand=False, fill=False)
            states_text = ", ".join(state_info)
            if status is None:
                suite_summary = "?"
            else:
                suite_summary = status
            if is_stopped:
                suite_summary = "stopped with " + suite_summary
            tip_label = gtk.Label(text_format % (suite, suite_summary, host))
            tip_label.show()
            tip_hbox.pack_start(tip_label, expand=False, fill=False,
                                padding=5)
            tip_vbox.pack_start(tip_hbox, expand=False, fill=False)
            text += long_text_format % (
                suite, suite_summary, host, states_text)
        text = text.rstrip()
        if hasattr(gtk, "Tooltip"):
            image_eb.set_has_tooltip(True)
            image_eb.connect("query-tooltip", self._on_img_tooltip_query,
                             tip_vbox)
        else:
            self._set_tooltip(image_eb, text)
        self.dot_hbox.pack_start(image_eb, expand=False, fill=False,
                                 padding=1)
Ejemplo n.º 3
0
 def update(self, suite_update_times=None):
     """Update the Applet."""
     suite_host_tuples = []
     statuses = copy.deepcopy(self.statuses)
     stop_summaries = copy.deepcopy(self.stop_summaries)
     for host in self.hosts:
         suites = (statuses.get(host, {}).keys() +
                   stop_summaries.get(host, {}).keys())
         for suite in suites:
             suite_host_tuples.append((suite, host))
     suite_host_tuples.sort()
     for child in self.dot_hbox.get_children():
         self.dot_hbox.remove(child)
     number_mode = (not self.is_compact and
                    len(suite_host_tuples) > self.MAX_INDIVIDUAL_SUITES)
     suite_statuses = {}
     compact_suite_statuses = []
     for suite, host in suite_host_tuples:
         if suite in statuses.get(host, {}):
             task_cycle_states = statuses[host][suite]
             is_stopped = False
         else:
             info = stop_summaries[host][suite]
             task_cycle_states, suite_time = info
             is_stopped = True
         status_map = {}
         for task, cycle, status in task_cycle_states:
             status_map.setdefault(status, []).append(task + "." + cycle)
         status = extract_group_state(status_map.keys(),
                                      is_stopped=is_stopped)
         if number_mode:
             suite_statuses.setdefault(is_stopped, {})
             suite_statuses[is_stopped].setdefault(status, [])
             suite_statuses[is_stopped][status].append(
                                        (suite, host, status_map.items()))
         elif self.is_compact:
             compact_suite_statuses.append((suite, host, status,
                                            status_map.items(), is_stopped))
         else:
             self._add_image_box([(suite, host, status, status_map.items(),
                                   is_stopped)])
     if number_mode:
         for is_stopped in sorted(suite_statuses.keys()):
             statuses = suite_statuses[is_stopped].items()
             statuses.sort(lambda x, y: cmp(len(y[1]), len(x[1])))
             for status, suite_host_states_tuples in statuses:
                 label = gtk.Label(
                             str(len(suite_host_states_tuples)) + ":")
                 label.show()
                 self.dot_hbox.pack_start(label, expand=False, fill=False)
                 suite_info_tuples = []
                 for suite, host, task_states in suite_host_states_tuples:
                     suite_info_tuples.append((suite, host, status,
                                               task_states, is_stopped))
                 self._add_image_box(suite_info_tuples)
     if self.is_compact:
         if not compact_suite_statuses:
             # No suites running or stopped.
             self.gcylc_image.show()
             return False
         self.gcylc_image.hide()
         self._add_image_box(compact_suite_statuses)
     return False