Esempio n. 1
0
class ComboLogViewer(logviewer):
    """Implement a viewer for task jobs in the "cylc gui".

    It has a a combo box for log file selection.

    task_id -- The NAME.POINT of a task proxy.
    filenames -- The names of the task job logs.
    cmd_tmpls -- A dict to map file names and alternate commands to tail follow
                 the file.
    init_active_index -- The index for selecting the initial log file.
    """

    LABEL_TEXT = "Choose Log File: "

    def __init__(self, task_id, filenames, cmd_tmpls, init_active_index):
        self.filenames = OrderedDict()
        name_str, point_str = TaskID.split(task_id)
        for filename in filenames:
            try:
                f_point_str, f_name_str, f_submit_num_str, f_base_name = (
                    filename.rsplit(os.sep, 4)[1:])
                if (f_point_str == point_str and f_name_str == name_str
                        and int(f_submit_num_str) and f_base_name):
                    name = f_submit_num_str + os.sep + f_base_name
                if ":" in filename:
                    name += " (%s)" % (filename.split(":", 1)[0])
            except ValueError:
                name = filename
            self.filenames[name] = filename
        self.init_active_index = init_active_index
        self.cmd_tmpls = cmd_tmpls
        logviewer.__init__(self, task_id, None,
                           filenames[self.init_active_index])

    def connect(self):
        """Connect to the selected log file tailer."""
        try:
            cmd_tmpl = self.cmd_tmpls[self.filename]
        except (KeyError, TypeError):
            cmd_tmpl = None
        self.t = Tailer(self.logview, self.filename, cmd_tmpl=cmd_tmpl)
        self.t.start()

    def create_gui_panel(self):
        """Create the panel."""
        logviewer.create_gui_panel(self)
        label = gtk.Label(self.LABEL_TEXT)
        combobox = gtk.combo_box_new_text()

        for name in self.filenames:
            combobox.append_text(name)

        combobox.connect("changed", self.switch_log)
        if self.init_active_index:
            combobox.set_active(self.init_active_index)
        else:
            combobox.set_active(0)

        self.hbox.pack_end(combobox, False)
        self.hbox.pack_end(label, False)

    def switch_log(self, callback):
        """Switch to another file, if necessary."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()

        name = model[index][0]
        filename = self.filenames[name]
        if filename != self.filename:
            self.filename = filename
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.log_label.set_text(name)
            self.connect()

        return False
Esempio n. 2
0
class ComboLogViewer(logviewer):

    """Implement a viewer for task jobs in the "cylc gui".

    It has a a combo box for log file selection.

    task_id -- The NAME.POINT of a task proxy.
    filenames -- The names of the task job logs.
    cmd_tmpls -- A dict to map file names and alternate commands to tail follow
                 the file.
    init_active_index -- The index for selecting the initial log file.
    """

    LABEL_TEXT = "Choose Log File: "

    def __init__(self, task_id, filenames, cmd_tmpls, init_active_index):
        self.filenames = OrderedDict()
        name_str, point_str = TaskID.split(task_id)
        for filename in filenames:
            try:
                f_point_str, f_name_str, f_submit_num_str, f_base_name = (
                    filename.rsplit(os.sep, 4)[1:])
                if (f_point_str == point_str and f_name_str == name_str and
                        int(f_submit_num_str) and f_base_name):
                    name = f_submit_num_str + os.sep + f_base_name
                if ":" in filename:
                    name += " (%s)" % (filename.split(":", 1)[0])
            except ValueError:
                name = filename
            self.filenames[name] = filename
        self.init_active_index = init_active_index
        self.cmd_tmpls = cmd_tmpls
        logviewer.__init__(
            self, task_id, None, filenames[self.init_active_index])

    def connect(self):
        """Connect to the selected log file tailer."""
        try:
            cmd_tmpl = self.cmd_tmpls[self.filename]
        except (KeyError, TypeError):
            cmd_tmpl = None
        self.t = Tailer(self.logview, self.filename, cmd_tmpl=cmd_tmpl)
        self.t.start()

    def create_gui_panel(self):
        """Create the panel."""
        logviewer.create_gui_panel(self)
        label = gtk.Label(self.LABEL_TEXT)
        combobox = gtk.combo_box_new_text()

        for name in self.filenames:
            combobox.append_text(name)

        combobox.connect("changed", self.switch_log)
        if self.init_active_index:
            combobox.set_active(self.init_active_index)
        else:
            combobox.set_active(0)

        self.hbox.pack_end(combobox, False)
        self.hbox.pack_end(label, False)

    def switch_log(self, callback):
        """Switch to another file, if necessary."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()

        name = model[index][0]
        filename = self.filenames[name]
        if filename != self.filename:
            self.filename = filename
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.log_label.set_text(name)
            self.connect()

        return False
Esempio n. 3
0
class ComboLogViewer(logviewer):
    """Implement a viewer for task job logs in the GUI, via "cylc cat-log".

    It has a a combo box for log file selection.

    """
    LABEL_TEXT = "File: "
    LABEL_TEXT2 = "Submit: "

    def __init__(self, suite, task_id, choice, extra_logs, nsubmits,
                 remote_run_opts):
        self.suite_name = suite
        self.task_id = task_id
        self.nsubmits = nsubmits
        self.nsubmit = nsubmits
        self.extra_logs = extra_logs
        self.suite = suite
        self.choice = choice
        self.cmd_tmpl = "cylc cat-log %s" % remote_run_opts + (
            " -m t -s %(subnum)s -f %(job_log)s %(suite_name)s %(task_id)s")
        logviewer.__init__(self)

    def connect(self):
        """Connect to the selected log file tailer."""
        cmd = self.cmd_tmpl % {
            'subnum': self.nsubmit,
            'suite_name': self.suite_name,
            'task_id': self.task_id,
            'job_log': self.choice
        }
        self.log_label.set_text(self.choice)
        self.t = Tailer(self.logview, cmd)
        self.t.start()

    def create_gui_panel(self):
        """Create the panel."""
        logviewer.create_gui_panel(self)

        label2 = gtk.Label(self.LABEL_TEXT2)
        combobox2 = gtk.combo_box_new_text()
        snums = range(1, self.nsubmits + 1)
        for snum in snums:
            combobox2.append_text(str(snum))
        combobox2.connect("changed", self.switch_snum)
        if self.nsubmit in snums:
            combobox2.set_active(snums.index(self.nsubmit))
        self.hbox.pack_end(combobox2, False)
        self.hbox.pack_end(label2, False)

        label = gtk.Label(self.LABEL_TEXT)
        combobox = gtk.combo_box_new_text()
        names = JOB_LOG_OPTS.values() + self.extra_logs
        for name in names:
            combobox.append_text(name)
        combobox.connect("changed", self.switch_log)
        combobox.set_active(names.index(self.choice))
        self.hbox.pack_end(combobox, False)
        self.hbox.pack_end(label, False)

    def switch_log(self, callback):
        """Switch to another file."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()

        filename = model[index][0]
        if filename != self.choice:
            self.choice = filename
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.connect()
        return False

    def switch_snum(self, callback):
        """Switch to another file."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()
        snum = model[index][0]
        if snum != self.nsubmit:
            self.nsubmit = snum
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.connect()
        return False
Esempio n. 4
0
class ComboLogViewer(logviewer):

    """Implement a viewer for task job logs in the GUI, via "cylc cat-log".

    It has a a combo box for log file selection.

    """
    LABEL_TEXT = "File: "
    LABEL_TEXT2 = "Submit: "

    def __init__(self, suite, task_id, choice, extra_logs, nsubmits,
                 remote_run_opts):
        self.suite_name = suite
        self.task_id = task_id
        self.nsubmits = nsubmits
        self.nsubmit = nsubmits
        self.extra_logs = extra_logs
        self.suite = suite
        self.choice = choice
        self.cmd_tmpl = "cylc cat-log %s" % remote_run_opts + (
            " -m t -s %(subnum)s -f %(job_log)s %(suite_name)s %(task_id)s")
        logviewer.__init__(self)

    def connect(self):
        """Connect to the selected log file tailer."""
        cmd = self.cmd_tmpl % {'subnum': self.nsubmit,
                               'suite_name': self.suite_name,
                               'task_id': self.task_id,
                               'job_log': self.choice}
        self.log_label.set_text(self.choice)
        self.t = Tailer(self.logview, cmd)
        self.t.start()

    def create_gui_panel(self):
        """Create the panel."""
        logviewer.create_gui_panel(self)

        label2 = gtk.Label(self.LABEL_TEXT2)
        combobox2 = gtk.combo_box_new_text()
        snums = range(1, self.nsubmits + 1)
        for snum in snums:
            combobox2.append_text(str(snum))
        combobox2.connect("changed", self.switch_snum)
        combobox2.set_active(snums.index(self.nsubmit))
        self.hbox.pack_end(combobox2, False)
        self.hbox.pack_end(label2, False)

        label = gtk.Label(self.LABEL_TEXT)
        combobox = gtk.combo_box_new_text()
        names = JOB_LOG_OPTS.values() + self.extra_logs
        for name in names:
            combobox.append_text(name)
        combobox.connect("changed", self.switch_log)
        combobox.set_active(names.index(self.choice))
        self.hbox.pack_end(combobox, False)
        self.hbox.pack_end(label, False)

    def switch_log(self, callback):
        """Switch to another file."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()

        filename = model[index][0]
        if filename != self.choice:
            self.choice = filename
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.connect()
        return False

    def switch_snum(self, callback):
        """Switch to another file."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()
        snum = model[index][0]
        if snum != self.nsubmit:
            self.nsubmit = snum
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.connect()
        return False
Esempio n. 5
0
class ComboLogViewer(logviewer):

    """Implement a viewer for task jobs in the "cylc gui".

    It has a a combo box for log file selection.

    task_id -- The NAME.POINT of a task proxy.
    filenames -- The names of the task job logs.
    cmd_tmpls -- A dict to map file names and alternate commands to tail follow
                 the file.
    init_active_index -- The index for selecting the initial log file.
    """

    LABEL_TEXT = "Choose Log File: "

    def __init__(self, task_id, filenames, cmd_tmpls, init_active_index):
        self.filenames = filenames
        self.init_active_index = init_active_index
        self.cmd_tmpls = cmd_tmpls
        self.common_dir = os.path.dirname(os.path.commonprefix(self.filenames))
        logviewer.__init__(
            self, task_id, None, self.filenames[self.init_active_index])

    def connect(self):
        """Connect to the selected log file tailer."""
        try:
            cmd_tmpl = self.cmd_tmpls[self.filename]
        except (KeyError, TypeError):
            cmd_tmpl = None
        self.t = Tailer(self.logview, self.filename, cmd_tmpl=cmd_tmpl)
        self.t.start()

    def create_gui_panel(self):
        """Create the panel."""
        logviewer.create_gui_panel(self)
        label = gtk.Label(self.LABEL_TEXT)
        combobox = gtk.combo_box_new_text()

        for filename in self.filenames:
            relpath = os.path.relpath(filename, self.common_dir)
            if len(relpath) < len(filename):
                combobox.append_text(relpath)
            else:
                combobox.append_text(filename)

        combobox.connect("changed", self.switch_log)
        if self.init_active_index:
            combobox.set_active(self.init_active_index)
        else:
            combobox.set_active(0)

        self.hbox.pack_end(combobox, False)
        self.hbox.pack_end(label, False)

    def switch_log(self, callback):
        """Switch to another file, if necessary."""
        if self.t is None:
            return False
        model = callback.get_model()
        index = callback.get_active()

        name = model[index][0]
        if name in self.filenames:
            filename = name
        else:
            filename = os.path.join(self.common_dir, name)
        if filename != self.filename:
            self.filename = filename
            self.t.stop()
            self.t.join()
            logbuffer = self.logview.get_buffer()
            pos_start, pos_end = logbuffer.get_bounds()
            self.reset_logbuffer()
            logbuffer.delete(pos_start, pos_end)
            self.log_label.set_text(name)
            self.connect()

        return False