Example #1
0
    def update_gui( self ):
        """Update the treeview with new task and family information.

        This redraws the treeview, but keeps a memory of user-expanded
        rows in 'expand_me' so that the tree is still expanded in the
        right places.

        If auto-expand is on, calculate which rows need auto-expansion
        and expand those as well.

        """
        model = self.ttreeview.get_model()

        # Retrieve any user-expanded rows so that we can expand them later.
        expand_me = self._get_user_expanded_row_ids()

        new_data = {}
        new_fam_data = {}
        self.ttree_paths.clear()
        for summary, dest in [(self.updater.state_summary, new_data),
                              (self.updater.fam_state_summary, new_fam_data)]:
            # Populate new_data and new_fam_data.
            for id in summary:
                name, ctime = id.split( TaskID.DELIM )
                if ctime not in dest:
                    dest[ ctime ] = {}
                state = summary[ id ].get( 'state' )
                message = summary[ id ].get( 'latest_message', )

                tsub = summary[ id ].get( 'submitted_time' )
                if isinstance(tsub, basestring) and tsub != "*":
                    if "T" in tsub:
                        # TODO: get rid of this condition (here for backwards compatibility)
                        tsub = _time_trim( isoformat_strftime(tsub, "%H:%M:%S") )
                tstt = summary[ id ].get( 'started_time' )
                tsut = summary[ id ].get( 'succeeded_time' )
                meant = summary[ id ].get( 'mean total elapsed time' )
                tetc = "*"
                if (tstt and (tsut is None or tsut == "*") and
                    self.updater.dt_date is not None and
                    (isinstance(meant, float) or isinstance(meant, int))):
                    try:
                        tstt_date = datetime.datetime.strptime(
                            tstt, "%Y-%m-%dT%H:%M:%S.%f")
                    except (TypeError, ValueError):
                        pass
                    else:
                        run_time = self.updater.dt_date - tstt_date
                        run_time = run_time.days * 86400.0 + run_time.seconds
                        to_go = meant - run_time
                        tetc = isoformat_strftime(
                            (self.updater.dt_date +
                             datetime.timedelta(seconds=to_go)).isoformat(),
                            "%H:%M:%S"
                        )
                if isinstance(tstt, basestring) and tstt != "*":
                    # TODO: get rid of the following condition (here for backwards compatibility)
                    if "T" in tstt:
                        tstt = _time_trim( isoformat_strftime(tstt, "%H:%M:%S") )
                if isinstance(meant, float) or isinstance(meant, int):
                    # TODO: get rid of the following condition (here for backwards compatibility)
                    try:
                        meant = int(meant)
                    except (TypeError, ValueError):
                        pass
                    else:
                        meant_hours, remainder = divmod(int(meant), 3600)
                        meant_minutes, meant_seconds = divmod(remainder, 60)
                        meant = "%d:%02d:%02d" % (meant_hours, meant_minutes,
                                                  meant_seconds)
                priority = summary[ id ].get( 'latest_message_priority' )
                try:
                    icon = self.dots[state]
                except KeyError:
                    icon = self.dots['empty']

                dest[ ctime ][ name ] = [ state, message, tsub, tstt, meant, tetc, icon ]

        tree_data = {}
        self.ttreestore.clear()
        times = new_data.keys()
        times.sort()

        for ctime in times:
            f_data = [ None ] * 7
            if "root" in new_fam_data[ctime]:
                f_data = new_fam_data[ctime]["root"]
            piter = self.ttreestore.append(None, [ ctime, ctime ] + f_data )
            family_iters = {}
            name_iters = {}
            task_named_paths = []
            for name in new_data[ ctime ].keys():
                # The following line should filter by allowed families.
                families = list(self.ancestors[name])
                families.sort(lambda x, y: (y in self.ancestors[x]) -
                                           (x in self.ancestors[y]))
                if "root" in families:
                    families.remove("root")
                if name in families:
                    families.remove(name)
                if not self.should_group_families:
                    families = []
                task_path = families + [name]
                task_named_paths.append(task_path)

            # Sorting here every time the treeview is updated makes
            # definition sort order the default "unsorted" order
            # (any column-click sorting is done on top of this).
            if self.cfg.use_defn_order and self.updater.ns_defn_order:
                task_named_paths.sort( key=lambda x: map( self.updater.dict_ns_defn_order.get, x ) )
            else:
                task_named_paths.sort()

            for named_path in task_named_paths:
                name = named_path[-1]
                state = new_data[ctime][name][0]
                self._update_path_info( piter, state, name )
                f_iter = piter
                for i, fam in enumerate(named_path[:-1]):
                    # Construct family tree for this task.
                    if fam in family_iters:
                        # Family already in tree
                        f_iter = family_iters[fam]
                    else:
                        # Add family to tree
                        f_data = [ None ] * 7
                        if fam in new_fam_data[ctime]:
                            f_data = new_fam_data[ctime][fam]
                        f_iter = self.ttreestore.append(
                                      f_iter, [ ctime, fam ] + f_data )
                        family_iters[fam] = f_iter
                    self._update_path_info( f_iter, state, name )
                # Add task to tree
                self.ttreestore.append( f_iter, [ ctime, name ] + new_data[ctime][name])
        if self.autoexpand:
            autoexpand_me = self._get_autoexpand_rows()
            for row_id in list(autoexpand_me):
                if row_id in expand_me:
                    # User expanded row also meets auto-expand criteria.
                    autoexpand_me.remove(row_id)
            expand_me += autoexpand_me
            self._last_autoexpand_me = autoexpand_me
        if model is None:
            return
        model.get_model().refilter()
        model.sort_column_changed()

        # Expand all the rows that were user-expanded or need auto-expansion.
        model.foreach( self._expand_row, expand_me )

        return False
Example #2
0
    def update_gui(self):
        """Update the treeview with new task and family information.

        This redraws the treeview, but keeps a memory of user-expanded
        rows in 'expand_me' so that the tree is still expanded in the
        right places.

        If auto-expand is on, calculate which rows need auto-expansion
        and expand those as well.

        """

        # Retrieve any user-expanded rows so that we can expand them later.
        expand_me = self._get_user_expanded_row_ids()

        new_data = {}
        new_fam_data = {}
        self.ttree_paths.clear()
        for summary, dest in [(self.updater.state_summary, new_data),
                              (self.updater.fam_state_summary, new_fam_data)]:
            # Populate new_data and new_fam_data.
            for id in summary:
                name, ctime = id.split(TaskID.DELIM)
                if ctime not in dest:
                    dest[ctime] = {}
                state = summary[id].get('state')
                message = summary[id].get('latest_message', )

                tsub = summary[id].get('submitted_time')
                if isinstance(tsub, basestring) and tsub != "*":
                    if "T" in tsub:
                        # TODO: get rid of this condition (here for backwards compatibility)
                        tsub = _time_trim(isoformat_strftime(tsub, "%H:%M:%S"))
                tstt = summary[id].get('started_time')
                if isinstance(tstt, basestring) and tstt != "*":
                    if "T" in tstt:
                        # TODO: get rid of this condition (here for backwards compatibility)
                        tstt = _time_trim(isoformat_strftime(tstt, "%H:%M:%S"))
                meant = _time_trim(summary[id].get('mean total elapsed time'))
                tetc = _time_trim(summary[id].get('Tetc'))
                priority = summary[id].get('latest_message_priority')
                if message is not None:
                    message = markup(get_col_priority(priority), message)
                icon = self.dots[state]
                dest[ctime][name] = [
                    state, message, tsub, tstt, meant, tetc, icon
                ]

        # print existing tree:
        #print
        #iter = self.ttreestore.get_iter_first()
        #while iter:
        #    row = []
        #    for col in range( self.ttreestore.get_n_columns() ):
        #        row.append( self.ttreestore.get_value( iter, col ))
        #    print "------------------", row
        #    iterch = self.ttreestore.iter_children( iter )
        #    while iterch:
        #        ch_row = []
        #        for col in range( self.ttreestore.get_n_columns() ):
        #            ch_row.append( self.ttreestore.get_value( iterch, col ))
        #        print "  -----------", ch_row
        #        iterch = self.ttreestore.iter_next( iterch )
        #    iter = self.ttreestore.iter_next( iter )
        #print

        tree_data = {}
        self.ttreestore.clear()
        times = new_data.keys()
        times.sort()
        for ctime in times:
            f_data = [None] * 7
            if "root" in new_fam_data[ctime]:
                f_data = new_fam_data[ctime]["root"]
            piter = self.ttreestore.append(None, [ctime, ctime] + f_data)
            family_iters = {}
            name_iters = {}
            task_named_paths = []
            for name in new_data[ctime].keys():
                # The following line should filter by allowed families.
                families = list(self.ancestors[name])
                families.sort(lambda x, y: (y in self.ancestors[x]) -
                              (x in self.ancestors[y]))
                if "root" in families:
                    families.remove("root")
                if name in families:
                    families.remove(name)
                if not self.should_group_families:
                    families = []
                task_path = families + [name]
                task_named_paths.append(task_path)
            task_named_paths.sort()
            for named_path in task_named_paths:
                name = named_path[-1]
                state = new_data[ctime][name][0]
                ###               if state is not None:
                ###                   state = re.sub('<[^>]+>', '', state)
                self._update_path_info(piter, state, name)
                f_iter = piter
                for i, fam in enumerate(named_path[:-1]):
                    # Construct family tree for this task.
                    if fam in family_iters:
                        # Family already in tree
                        f_iter = family_iters[fam]
                    else:
                        # Add family to tree
                        f_data = [None] * 7
                        if fam in new_fam_data[ctime]:
                            f_data = new_fam_data[ctime][fam]
                        f_iter = self.ttreestore.append(
                            f_iter, [ctime, fam] + f_data)
                        family_iters[fam] = f_iter
                    self._update_path_info(f_iter, state, name)
                # Add task to tree
                self.ttreestore.append(f_iter,
                                       [ctime, name] + new_data[ctime][name])
        if self.autoexpand:
            autoexpand_me = self._get_autoexpand_rows()
            for row_id in list(autoexpand_me):
                if row_id in expand_me:
                    # User expanded row also meets auto-expand criteria.
                    autoexpand_me.remove(row_id)
            expand_me += autoexpand_me
            self._last_autoexpand_me = autoexpand_me
        model = self.ttreeview.get_model()
        if model is None:
            return
        model.get_model().refilter()
        model.sort_column_changed()

        # Expand all the rows that were user-expanded or need auto-expansion.
        model.foreach(self._expand_row, expand_me)

        return False
Example #3
0
    def update_gui(self):
        """Update the treeview with new task and family information.

        This redraws the treeview, but keeps a memory of user-expanded
        rows in 'expand_me' so that the tree is still expanded in the
        right places.

        If auto-expand is on, calculate which rows need auto-expansion
        and expand those as well.

        """

        # Retrieve any user-expanded rows so that we can expand them later.
        expand_me = self._get_user_expanded_row_ids()

        new_data = {}
        new_fam_data = {}
        self.ttree_paths.clear()
        for summary, dest in [(self.updater.state_summary, new_data), (self.updater.fam_state_summary, new_fam_data)]:
            # Populate new_data and new_fam_data.
            for id in summary:
                name, ctime = id.split(TaskID.DELIM)
                if ctime not in dest:
                    dest[ctime] = {}
                state = summary[id].get("state")
                message = summary[id].get("latest_message")

                tsub = summary[id].get("submitted_time")
                if isinstance(tsub, basestring) and tsub != "*":
                    if "T" in tsub:
                        # TODO: get rid of this condition (here for backwards compatibility)
                        tsub = _time_trim(isoformat_strftime(tsub, "%H:%M:%S"))
                tstt = summary[id].get("started_time")
                if isinstance(tstt, basestring) and tstt != "*":
                    if "T" in tstt:
                        # TODO: get rid of this condition (here for backwards compatibility)
                        tstt = _time_trim(isoformat_strftime(tstt, "%H:%M:%S"))
                meant = _time_trim(summary[id].get("mean total elapsed time"))
                tetc = _time_trim(summary[id].get("Tetc"))
                priority = summary[id].get("latest_message_priority")
                if message is not None:
                    message = markup(get_col_priority(priority), message)
                icon = self.dots[state]
                dest[ctime][name] = [state, message, tsub, tstt, meant, tetc, icon]

        # print existing tree:
        # print
        # iter = self.ttreestore.get_iter_first()
        # while iter:
        #    row = []
        #    for col in range( self.ttreestore.get_n_columns() ):
        #        row.append( self.ttreestore.get_value( iter, col ))
        #    print "------------------", row
        #    iterch = self.ttreestore.iter_children( iter )
        #    while iterch:
        #        ch_row = []
        #        for col in range( self.ttreestore.get_n_columns() ):
        #            ch_row.append( self.ttreestore.get_value( iterch, col ))
        #        print "  -----------", ch_row
        #        iterch = self.ttreestore.iter_next( iterch )
        #    iter = self.ttreestore.iter_next( iter )
        # print

        tree_data = {}
        self.ttreestore.clear()
        times = new_data.keys()
        times.sort()
        for ctime in times:
            f_data = [None] * 7
            if "root" in new_fam_data[ctime]:
                f_data = new_fam_data[ctime]["root"]
            piter = self.ttreestore.append(None, [ctime, ctime] + f_data)
            family_iters = {}
            name_iters = {}
            task_named_paths = []
            for name in new_data[ctime].keys():
                # The following line should filter by allowed families.
                families = list(self.ancestors[name])
                families.sort(lambda x, y: (y in self.ancestors[x]) - (x in self.ancestors[y]))
                if "root" in families:
                    families.remove("root")
                if name in families:
                    families.remove(name)
                if not self.should_group_families:
                    families = []
                task_path = families + [name]
                task_named_paths.append(task_path)
            task_named_paths.sort()
            for named_path in task_named_paths:
                name = named_path[-1]
                state = new_data[ctime][name][0]
                ###               if state is not None:
                ###                   state = re.sub('<[^>]+>', '', state)
                self._update_path_info(piter, state, name)
                f_iter = piter
                for i, fam in enumerate(named_path[:-1]):
                    # Construct family tree for this task.
                    if fam in family_iters:
                        # Family already in tree
                        f_iter = family_iters[fam]
                    else:
                        # Add family to tree
                        f_data = [None] * 7
                        if fam in new_fam_data[ctime]:
                            f_data = new_fam_data[ctime][fam]
                        f_iter = self.ttreestore.append(f_iter, [ctime, fam] + f_data)
                        family_iters[fam] = f_iter
                    self._update_path_info(f_iter, state, name)
                # Add task to tree
                self.ttreestore.append(f_iter, [ctime, name] + new_data[ctime][name])
        if self.autoexpand:
            autoexpand_me = self._get_autoexpand_rows()
            for row_id in list(autoexpand_me):
                if row_id in expand_me:
                    # User expanded row also meets auto-expand criteria.
                    autoexpand_me.remove(row_id)
            expand_me += autoexpand_me
            self._last_autoexpand_me = autoexpand_me
        model = self.ttreeview.get_model()
        if model is None:
            return
        model.get_model().refilter()
        model.sort_column_changed()

        # Expand all the rows that were user-expanded or need auto-expansion.
        model.foreach(self._expand_row, expand_me)

        return False